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

后端 未结 1 1666
甜味超标
甜味超标 2021-01-15 05:16

I use the example code from mongodb site to show the problem here. OS: ArchLiux, c++ is a link to g++

[dean@dell_xps_13 ~]$ c++ --version c++ (GCC) 6

1条回答
  •  爱一瞬间的悲伤
    2021-01-15 05:38

    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.

    0 讨论(0)
自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题