ImportC linking issue

Andrey Zherikov andrey.zherikov at gmail.com
Sun Nov 13 11:15:16 UTC 2022


On Saturday, 12 November 2022 at 10:02:12 UTC, confuzzled wrote:
> Why would I have to search for libcrypto, libminizip, libexpat, 
> and more that I haven't even figured out what library they are? 
> I thought those dependencies would already be linked into 
> libxlsxio_read.a which is a statically linked library.

This is called transitive dependencies.

For Unix systems linking a static library is not a linking per 
se, it means putting object files (.o) into an archive (.a) using 
[ar](https://linux.die.net/man/1/ar). So "libfoo.a" is just a set 
of object files that don't know anything about their dependencies 
and if you use something from libfoo.a, you might need to add 
another library to you link line. Technically there are two 
possible cases: (1) function that you use doesn't depend on 
anything else, then you don't need to add anything to your link 
line; and (2) function uses something from,  say libbar.a - then 
you have to add libbar.a to your link line.

Dynamic libraries (.so) are treated the same way as executables: 
they are created by linker ([ld](https://linux.die.net/man/1/ld) 
for example) and so they have to have all symbols resolved.  This 
means that if libfoo.so depends on libbar.a then the latter is 
already baked in into the former so your don't need to specify it 
when you link with libfoo.so. TBH I don't remember whether you 
should add libbar.so (dynamic library) which is a dependency of 
libfoo.so to your link line.


More information about the Digitalmars-d-learn mailing list