Sign in to follow this  
fir

question about linking

Recommended Posts

I always do not know this - If i link many object  modules (or library) and thay contain the functions that are not called from my code will they be linked to or stripped out form final exe? Thare maybe may be some differences in behavoiur of modules and libraries but im not sure..

 

?

 

 

Share this post


Link to post
Share on other sites

If you're talking about static libs, then the behavior depends on the compiler toolchain you're using as well as the settings provided for the linker. In Visual C++ for instance, dead-code stripping is controlled by the /OPT:REF command-line option.

Share this post


Link to post
Share on other sites

c standard is not saying something? or some common rule - that it is linked in or not?

Share this post


Link to post
Share on other sites

c standard is not saying something? or some common rule - that it is linked in or not?

"Linking" is not a concept addressed by the language standard, no.  There is no requirement in the language standard that a system offer separate compilation of modules, and indeed there are embedded systems that do not.

 

Practically, though, most modern (post-1960s at least) linkers will normally only satisfy undefined symbols from a static archive (library).  Dynamic shared objects (DLLs, .so files, .dylibs and so on) are loaded by the dynamic link-loader in their entirety, just as an executable is, but their symbol relocation tables may not be resolve until required (so-called "lazy" loading).  Command-line options can be used to vary that behaviour (eg. --Wl,-whole-archive passed to GCC).

 

Symbols from object modules may also have unreferenced symbols stripped.  That's going to depend on your linker and likely on the options passed o the linker.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this