Very strange linker behavior

后端 未结 8 2083
猫巷女王i
猫巷女王i 2020-12-07 17:56

This is strange because I was able to get the error below to go away by removing the reference to libm.

gcc -o example example.o -Wl -L/home/kensey/cdev/lib          


        
相关标签:
8条回答
  • 2020-12-07 18:27

    Just to add to the list of answers, http://fedoraproject.org/wiki/UnderstandingDSOLinkChange It is informative. It isn't relevant to the question asked above, but, the explanation relates to the error message /usr/bin/ld: note: 'some_reference' is defined in DSO some.so so try adding it to the linker command line

    0 讨论(0)
  • 2020-12-07 18:29

    The explanation to what's happening is very simple:

    1. Your libgplot.a depends on libm.so, yet the order of -lm and -lgplot on the link line is wrong. The order of libraries on the link line does matter. In general, system libraries (-lpthread, -lm, -lrt, -ldl) should follow everything else on the link line.

    2. When you remove -lm from the link line, libm.so.6 is still pulled into the link by some other library that appears later on the link line (libgd, libxml2 or libcurl) because that library depends on libm.so.6. But now libm.so.6 is in correct place on the link line, and so everything works.

    if I put -lm at the end of the link command, listing it as the last library, I do not get the error.

    That confirms above explanation.

    0 讨论(0)
提交回复
热议问题