Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8190441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T03:39:07+00:00 2026-06-07T03:39:07+00:00

I’m new in C and especially writing static libraries and I’m getting strange behavior

  • 0

I’m new in C and especially writing static libraries and I’m getting strange behavior from my library.

I wrote a little static library called cde. I compiled the different parts with gcc into .o-files and then I used ar to put them all together into an .a-file

Now, when I want to test my library I do the following:

gcc test.c -L../bin -lcde -lelf

libcde.a is my library located in ../bin. libelf.a is a library I need for my library (i don’t know how to put it directly into my own library…).

The thing is that I can call every function of my library without having to include the header-file of my library. How is that possible? At compile-time the files shouldn’t be linked so the compiler should have no idea what functions are available inside my library…

When I run it the following way,

gcc -L../bin -lcde -lelf test.c

the file test.c can’t find any of my functions defined in my header file even though I’ve included it.

I think I’m doing something fundamentally wrong here, but I really can’t find out what.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T03:39:09+00:00Added an answer on June 7, 2026 at 3:39 am

    There are two questions here:

    1. Why does test.c compile without a header providing declarations of routines in the library?
    2. Why does the link work with test.c listed first on the command line but not with test.c listed last on the command line?

    We cannot provide a full answer to the first because you have not shown the source code. As others have indicated, C has some leeway to provide implicit declarations, largely for historical reasons. Those implicit declarations might not match the actual definitions of your routines, which can cause errors, so you should avoid implicit declarations.

    The answer to your second question is this. Given either of the two command lines you show, the compiler compiles test.c and then invokes the linker. (The compiler can also be made to do other things, such as to compile without linking or to link object modules from previously compiled sources.) When the compiler invokes the linker, it passes the linker arguments in an order that corresponds to the order you passed them to the linker. In particular, if you put -lcde before test.c, then the compiler puts -lcde before the object module that comes from test.c, test.o, when it runs the linker.

    This is important because of the way the linker operates. Among other things, the linker has a list of symbols that it needs definitions for. The list is initially empty. The linker processes inputs from the command line from left to right. When the linker sees an object module like test.o in its command line, it reads the object module and processes it. Often, an object module contains references to some symbols that it does not define, such as calls to library routines. If the linker already has definitions of these symbols from a previous file, it connects the references to the definitions. If it does not have definitions, it adds the symbols to the list of symbols the linker needs definitions for.

    When the linker processes a library file, it checks each object module within the library to see if that object module defines a symbol that is on the linker’s list of needed definitions. If so, the linker reads that object module and adds it (and its definitions) to the executable the linker is building. If not, the linker ignores that object module.

    Now we can see why test.c -lcde works but -lcde test.c does not. In the former case, the linker makes a list of everything that test.o needs, then it gets those things from the cde library. In the latter case, the linker sees the cde library but does not need anything from it yet, so it goes on without taking anything from the library. Then the linker reads test.c and adds to the list of needed symbols. Then the command line ends, and the linker has no more files but still has symbols without definitions. So it reports an error.

    So, generally, libraries should be listed last on command lines.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
public static bool CheckLogin(string Username, string Password, bool AutoLogin) { bool LoginSuccessful; // Trim
I have a text area in my form which accepts all possible characters from
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.