Can't link against mongocxx static libraries

112 Views Asked by At

I have install mongocxx's both static and dynamic libraries.

$ l /usr/local/lib/libmongoc* 
/usr/local/lib/libmongoc-1.0.so@    /usr/local/lib/libmongoc-1.0.so.0.0.0  /usr/local/lib/libmongocxx.so@       /usr/local/lib/libmongocxx.so._noabi@
/usr/local/lib/libmongoc-1.0.so.0@  /usr/local/lib/libmongoc-static-1.0.a  /usr/local/lib/libmongocxx.so.3.8.0  /usr/local/lib/libmongocxx-static.a
$ l /usr/local/lib/libbson*
/usr/local/lib/libbson-1.0.so@    /usr/local/lib/libbson-1.0.so.0.0.0  /usr/local/lib/libbsoncxx.so.3.8.0    /usr/local/lib/libbsoncxx-static.a
/usr/local/lib/libbson-1.0.so.0@  /usr/local/lib/libbsoncxx.so@        /usr/local/lib/libbsoncxx.so._noabi@  /usr/local/lib/libbson-static-1.0.a

Despite giving full path to static libraries of mongocxx using target_link_libraries, I keep getting this error:

main.cpp:(.text.startup+0x5e): undefined reference to `mongocxx::v_noabi::instance::instance()'
/usr/bin/ld: main.cpp:(.text.startup+0x6d): undefined reference to `bsoncxx::v_noabi::builder::core::core(bool)'
/usr/bin/ld: main.cpp:(.text.startup+0x91): undefined reference to `bsoncxx::v_noabi::builder::core::key_view(core::v1::basic_string_view<char, std::char_traits<char> >)'
/usr/bin/ld: main.cpp:(.text.startup+0xb5): undefined reference to `bsoncxx::v_noabi::builder::core::append(bsoncxx::v_noabi::types::b_string const&)'
/usr/bin/ld: main.cpp:(.text.startup+0xc2): undefined reference to `bsoncxx::v_noabi::builder::core::extract_document()'
/usr/bin/ld: main.cpp:(.text.startup+0xca): undefined reference to `bsoncxx::v_noabi::builder::core::~core()'
/usr/bin/ld: main.cpp:(.text.startup+0xe8): undefined reference to `bsoncxx::v_noabi::builder::core::~core()'
/usr/bin/ld: main.cpp:(.text.startup+0xf2): undefined reference to `mongocxx::v_noabi::instance::~instance()'
/usr/bin/ld: main.cpp:(.text.startup+0x112): undefined reference to `mongocxx::v_noabi::instance::~instance()'

I've added the following find_packages commands

find_package(mongocxx REQUIRED)
find_package(bsoncxx REQUIRED)
find_package(mongoc-1.0 REQUIRED)
find_package(mongoc-1.0 REQUIRED)
find_package(bson-1.0 REQUIRED)

and added the libraries to target_link_libraries as follows:

    INTERFACE mongo::mongocxx_static
    INTERFACE mongo::bsoncxx_static
    INTERFACE mongo::bson_static
    INTERFACE mongo::mongoc_static

What am I doing wrong?

P.S. I'm trying to build a static executable.

1

There are 1 best solutions below

1
acm On

You have declared these dependencies as INTERFACE, which indicates that the target itself doesn't depend on them, but that dependencies of the target do. As a result, those libraries are not being included in the link for your target, since it doesn't depend on them.

If you intend for your target to actually make use of these libraries, they should be added as PUBLIC or PRIVATE to your target.