CMake链接错误(未定义引用) [英] CMake linking error (undefined reference to)

查看:542
本文介绍了CMake链接错误(未定义引用)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用SSL-Vision软件。它有一个示例客户,我一直试图将其与整个项目分开。我找到了自己编辑客户端所需的资源,因此我只是从软件中复制了它们,并使用CMake来构建我的客户端。



下面的项目结构被简化,缩小了

 
├──CMakeLists.txt
├──main.cc
├──建立
│├──CMakeLists.txt
│└──messages_ssl_ .. 。(.cc / .h,每个4个)
└──src
├──CMakeLists.txt
└──(其他子目录和源/标题)

./ CMakeLists.txt

  cmake_minimum_required(版本2.6)
项目(TestClient)

find_package(需要PkgConfig)
pkg_check_modules(QTCORE_PKG QtCore)
include_directories ($ {QTCORE_PKG_INCLUDE_DIRS})

include(FindProtobuf)
find_package(需要Protobuf)
include_directories($ {PROTOBUF_INCLUDE_DIRS})

find_package(PkgConfig REQUI )
pkg_check_modules(GLIB_PKG glib-2.0)
include_directories($ {GLIB_PKG_INCLUDE_DIRS})

include_directories( src)
add_subdirectory(src)

include_directories( build)
add_subdirectory(build)


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_c $ p $ c $ p $ c $ p $ c $ p $ c $ p code b

./ build / CMakeLists.txt

  add_library(messages_robocup_ssl_detection .pb共享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) b
$ b 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 
//其他protobuf包含

messages_robocup_ssl_wrapper.h

  #include messages_robocup_ssl_detection.pb.h 
#include messages_robocup_ssl_geometry.pb.h
//其他protobuf包括

在每个.cc文件中仅包含其标头和其他probubuf库。



最后,当我制作时,会产生以下错误:

 链接CXX可执行文件clientTest 
build / libmessages_robocup_ssl_wrapper.pb.so:未定义对 SSL_GeometryData :: ByteSize()const的引用
build / libmessages_robocup_ssl_wrapper.pb.so:未定义对SSL_GeometryData :: MergeFrom(SSL_GeometryData const& '
构建/库ages_robocup_ssl_wrapper.pb.so:对`protobuf_AddDesc_messages_5frobocup_5fssl_5fgeometry_2eproto()的未定义引用
build / libmessages_robocup_ssl_wrapper.pb.so:对SSL_GeometryData.bbsso的未定义引用对`SSL_GeometryData :: SSL_GeometryData()'的引用
build / libmessages_robocup_ssl_wrapper.pb.so:对`SSL_GeometryData :: default_instance()'的引用未定义:: SerializeWithCachedSizesToArray(unsigned char *)const'
build / libmessages_robocup_ssl_wrapper.pb.so:未定义对`SSL_GeometryData :: MergePartialFromCodedStream(google :: protobuf :: io :: CodedInputStream *)'的引用
collect2: ld返回1个退出状态
make [2]:** [clientTest]错误1
make [1]:** [CMakeFiles / clientTest.dir / all]错误2
make:* * [all] Erro 2

我已经尝试了一段时间。
如果 libmessages_robocup_ssl_wrapper.pb.so 为什么在链接之前已经构建,它会显示错误?

解决方案

很可能是链接顺序。



看起来像 messages_robocup_ssl_wrapper.pb 取决于 messages_robocup_ssl_geometry.pb 。如果是这样,包装程序应该在链接行中的几何体之前

  target_link_libraries(clientTest robocup_ssl_client 
messages_robocup_ssl_detection.pb
messages_robocup_ssl_wrapper.pb
messages_robocup_ssl_geometry.pb
messages_robocup_ssl_refbox_log.pb
netraw
robocup_ssl_client
protobu
netraw
robocup_ssl_client
protobu b

更好的是,让CMake照顾这样的依赖项。



如果添加...

  target_link_libraries(messages_robocup_ssl_wrapper.pb 
messages_robocup_ssl_geometry.pb)

然后,当 messages_robocup_ssl_wrapper.pb 为CMake时,CMake将自动保留该依赖项。指定为另一个的依赖项目标。如果这样做,则可以选择从 target_link_libraries(clientTest ...)调用中省略 messages_robocup_ssl_geometry.pb


I am working with the SSL-Vision software. It has an example client that I've been trying to separate from the whole project. I found the sources needed to edit a client myself, so I just copied them from the software and used CMake to build my client.

The project structure below is simplified, narrowing to the issue (I believe!).

.
├── 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(VERSION 2.6)
project( TestClient )

find_package( PkgConfig REQUIRED )
pkg_check_modules( QTCORE_PKG QtCore )
include_directories( ${QTCORE_PKG_INCLUDE_DIRS} )

include(FindProtobuf)
find_package( Protobuf REQUIRED )
include_directories( ${PROTOBUF_INCLUDE_DIRS} )

find_package( PkgConfig REQUIRED )
pkg_check_modules( GLIB_PKG glib-2.0 ) 
include_directories( ${GLIB_PKG_INCLUDE_DIRS} )

include_directories( "src" ) 
add_subdirectory( src )

include_directories( "build" ) 
add_subdirectory( build )


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 )

It could be a missing #include in the messages_ssl_... files, but they all are auto-generated and seems to be correct.

In messages_robocup_ssl_detection.pb.h and messages_robocup_ssl_detection.pb.h there are only protobuf includes.

In messages_robocup_ssl_refbox_log.pb.h:

#include "messages_robocup_ssl_detection.pb.h"
// Other protobuf includes

In messages_robocup_ssl_wrapper.h:

#include "messages_robocup_ssl_detection.pb.h"
#include "messages_robocup_ssl_geometry.pb.h"
// Other protobuf includes

In each .cc file is included only its header and other protobuf libs.

Finally, when I do make, the following error is generated:

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

I've been trying to fix this for some time. Why is the libmessages_robocup_ssl_wrapper.pb.so showing errors if it has already been built before the linkage?

解决方案

It could well be the linking order.

It looks like messages_robocup_ssl_wrapper.pb depends on messages_robocup_ssl_geometry.pb. If so, wrapper should come before geometry in the link line.

target_link_libraries( clientTest robocup_ssl_client
                       messages_robocup_ssl_detection.pb
                       messages_robocup_ssl_wrapper.pb
                       messages_robocup_ssl_geometry.pb
                       messages_robocup_ssl_refbox_log.pb
                       netraw
                       robocup_ssl_client
                       protobuf
                       QtCore )

Even better, let CMake take care of dependencies like this.

If you add...

target_link_libraries( messages_robocup_ssl_wrapper.pb
                       messages_robocup_ssl_geometry.pb )

then CMake will automatically retain that dependency when messages_robocup_ssl_wrapper.pb is specified as a dependency of another target. If you do this, then you can choose to omit messages_robocup_ssl_geometry.pb from the target_link_libraries( clientTest ... ) call.

这篇关于CMake链接错误(未定义引用)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆