g++ cannot static link libmongcxx(r3.0.2) but dynamic link works g++ cannot static link libmongcxx(r3.0.2) but dynamic link works mongodb mongodb

g++ cannot static link libmongcxx(r3.0.2) but dynamic link works


The -static flag forces the linker to accept only static libraries and not any shared libraries. In other words it does not require a dependency on dynamic libraries at runtime in order to run.Most likely mongocxx has some dependencies.To achieve static linking requires that the archive (.a) versions of your libraries exist on the system.

The another possible issue is that the order of static libraries in the linker command line does matter, so that might also be an issue if there is a dependency on different static libs. The linker will process the libraries in order as they are in the command line, and from each static lib it will only pull those symbols that are required (with as much information as the linker has at that time)

Use nm . That will give you the symbol names.