我正在使用SSL-Vision软件。它有一个示例客户端,我一直试图从整个项目中分离出来。我发现自己需要编辑客户端的源代码,所以我只是从软件中复制它们并使用CMake来构建我的客户端。CMake链接错误(未定义参考)
下面的项目结构被简化,缩小到问题(我相信!)。
.
├── CMakeLists.txt
├── main.cc
├── build
│ ├── CMakeLists.txt
│ └── messages_ssl_... (.cc/.h, 4 each)
└── src
├── CMakeLists.txt
└── (Other subdirs and sources/headers)
./CMakeLists.txt:
cmake_minimum_required(版本2.6)
项目(TestClient的)find_package(PkgConfig必填)
pkg_check_modules(QTCORE_PKG QtCore)
include_directories($ {QTCORE_PKG_INCLUDE_DIRS})包括(FindProtobuf)
find_package(的Protobuf REQUIRED)
include_directories($ {PROTOBUF_INCLUDE_DIRS})find_package(PkgConfig REQUIRED)
pkg_check_modules(GLIB_PKG油嘴-2.0)
include_directories($ {GLIB_PKG_INCLUDE_DIRS})include_directories( “SRC”)add_subdirectory(SRC)
include_directories(“BUIL d”)add_subdirectory(构建)
add_executable(clientTest clientTest.cc)
target_link_libraries(clientTest robocup_ssl_client messages_robocup_ssl_detection.pb messages_robocup_ssl_geometry.pb messages_robocup_ssl_wrapper.pb messages_robocup_ssl_refbox_log.pb netraw robocup_ssl_client protobuf的QtCore)
./build/CMakeLists.txt:
add_library(messages_robocup_ssl_detection.pb SHARED messages_robocup_ssl_detection.pb.cc)
add_library(messages_robocup_ssl_refbox_log.pb SHARED messages_robocup_ssl_refbox_log.pb.cc)
add_library(messages_robocup_ssl_geometry.pb SHARED messages_robocup_ssl_geometry.pb.cc)
add_library(messages_robocup_ssl_wrapper.pb SHARED messages_robocup_ssl_wrapper.pb.cc)
在messages_ssl_...
文件中可能缺少#include,但它们都是自动生成的,似乎是正确的。
在messages_robocup_ssl_detection.pb.h
和messages_robocup_ssl_detection.pb.h
只有protobuf包括。
在messages_robocup_ssl_refbox_log.pb.h
:
#include "messages_robocup_ssl_detection.pb.h"
// Other protobuf includes
在messages_robocup_ssl_wrapper.h
:
#include "messages_robocup_ssl_detection.pb.h"
#include "messages_robocup_ssl_geometry.pb.h"
// Other protobuf includes
在各.cc文件仅包括其标题和其他的protobuf库。
最后,当我做,会生成以下错误:
Linking CXX executable clientTest
build/libmessages_robocup_ssl_wrapper.pb.so: undefined reference to `SSL_GeometryData::ByteSize() const'
build/libmessages_robocup_ssl_wrapper.pb.so: undefined reference to `SSL_GeometryData::MergeFrom(SSL_GeometryData const&)'
build/libmessages_robocup_ssl_wrapper.pb.so: undefined reference to `protobuf_AddDesc_messages_5frobocup_5fssl_5fgeometry_2eproto()'
build/libmessages_robocup_ssl_wrapper.pb.so: undefined reference to `SSL_GeometryData::Clear()'
build/libmessages_robocup_ssl_wrapper.pb.so: undefined reference to `SSL_GeometryData::SSL_GeometryData()'
build/libmessages_robocup_ssl_wrapper.pb.so: undefined reference to `SSL_GeometryData::default_instance()'
build/libmessages_robocup_ssl_wrapper.pb.so: undefined reference to `SSL_GeometryData::SerializeWithCachedSizesToArray(unsigned char*) const'
build/libmessages_robocup_ssl_wrapper.pb.so: undefined reference to `SSL_GeometryData::MergePartialFromCodedStream(google::protobuf::io::CodedInputStream*)'
collect2: ld returned 1 exit status
make[2]: ** [clientTest] Erro 1
make[1]: ** [CMakeFiles/clientTest.dir/all] Erro 2
make: ** [all] Erro 2
我一直在试图解决这一问题有一段时间了。 为什么libmessages_robocup_ssl_wrapper.pb.so
显示错误,如果它已经建立在链接之前?
如果有任何额外的信息需要,请问!
它的工作! 就像你所说的那样只是换了一条线,而且它完美地工作。 我还添加了这两行,CMake从现在开始已经知道'messages_robocup_ssl_wrapper.pb'依赖于'messages_robocup_ssl_geometry.pb'。 谢谢! – Lucas
好东西。很高兴你修好了它。 – Fraser