具有相同库头文件版本冲突的依赖项

时间:2020-05-20 15:38:49

标签: c++ cmake linker dependencies

我编译了一个使用tensorflow C api的简单程序,因此我将其链接到c_api.h标头和libtensorflow.so上。它可以编译并链接到program

当我使用ldd program检查可执行文件的库依赖关系时,会得到直接依赖关系及其位置:

linux-vdso.so.1 (0x00007ffc5bf4e000)

libtensorflow_framework.so.1 => /home/myuser/libtensorflow/lib/libtensorflow_framework.so.1 (0x00007fd35d341000)

libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fd35f34a000)

(...other libraries...)

但是,当我运行该程序时,我得到的错误描述为here

[libprotobuf FATAL external/protobuf/src/google/protobuf/stubs/common.cc:78] 
This program was compiled against version 2.6.1 of the Protocol Buffer runtime library, which is not compatible with the installed version (3.1.0). 
Contact the program author for an update. 
If you compiled the program yourself, make sure that your headers are from the same version of Protocol Buffers as your link-time library.

libprotobuf不在可执行文件的直接依赖项列表中,因此我认为它是 sub依赖项 (即,链接的库之一的依赖项)

我的理解是,dependency-that-uses-protobuf.so库是使用libprotobuf.so.2.6.1文件编译的,而我的编译器使用的是同一库但版本3.1.0的标头。 正确吗?

如果是这样,我如何告诉链接器使用该特定库版本的标头(而不是其他版本的(使用CMAKE))来进行编译,从而防止运行时错误并获得链接器错误。 (?)

我的困惑是因为到目前为止,我仅指定了链接库,这些链接库是可执行文件的直接依赖项,因此我不知道(如果我应该的话)链接属于子依赖项的库。 / em>

1 个答案:

答案 0 :(得分:0)

我的解决方法是指定具有兼容protobuf版本的其他OpenCV路径:

# Finds installed opencv with incompatible Protobuff
# find_package( OpenCV REQUIRED ) 

# Finds the opencv with compatible Protobuf in my system
find_package( OpenCV REQUIRED PATHS /usr/local NO_DEFAULT_PATH)

说明

opencv库和tensorflow库都是通过静态链接编译到libprotobufhence they don't show up with ldd command的。但是在编译时仍然需要头文件,并且头文件的版本相互冲突。