Search code examples
c++ld

G++ error with -lxnt flag after xlnt is installed


I am trying to install the xlnt library on Ubuntu 18. I have installed xlnt exactly as the instructions say on the repo. When I try to compile my code, the following error pops up:

/usr/bin/ld: cannot find -lxlnt
collect2: error: ld returned 1 exit status
makefile:204: recipe for target 'BOF-debug-static' failed
make: *** [BOF-debug-static] Error 1

I have been installing other libraries to get the code working, and I've noticed that the other libraries are creating .a files at /usr/local/lib along with a few other .la, and .so files. When I install xlnt, it is not creating any .a files, but does create a .so and .so.1.2 files. Not sure if that is relevant, but it's something I've noticed.

How do I make xlnt discoverable to g++ and get the -lxlnt flag to work?


Solution

  • The target you are building BOF-debug-static is evidently one that requests either a fully static linkage, with the -static linkage option, or possibly one that requests static linkage specifically of libxlnt, with a linkage option such as:

    -Wl,-Bstatic -lxlnt -Wl,-Bdynamic
    

    Since, as you observed, libxlnt by default provides only a shared/dynamic library libzlint.so ( -> libzlint.so.X.Y.Z), and no static library libzlnt.a, the linker ignores the the shared library when required to link -lxlnt statically and says:

    /usr/bin/ld: cannot find -lxlnt
    

    You cannot link a shared library statically.

    However, if you configure the CMake build system with:

    cmake -DSTATIC=ON [your previous options...]
    

    then make will build a static library and running make install (as root) will create /usr/local/lib/libxlnt.a.