与同一库的 header 版本冲突的依赖项
Dependencies with conflicting header versions of the same library
我编译了一个使用 tensorflow C api 的简单程序,所以我 link 它针对 c_api.h
headers 和 libtensorflow.so
。它编译 links 到 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...)
但是,当我 运行 程序时,我得到了与 描述相同的错误:
[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
不在可执行文件的直接依赖项列表中,因此我假设它是 子依赖项 (即依赖项其中一个图书馆 linked)。
我的理解是,库 dependency-that-uses-protobuf.so
是使用 libprotobuf.so.2.6.1
文件编译的,而我的编译器使用的是同一库的 headers,但版本为 3.1.0。 对吗?
如果是这样,我如何告诉 linker 使用特定库版本的 headers 进行编译,而不是其他版本 (使用 CMAKE),从而防止 运行time 错误并得到 linker 错误。 (?)
我的困惑是因为到目前为止我只指定了 link 库,它们是可执行文件的直接依赖项,所以我不知道如何(如果我应该)link 库 sub-dependencies.
我的解决方法是指定一个具有兼容 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 库都是使用 静态链接 到 libprotobuf
、hence they don't show up with ldd
command 编译的。但是编译时仍然需要头文件,并且两者的头文件版本冲突。
我编译了一个使用 tensorflow C api 的简单程序,所以我 link 它针对 c_api.h
headers 和 libtensorflow.so
。它编译 links 到 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...)
但是,当我 运行 程序时,我得到了与
[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
不在可执行文件的直接依赖项列表中,因此我假设它是 子依赖项 (即依赖项其中一个图书馆 linked)。
我的理解是,库 dependency-that-uses-protobuf.so
是使用 libprotobuf.so.2.6.1
文件编译的,而我的编译器使用的是同一库的 headers,但版本为 3.1.0。 对吗?
如果是这样,我如何告诉 linker 使用特定库版本的 headers 进行编译,而不是其他版本 (使用 CMAKE),从而防止 运行time 错误并得到 linker 错误。 (?)
我的困惑是因为到目前为止我只指定了 link 库,它们是可执行文件的直接依赖项,所以我不知道如何(如果我应该)link 库 sub-dependencies.
我的解决方法是指定一个具有兼容 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 库都是使用 静态链接 到 libprotobuf
、hence they don't show up with ldd
command 编译的。但是编译时仍然需要头文件,并且两者的头文件版本冲突。