makefile - Does order of linker flags matter when running linking step in C++? -


my original question below, evolved following related question: is there wrong putting linker flags after objects in linker statement?


when build in eclipse, following linking statement run:

g++ -fopenmp -lconfig++ -o "pc2" ./main.o ./sampling.o ./simulation.o

which incorrect, because lconfig++ must follow, not precede, object file listing. so, modified makefile, automatically generated eclipse based on project settings. specifically, changed portion of makefile

# tool invocations pc2: $(objs) $(user_objs)     @echo 'building target: $@'     @echo 'invoking: gcc c++ linker'     g++ -fopenmp -lconfig++ -o "pc2" $(objs) $(user_objs) $(libs)     @echo 'finished building target: $@'     @echo ' ' 

to follows:

# tool invocations pc2: $(objs) $(user_objs)     @echo 'building target: $@'     @echo 'invoking: gcc c++ linker'     g++ -o "pc2" $(objs) $(user_objs) $(libs) -fopenmp -lconfig++      @echo 'finished building target: $@'     @echo ' ' 

then, after modifying 1 line of makefile, entered

make clean -c release

at command line, produced following correct linking statement:

g++ -o "pc2" ./main.o ./sampling.o ./simulation.o -fopenmp -lconfig++

therefore, know how fix makefile build process correct.

what not know how configure eclipse makefile generates places linker flags (or "options"?) @ correct location.

you've answered own question: yes, order of objects , libraries on link line does matter.

is there reason why might need linker flags precede object files?

there may well exist such linker flags. example --start-group gnu-ld linker options must (obviously) precede library group starts. --start-lib gold linker option must (obviously) precede objects form library, etc.

i discovered move ${flags} in settings

you have included -lconfig++ in ${flags} somewhere in eclipse, , that's mistake -- -lconfig++ not linker flag (even though looks one), it's library specification, , should included in ${libs} or such.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -