无法正确链接CMakeLists中的库

时间:2019-11-07 13:53:51

标签: cmake ros catkin

在将源文件(我已将它们作为库添加到我的CMakeLists中)链接到我的主文件时遇到了一些麻烦。这是我的CMakeLists

cmake_minimum_required(VERSION 2.8.3)
project(ros_bridge)

set(${PROJECT_NAME}_CATKIN_COMPONENTS
  nav_msgs
  roscpp
  sensor_msgs
  std_msgs
)

add_compile_options(-std=c++14)

find_package(catkin REQUIRED COMPONENTS ${${PROJECT_NAME}_CATKIN_COMPONENTS})
find_package(RapidJSON REQUIRED)

catkin_package(
  INCLUDE_DIRS
    include
    include/aws_iot_sdk
    include/common
    include/network
  CATKIN_DEPENDS ${${PROJECT_NAME}_CATKIN_COMPONENTS}
)


include_directories(
  include
  include/aws_iot_sdk
  ${catkin_INCLUDE_DIRS}
)

## Libraries

add_library(ros_client src/ros_client.cpp)
add_library(ConfigCommon include/common/ConfigCommon.cpp)
add_library(OpenSSL include/network/OpenSSL/OpenSSLConnection.cpp)
add_library(WebSocket include/network/WebSocket/WebSocketConnection.cpp)

add_executable(ros_bridge_node src/main.cpp)

## Lib links
target_link_libraries(ros_client ConfigCommon ${catkin_LIBRARIES} ${RapidJSON_LIBRARIES} OpenSSL WebSocket)
target_link_libraries(ConfigCommon ${catkin_LIBRARIES} ${RapidJSON_LIBRARIES} OpenSSL WebSocket)

target_link_libraries(ros_bridge_node ${catkin_LIBRARIES} ros_client ConfigCommon OpenSSL WebSocket ${RapidJSON_LIBRARIES})

因此,当编译器尝试链接主文件(即ros_bridge_node)时,出现链接错误:

ros_client.cpp:(.text+0x605): undefined reference to `awsiotsdk::util::Logging::GetLogSystem()'
ros_client.cpp:(.text+0x66d): undefined reference to `awsiotsdk::ResponseHelper::ToString[abi:cxx11](awsiotsdk::ResponseCode)'
CMakeFiles/ros_bridge_node.dir/src/ros_client.cpp.o: In function `ros_bridge::RosClient::RunPublish(int&)':
ros_client.cpp:(.text+0x8d9): undefined reference to `awsiotsdk::Utf8String::Create(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
/home/abyl/master-wheel/devel/lib/libWebSocket.so: undefined reference to `BIO_push'
/home/abyl/master-wheel/devel/lib/libWebSocket.so: undefined reference to `awsiotsdk::NetworkConnection::Read(std::vector<unsigned char, std::allocator<unsigned char> >&, unsigned long, unsigned long, unsigned long&)'
/home/abyl/master-wheel/devel/lib/libConfigCommon.so: undefined reference to `awsiotsdk::util::JsonParser::InitializeFromJsonFile(rapidjson::GenericDocument<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator>, rapidjson::CrtAllocator>&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/home/abyl/master-wheel/devel/lib/libWebSocket.so: undefined reference to `SHA1'
/home/abyl/master-wheel/devel/lib/libWebSocket.so: undefined reference to `BIO_f_base64'
/home/abyl/master-wheel/devel/lib/libWebSocket.so: undefined reference to `awsiotsdk::network::OpenSSLConnection::IsPhysicalLayerConnected()'
/home/abyl/master-wheel/devel/lib/libWebSocket.so: undefined reference to `BIO_set_flags'
/home/abyl/master-wheel/devel/lib/libWebSocket.so: undefined reference to `BIO_new'

那么如何正确地将库链接到我的Main文件?

编辑:

我有setaws_iot_sdk的目标文件,如下所示:

set(${aws_sdk} /home/ren/aws-iot-device-sdk-cpp/build/CMakeFiles/aws-iot-sdk-cpp.dir/src)


set_source_files_properties(
  ${aws_sdk_path}
  PROPERTIES
  EXTERNAL_OBJECT true
  GENERATED true
)

并尝试将其链接到我的主文件:

target_link_libraries(ros_bridge_node ros_client ConfigCommon Open WebSocket wslay ${RapidJSON_LIBRARIES} ${catkin_LIBRARIES} -lssl ${aws_sdk})

但是仍然遇到相同的链接问题。可能是我将目标文件链接错误了吗? (现在所有的链接问题都来自aws_iot_sdk

0 个答案:

没有答案