1

I'm trying to build a project that depends on binary distributed static libraries.

The linker complains it cannot find ini_config functions, among others:

config_params.c:(.text+0x16f): undefined reference to  `ini_get_config_valueobj'

It finds the dynamic libraries, but not the static version:

attempt to open /usr/lib/gcc/x86_64-linux-gnu/7/libini_config.a failed
attempt to open /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libini_config.so succeeded

Those files are present on debian stretch. Is there a way to get them on ubuntu as well ?

stamm
  • 51
  • 1
  • 4
  • 1
    Those are also available on Ubuntu: https://packages.ubuntu.com/search?suite=bionic&arch=any&mode=exactfilename&searchon=contents&keywords=libini_config.a – muru Jul 05 '18 at 15:07
  • 1
    The location is different there `/usr/lib/x86_64-linux-gnu/libini_config.a` than where it is looking... you will probably need to make sure `libini-config-dev` is installed and then include `/usr/lib/x86_64-linux-gnu` when compiling. – SudoSURoot Jul 05 '18 at 15:11
  • Yes, there it is! Thank you, I've missed that. But the linker is looking into `/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/` and finds the `.so`, how can I change that? – stamm Jul 05 '18 at 15:24
  • So, according to [this question](https://stackoverflow.com/questions/6578484/telling-gcc-directly-to-link-a-library-statically), I just need to replace `-ldl` with `-l:libdl.a`. – stamm Jul 05 '18 at 15:31

1 Answers1

4

All packages seem to install their static libraries. They can be found in /usr/lib/x86_64-linux-gnu.

Apparently, the linker first picks the dynamic libraries when using -lsomelib. To override that, you can use the -l:libsomelib.a, it will then only match the exact filename somelib.a. Use -L/usr/lib/x86_64-linux-gnu the same way as for "linking" dynamic libraries.

To debug the library searching phase, you can add -Wl, --verbose to your LDFLAGS. gcc will then display every path it tries for your -lXXX options.

Keep in mind that archives are checked only once, as stated in this answer, if some symbols are still not found, you maybe have to reorder the parameters.

BeastOfCaerbannog
  • 12,964
  • 10
  • 49
  • 77
stamm
  • 51
  • 1
  • 4