mongodbgccmongo-c-driver

Undefined reference to symbol error when linking Mongo C driver static library


I'm trying to build a program using the Mongo C driver. My CMake configuration includes this:

include_directories("/usr/local/include/libmongoc-1.0")
include_directories("/usr/local/include/libbson-1.0")
...
SET (STATIC_LIBS
    ...
    libmongoc-static-1.0.a
    libbson-static-1.0.a
)

TARGET_LINK_LIBRARIES(myapp ${STATIC_LIBS})

Compile stage goes fine (so it seems that includes are correctly found), but when the linking stage takes place I get this error:

/usr/bin/ld: /usr/local/lib/libmongoc-static-1.0.a(mongoc-counters.c.o): undefined reference to symbol 'shm_unlink@@GLIBC_2.2.5'
//lib/x86_64-linux-gnu/librt.so.1: error adding symbols: DSO missing from command line

It seems it correctly find the static library file but something in it doesn't like it...

Somebody has found a similar error? Is there any known solution?

Some additional info about my system:

Thanks!

EDIT: debugging on this, I have discovered that if I build the Mongo C driver without SHM counters support this way:

cmake -DENABLE_AUTOMATIC_INIT_AND_CLEANUP=OFF -DENABLE_SHM_COUNTERS=OFF -DENABLE_STATIC=ON ..

Then the above error disappears. However, this new and similar one happens:

/usr/bin/ld: /usr/local/lib/libmongoc-static-1.0.a(mongoc-scram.c.o): undefined reference to symbol 'usprep_close_57'
//usr/lib/x86_64-linux-gnu/libicuuc.so.57: error adding symbols: DSO missing from command line

Solution

  • I think I finally solved the problem this way (after looking to this piece of documentation):

    include_directories("/usr/local/include/libmongoc-1.0")
    include_directories("/usr/local/include/libbson-1.0")
    ...
    
    find_package (mongoc-1.0 1.17.4 EXACT)
    
    SET (STATIC_LIBS
        ...
        mongo::mongoc_static
    )
    
    TARGET_LINK_LIBRARIES(myapp ${STATIC_LIBS})
    

    I didn't need to use -DENABLE_SHM_COUNTERS=OFF -DENABLE_STATIC=ON to build the driver and the recommended way in documentation worked:

    cmake -DENABLE_AUTOMATIC_INIT_AND_CLEANUP=OFF ..