Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.8k views
in Technique[技术] by (71.8m points)

linux - Why does order in which input libraries are specified matter?

I'm quite new to programming for Linux. You could say I'm a Windows guy. So, I was porting my project to Linux, and it almost made me insane: I'm sure I have specified all the dependencies with -l flag, and yet I'm getting "unresolved symbol" errors. Then I've found this topic, and it solved my problem: Boost linking on Linux with GCC

Could someone please explain me why does the order matter, and how exactly it matters? I'm pretty sure it is not the case with MSVC linker...

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

From "An Introduction to GCC - for the GNU compilers gcc and g++"

The traditional behavior of linkers is to search for external functions from left to right in the libraries specified on the command line. This means that a library containing the definition of a function should appear after any source files or object files which use it.

I believe that msvc linkers do 2 passes over the code so they might be able to resolve the symbols even when the libraries are specified in different order (reference missing ...)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share

2.1m questions

2.1m answers

63 comments

56.6k users

...