This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Link order: Library first or Source first?

Anonymous
Anonymous

Hi,

 

I would like to ask a question on library.

 

 

If under a project folder there are two files:

1.    The original library source file with suffix .c, for example, my_math.c; it is also included as a project file.

2.    The compiled library my_math.lib generated from my_math.c; it is added to the project as a library file

 

And when another project file, say main.c, references a function, say, my_addition() both defined

1.    In my_math.c

2.    Also contained in my_math.lib

 

What is the order of searching?

1.    With the presence of my_math.lib, would the compile still compile my_math.c?

2.    Would the linker link calls of my_addition() in main.c to compiled object file corresponding to  my_math.c, or directly to my_math.lib?

 

I searched ISO C99 standard as well as K&R 2, but it seems there is no discussion about this.

 

It is basically a stipulation on search order. Is there any specific rules governing this? Or is it customizable?

 

 

Zheng

 

  • This is a topic that is outside the scope of the C standard.

    The linker will first search through all object files specified on the command line, and then it will begin looking through the libraries specified.  You can alter the library search order.  See Section 7.4.13.3 "Exhaustively Read and Search Libraries (--reread_libs and --priority Options)" of the C6000 Assembly Language Tool's User's Guide (the exact section number varies by target and compiler version).