3

If I have two libraries with the same library name but stored in different directories (and they may contain different code) and I list both directories in the LDFLAGS variable in a makefile, how does the linker know where to look first and which library to use?

  LDFLAGS+= \
        -L${INSTALL_DIR}/lib\
        -L${EVO_INSTALL_DIR}/lib\

Will it look in the INSTALL_DIR path first or in the EVO_INSTALL_DIR path?

1 Answer 1

3

INSTALL_DIR. It will look in the order they are listed.

By the way, it's your linker (probably the same program as your compiler) that's making this choice, not the Makefile. Make (which is reading your Makefile) only runs the build tools.

1
  • I've done some major surgery on the question (title and content) which render your second paragraph less important. Your observation is entirely accurate, and the first version of the question appeared to show major confusion about which program is doing what. You get my +1 because you picked out and correctly answered the two salient points from the original (libraries searched in order of the directories listed on the command line, and it is the linker doing the searching, not make and even less the makefile). Nov 2, 2012 at 19:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.