order of arguments to compiler matter?

order of arguments to compiler matter?

Hi, I had the notion that the order of arguments to the compiler do not matter. But this does not seem to be the case atleast during the linking stage.

When I give the following arguments to icc 13.0,

$ icc -L../annotations -openmp -lrt -lannotations -o ../bin/cg.B_annot cg_annot.o ../common/c_print_results.o ../common/c_randdp.o ../common/c_timers.o ../common/c_wtime.o

This throws lots of errors of undefined references for methods declared in libannotations. But when I give the following arguments:

$ icc -L../annotations -o ../bin/cg.B_annot cg_annot.o ../common/c_print_results.o ../common/c_randdp.o ../common/c_timers.o ../common/c_wtime.o  -openmp -lrt -lannotations

It works flawlessly! What am I missing??

Thanks,
Pranith 

6 Beiträge / 0 neu
Letzter Beitrag
Nähere Informationen zur Compiler-Optimierung finden Sie in unserem Optimierungshinweis.

This is actually during the linking phase. Is there any documentation as to which order one should pass the flags to the linker?

Thanks,
Pranith

I think the compile and link options can be written in any order.
Generally in Unix/Linux/OSX, man page of the command will tell you the calling syntay.
So "man icc" tells you the correct order.
But order of linking matters very much; you shuld list them in order of dependency. Library which does not depend on anything else, should be last, and library, which calls functions from other library, should be in front of it.
Generally, there are no instructions for link order of all libraries in the world. You should know what you use put libraries in the correct order.
Usually, every library or toolkit comes wiht some examples, and you should copy what the authors provided. Problems arise when you use several libraries for different purposes, like jpeg, png, Xlib, Xt, freetype... and each of them implicitly uses some other library.
But i think your case is simple enough:
1) compiler
2) compile/link options
3) object files
4) libraries

The group of arguments passed to gnu ld must comply with the rules of that application (gnu binutils manual). If you want multiple passes through libraries, you have options (not mentioned here) to specify that, but you don't get it by default.
In the original question, the linker was asked to search the libraries before any references to their contents were established by processing .o file.
It's logical to place the -openmp option as you did in the first example; icc is responsible for placing the resulting -l commands at the end of the script passed to ld, but icc doesn't second guess the order of objects and libraries you specify.
You can add the -# option to see what goes in the linker script.

Best Reply

You're using '-L' ( upper case ) and '-l' ( lower case ) switches. In the second case you've changed the position of '-l' option and that is why everything was right and an executable was built. Even if these two switches instruct the linker to search for additional libraries there are some differences:
...
-L - Tells the linker to search for libraries in a specified directory before searching the standard directories
...
-l - Tells the linker to search for a specified library when linking
...
Remember, that libraries and object files are searched by the linker in the order they are specified.

Zitat:

pranith schrieb:

This is actually during the linking phase. Is there any documentation as to which order one should pass the flags to the linker?

Thanks,
Pranith


...
Please take a look at:
...
http://software.intel.com/sites/products/documentation/hpc/composerxe/en...

...

Kommentar hinterlassen

Bitte anmelden, um einen Kommentar hinzuzufügen. Sie sind noch nicht Mitglied? Jetzt teilnehmen