undefined reference to symbol '_ZN3pcl7console5printENS0_15VERBOSITY_LEVELEPKcz' - c++

`I am simply trying to compile a program in ROS . I already linked all the necessary libraries but this one I can't find. All I am getting is the following error in codeblocks (also in eclipse).
Anybody know how to get rid of this error? Or even which library it require?
cmake_minimum_required(VERSION 2.8.3)
project(gpuvoxelgetpointcloud)
find_package(catkin REQUIRED COMPONENTS
cmake_modules
roscpp
rospy
std_msgs
sensor_msgs
cv_bridge
image_transport
pcl_conversions
pcl_ros
)
find_package(icl_core REQUIRED )
find_package(gpu_voxels REQUIRED)
find_package(Boost COMPONENTS system REQUIRED)
find_package(orocos_kdl REQUIRED)
find_package(CUDA REQUIRED)
find_package(PCL 1.7 REQUIRED)
#include <pcl_ros/transforms.h>
#include <pcl/conversions.h>
#include <pcl/PCLPointCloud2.h>
Error is:
undefined reference to symbol
'_ZN3pcl7console5printENS0_15VERBOSITY_LEVELEPKcz'
//use/lib/aarch64_linux-gnu/ libpcl-common.so.1.7: error adding symbols:DSO missing from command line collect2:ld returned 1 exit status.
I am using plc on TX2 and maybe there is something wrong with plc on arm.

Try adding the followings to your CMakeLists.txt:
find_package(PCL 1.7 REQUIRED)
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
include_directories(
${PCL_INCLUDE_DIRS}
)
Also, link ${PCL_LIBRARIES} to your targets. Include the necessary header files in your cpp codes.

Related

undefined reference to `boost::system::generic_category()

I'm developing a cpp project in Clion. For the build I use cmake. Last weekend I upgraded from ubuntu 18.04 to 20.04, from then I cannot build my project and I get the error:
/usr/local/include/boost/system/error_code.hpp:221: undefined reference to `boost::system::generic_category()'. It seems that something in the linking isn't right. I reinstalled all packages, tried different versions but nothing. My CMakeLists.txt is:
cmake_minimum_required(VERSION 3.7)
project(pki_cpp)
set(CMAKE_CXX_STANDARD 11)
set(THREADS_PREFER_PTHREAD_FLAG ON)
#find_package(libmongocxx REQUIRED)
find_package(mongocxx REQUIRED)
find_package(bsoncxx REQUIRED)
include_directories(${LIBMONGOCXX_INCLUDE_DIR})
include_directories(${LIBBSONCXX_INCLUDE_DIR})
include_directories(SYSTEM ./lib)
set(BOOST_ROOT /usr/lib/)
find_package(Boost 1.71.0 REQUIRED COMPONENTS system chrono thread filesystem)
include_directories(${Boost_INCLUDE_DIR})
if(NOT Boost_FOUND)
message(FATAL_ERROR "Could not find boost!")
endif()
find_package(Threads REQUIRED)
find_package(OpenSSL REQUIRED)
# A custom library
add_subdirectory(asnDatatypes)
include_directories({CMAKE_CURRENT_SOURCE_DIR} asnDatatypes)
set_property(TARGET asnLibrary PROPERTY POSITION_INDEPENDENT_CODE ON)
# end custom library
#cryptopp library
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/contrib/cmake")
find_package(CryptoPP REQUIRED)
include_directories(${CRYPTOPP_INCLUDE_DIR})
link_directories(${CryptoPP_INCLUDE_DIR})
# end cryptopp
add_executable(pki_cpp main.cpp rootCA.cpp rootCA.h)
target_include_directories(pki_cpp PRIVATE ${Boost_INCLUDE_DIRS} ${LIBMONGOCXX_INCLUDE_DIRS} )
link_directories(pki_cpp ${Boost_LIBRARY_DIRS})
target_link_libraries(pki_cpp ${Boost_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${Boost_FILESYSTEM_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${Boost_LIBRARIES} Boost::system Threads::Threads boost_system asnLibrary OpenSSL::SSL ${CRYPTOPP_LIBRARIES} ${LIBMONGOCXX_LIBRARIES} mongo::bsoncxx_shared mongo::mongocxx_shared ${CMAKE_THREAD_LIBS_INIT} ${Boost_FILESYSTEM_LIBRARY} ${Boost_SYSTEM_LIBRARY} Boost::system)
Any help is appreciated!
That's a lot of stuff, all randomly ordered and commented out. The obvious error is a failure to link Boost System
I'd go with
FIND_PACKAGE(Boost 1.65.0
COMPONENTS system program_options REQUIRED)
LINK_DIRECTORIES(${Boost_LIBRARY_DIRS})
INCLUDE_DIRECTORIES(${Boost_INLUDE_DIRS})
LINK_LIBRARIES(${Boost_LIBRARIES})
Alternatively you can be specific and link specific libs to specific targets
TARGET_LINK_LIBRARIES(mylib ${Boost_SYSTEM_LIBRARY})
TARGET_LINK_LIBRARIES(myexecutable ${Boost_THREAD_LIBRARY})

ROS question: How to compile custom cv_bridge with opencv4 correctly

I want to use opencv-4.4.0 in my ROS program, and I found that to do this I have to compile cv_bridge from source with current opencv version, since cv_bridge shipped from ROS only support opencv3. After some searching I found this which I think is customized to compatible with opencv4:
https://github.com/fizyr-forks/vision_opencv/tree/opencv4
after catkin build and changing include path in my program, this error occurred:
OpenCV Error: Assertion failed (scn == 3 || scn == 4) in cvtColor, file /build/opencv-L2vuMj/opencv-3.2.0+dfsg/modules/imgproc/src/color.cpp, line 9716
terminate called after throwing an instance of 'cv::Exception'
what(): /build/opencv-L2vuMj/opencv-3.2.0+dfsg/modules/imgproc/src/color.cpp:9716: error: (-215) scn == 3 || scn == 4 in function cvtColor
This error is from cv::imshow() after cv_bridge::toCvCopy(msg, sensor_msgs::image_encodings::MONO8); It doesn't really matter because I found after changing the last
argument MONO8 to BGR8, imshow was able to work. So I think I can use BGR8 then change it to grey scale using opencv function later. However from this error message I realized cv_bridge is still trying to use opencv-3.2 instead of opencv-4.4.0. Please help me figure it out how to compile it with correct opencv version! Here's my CMakeLists.txt and package.xml. I changed them a little as original files didn't work for me properly(so as mine).
I'm sorry if they are hard to read.
CMakeLists.txt:
cmake_minimum_required(VERSION 2.8) project(cv_bridge)
find_package(catkin REQUIRED COMPONENTS rosconsole sensor_msgs)
if(NOT ANDROID) find_package(PythonLibs)
if(PYTHONLIBS_VERSION_STRING VERSION_LESS 3)
find_package(Boost REQUIRED python) else()
find_package(Boost REQUIRED python3) endif() else() find_package(Boost REQUIRED) endif()
find_package(OpenCV 4.4.0 REQUIRED COMPONENTS
opencv_core
opencv_imgproc
opencv_imgcodecs CONFIG ) set(OpenCV_DIR=/usr/local/lib/cmake/opencv4)
catkin_package( INCLUDE_DIRS include LIBRARIES ${PROJECT_NAME}
CATKIN_DEPENDS rosconsole sensor_msgs DEPENDS OpenCV CFG_EXTRAS
cv_bridge-extras.cmake )
catkin_python_setup()
include_directories(include ${Boost_INCLUDE_DIRS}
${OpenCV_INCLUDE_DIRS} ${catkin_INCLUDE_DIRS})
if(NOT ANDROID) add_subdirectory(python) endif() add_subdirectory(src)
if(CATKIN_ENABLE_TESTING) add_subdirectory(test) endif()
install( DIRECTORY include/${PROJECT_NAME}/ DESTINATION
${CATKIN_PACKAGE_INCLUDE_DESTINATION} )
package.xml:
<package format="2"> <name>cv_bridge</name>
<version>1.13.0</version> <description>
This contains CvBridge, which converts between ROS
Image messages and OpenCV images. </description> <author>Patrick Mihelich</author> <author>James Bowman</author>
<maintainer email="vincent.rabaud#gmail.com">Vincent
Rabaud</maintainer> <license>BSD</license> <url
type="website">http://www.ros.org/wiki/cv_bridge</url> <url
type="repository">https://github.com/ros-perception/vision_opencv</url>
<urlI'm sorry if it's hard to read.
type="bugtracker">https://github.com/ros-perception/vision_opencv/issues</url>
<export>
<rosdoc config="rosdoc.yaml" /> </export>
<buildtool_depend>catkin</buildtool_depend>
<build_depend>boost</build_depend>
<build_depend>opencv2</build_depend>
<build_depend>python</build_depend>
<build_depend>python-opencv</build_depend>
<build_depend>rosconsole</build_depend>
<build_depend>sensor_msgs</build_depend>
<exec_depend>boost</exec_depend>
<exec_depend>opencv2</exec_depend> <exec_depend>python</exec_depend>
<exec_depend>python-opencv</exec_depend>
<exec_depend>rosconsole</exec_depend>
<build_export_depend>opencv2</build_export_depend>
<build_export_depend>sensor_msgs</build_export_depend>
<test_depend>rostest</test_depend>
<test_depend>python-numpy</test_depend>
<doc_depend>dvipng</doc_depend> </package>
update:
I insert a line of code to print out opencv version in cv_bridge.cpp. And the result is 4.4.0. Does this mean it's using the correct version of opencv and the upper error message is from another package? I checked both cv_bridge and my own program that are both using opencv 4.4.0 as I included. I really run out of idea. Here is what I included:
#include <ros/ros.h>
#include <image_transport/image_transport.h>
#include </home/robotics/catkin_ws/src/vision_opencv-opencv4/cv_bridge/include/cv_bridge/cv_bridge.h>
#include <sensor_msgs/image_encodings.h>
#include <opencv4/opencv2/imgproc/imgproc.hpp>
#include <opencv4/opencv2/highgui/highgui.hpp>
#include <iostream>
I'm answering my own question cause I finally found a solution! According to this post,I found that my CMakeLists.txt of custmized cv_bridge didn't have set (CMAKE_CXX_STANDARD 11). So I added it and catkin build,then try my program and every thing fixed! Here's my whole CMakelists:
cmake_minimum_required(VERSION 2.8)
set (CMAKE_CXX_STANDARD 11)
project(cv_bridge)
find_package(catkin REQUIRED COMPONENTS rosconsole sensor_msgs)
if(NOT ANDROID)
find_package(PythonLibs)
if(PYTHONLIBS_VERSION_STRING VERSION_LESS 3)
find_package(Boost REQUIRED python)
else()
find_package(Boost REQUIRED python3)
endif()
else()
find_package(Boost REQUIRED)
endif()
set(CV_MAJOR_VERSION=4.4.0)
set(OpenCV_DIR=/usr/local/lib/cmake/opencv4)
find_package(OpenCV 4.4.0 REQUIRED
COMPONENTS
core
imgproc
imgcodecs
CONFIG
)
catkin_package(
INCLUDE_DIRS include
LIBRARIES ${PROJECT_NAME}
CATKIN_DEPENDS rosconsole sensor_msgs
DEPENDS OpenCV
CFG_EXTRAS cv_bridge-extras.cmake
)
catkin_python_setup()
include_directories(include ${Boost_INCLUDE_DIRS} ${OpenCV_INCLUDE_DIRS} ${catkin_INCLUDE_DIRS})
if(NOT ANDROID)
add_subdirectory(python)
endif()
add_subdirectory(src)
if(CATKIN_ENABLE_TESTING)
add_subdirectory(test)
endif()
# install the include folder
install(
DIRECTORY include/${PROJECT_NAME}/
DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
)

Add lib*.so to cmake

I've my package with CMakeLists.txt and I have a libNewLib.so compiled from another package from another library (NewLib). I've also the header files of that library that I include like so:
set(LIB_MANUALLY "${CMAKE_CURRENT_SOURCE_DIR}/lib/") #I put the file libNewLib.so here
include_directories(
include/NewLib
)
LINK_DIRECTORIES(${LIB_MANUALLY})
target_link_libraries(estimation libNewLib.so)
But I still get the error:
/usr/bin/ld: cannot find -lNewLib
Is it the correct way to do it?
I tried a couple of solutions but it didn't work.
I'm using Ros kinetic catkin package
make VERSION 2.8.3
Full CMakeLists.txt:
cmake_minimum_required(VERSION 2.8.3)
project(localization)
add_compile_options(-std=c++11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Ofast -march=native")
set(LIB_MANUALLY "${CMAKE_CURRENT_SOURCE_DIR}/lib/")
message(STATUS "LIB_MANUALLY : ${LIB_MANUALLY}")
find_package(catkin REQUIRED COMPONENTS
cv_bridge
image_transport
roscpp
rospy
std_msgs
)
find_package(OpenCV REQUIRED
NO_MODULE # should be optional, tells CMake to use config mode
PATHS /usr/local # look here
NO_DEFAULT_PATH) # and don't look anywhere else
catkin_package(
# INCLUDE_DIRS include
# LIBRARIES localization
CATKIN_DEPENDS cv_bridge image_transport roscpp rospy std_msgs
# DEPENDS system_lib
)
include_directories(
include
include/NewLib
${catkin_INCLUDE_DIRS}
${OpenCV_INCLUDE_DIRS}
)
add_executable(estimation
src/pose_map_estimation.cpp
src/pose_map_estimation_main.cpp
)
target_link_libraries(estimation ${catkin_LIBRARIES} ${OpenCV_LIBRARIES} libNewLib.so)
LINK_DIRECTORIES(${LIB_MANUALLY})
In https://cmake.org/cmake/help/v3.0/command/link_directories.html it says:
Specify the paths in which the linker should search for libraries. The command will apply only to targets created after it is called.
So, try if it works if you create the target AFTER the link_directories command.
You could also consider to write a proper cmake file for locating your library and use find_package to find it.

CPPREST SDK on CLion using CMake on Mac

I am attempting to use the CPPREST SDK in CLion on a Mac using CMake. I'm almost there, but I cannot seem to resolve the following linker error:
Undefined symbols for architecture x86_64:
"_ERR_remove_thread_state", referenced from:
boost::asio::ssl::detail::openssl_init_base::do_init::~do_init() in PongRemote.cpp.o
I have specified -lssl and -lcrypto, but still get this "thread state" error. Based on some research, it looks like it is coming from OpenSSL. I used Homebrew to install CPPREST.
I have tested this with literally just a main and the basic includes:
#include <cpprest/http_client.h>
#include <cpprest/filestream.h>
with a CMake of:
project(cpprest)
cmake_minimum_required(VERSION 3.8)
set(CMAKE_CXX_STANDARD 14)
# BOOST PACKAGE
find_package(Boost REQUIRED COMPONENTS
atomic
chrono
date_time
exception
filesystem
random
regex
serialization
system
thread
)
include_directories(${Boost_INCLUDE_DIRS})
IF (!Boost_FOUND)
MESSAGE("*** ERROR *** Boost package not found")
RETURN()
ENDIF ()
# Microsoft RESTful API Package (Casablanca)
set(CPPREST_LIBRARIES "/usr/local/opt/openssl/lib")
include_directories("/usr/local/opt/openssl/include")
# Compile and link
# Build the core library and executable
include_directories(${CMAKE_SOURCE_DIR})
set(SOURCE_FILES
main.cpp
)
set(LINK_LIBRARIES
${Boost_LIBRARIES}
${CPPREST_LIBRARIES}
-lssl
-lcrypto
)
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
target_link_libraries(${PROJECT_NAME} ${LINK_LIBRARIES})
After taking some time, the linking problem was due to the CMake find commands not working properly. I manually pointed directly to the libraries for both OpenSSL and RESTCPP and the problem was fixed.
Project(cpprest)
cmake_minimum_required(VERSION 3.8)
set(CMAKE_CXX_STANDARD 17)
# BOOST PACKAGE
set(Boost_USE_MULTITHREADED ON) # Default ON
set(Boost_USE_STATIC_LIBS ON) # Default OFF
set(Boost_USE_DEBUG_RUNTIME OFF) # Default ON
set(Boost_USE_DEBUG_PYTHON OFF) # Default OFF
set(Boost_USE_STLPORT OFF) # Default OFF
find_package(Boost REQUIRED COMPONENTS
atomic
chrono
date_time
exception
filesystem
program_options
random
regex
system
serialization
thread
)
IF (!Boost_FOUND)
MESSAGE("*** ERROR *** Boost package not found")
RETURN()
ENDIF ()
include_directories(${Boost_INCLUDE_DIRS})
MESSAGE("Boost_INCLUDE_DIRS:\t" ${Boost_INCLUDE_DIRS})
# Open SSL Package
set(OpenSSL_INCLUDE /usr/local/opt/openssl/include)
set(OpenSSL_LIBRARIES
/usr/local/opt/openssl/lib/libcrypto.dylib
/usr/local/opt/openssl/lib/libssl.dylib)
include_directories(${OpenSSL_INCLUDE})
# Microsoft RESTful API Package (Casablanca)
set(CppREST_INCLUDE /usr/local/opt/cpprestsdk/include)
set(CppREST_LIBRARIES /usr/local/opt/cpprestsdk/lib/libcpprest.dylib)
include_directories(${CppREST_INCLUDE})
# Compile and link
# Build the core library and executable
set(SOURCE_FILES main.cpp)
set(LINK_LIBRARIES
${Boost_LIBRARIES}
${OpenSSL_LIBRARIES}
${CppREST_LIBRARIES}
)
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
target_link_libraries(${PROJECT_NAME} ${LINK_LIBRARIES})

Linking to boost

I am trying to link to the boost libraries for a ros node, in connection I found the following links: "How to include external library (boost) into CLion C++ project with CMake?" and "How to link C++ program with Boost using CMake" and "problem building in groovy with catkin and boost".
As a result I create my CMakelists.txt as follows which needs to use OpenCV and Boost:
cmake_minimum_required(VERSION 2.8.3)
project(image_listener_rosbag)
#set(Boost_USE_STATIC_LIBS OFF)
#set(Boost_USE_MULTITHREADED ON)
#set(Boost_USE_STATIC_RUNTIME OFF)
## Find catkin macros and libraries
find_package(catkin REQUIRED COMPONENTS
cv_bridge
image_transport
message_generation
roscpp
sensor_msgs
std_msgs
)
add_message_files(
FILES
)
generate_messages(
DEPENDENCIES
std_msgs
sensor_msgs
)
catkin_package(
CATKIN_DEPENDS message_runtime
)
find_package(catkin REQUIRED)
find_package(OpenCV REQUIRED)
find_package( Boost REQUIRED COMPONENTS serialization archive ) # is this correct?
# The components included are chosen because I need to use the following usings:
#include <boost/archive/binary_oarchive.hpp>
#include <boost/archive/binary_iarchive.hpp>
#include <boost/serialization/split_free.hpp>
include_directories(
${OpenCV_INCLUDE_DIRS} ${catkin_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS}
)
link_directories(${Boost_LIBRARY_DIR})
add_library(image_listener_rosbag src/image_listener.cpp)
add_dependencies(image_listener_rosbag ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
add_executable(image_listener_rosbag_node src/image_listener.cpp)
target_link_libraries(image_listener_rosbag_node ${OpenCV_LIBRARIES} ${catkin_LIBRARIES} ${Boost_LIBRARIES})#
When I try to build it suddenly another package relying on PCL crashes with:
-- Configuring incomplete, errors occurred!
See also "/home/johann/catkin_ws/build/CMakeFiles/CMakeOutput.log".
See also "/home/johann/catkin_ws/build/CMakeFiles/CMakeError.log".
make: *** [cmake_check_build_system] Error 1
Looking into the CMakeError.log Complains about not finding pthread_create. The PCL package that crashes has no reference to boost other than what PCL has inside. Should I add boost explicitly in the failing package as above? Tried: adding the information about boost from above to the PCL node, I get the same error log referencing the missing pthread_create.
As a test I have tried editing the code above in several ways if remove all the boost references from the code above, both packages are build and runs with no issue.
If I remove find_package(Boost ... I receive a lot of issues like: undefined reference to boost::archive::detail::basic_oarchive::~basic_oarchive()` But the PCL node compiles fine with no issue.
Question: Am I adding boost correctly and the libraries?
If so is there some issue when including PCL in another package that you need a special reference?
System: For reference I am implementing it using ros indigo full, with the included opencv(2.4) and pcl(looks like 1.54 libraries), everything is on Ubuntu 14.04.
Extra
This question, "PCL install links directly to boost installation directory somehow", seems to have some of the same issues I have however not been able to transfer the suggestions yet.
PCL node
The below node is the one exhibiting the error when the boost includes are added above.
cmake_minimum_required(VERSION 2.8.3)
project(pointcloudlistener)
find_package(PCL REQUIRED)
find_package(catkin REQUIRED COMPONENTS
cv_bridge
image_transport
PCL
pcl_ros
roscpp
sensor_msgs
std_msgs
)
add_message_files(
FILES
)
generate_messages(
DEPENDENCIES
std_msgs
sensor_msgs
)
catkin_package(
CATKIN_DEPENDS message_runtime
)
find_package(catkin REQUIRED)
find_package(OpenCV REQUIRED)
find_package(PCL REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS} ${catkin_INCLUDE_DIRS} ${PCL_INCLUDE_DIRS})
link_directories(
${PCL_LIBRARY_DIRS}
)
add_library(pointcloudlistener src/pcl_listener.cpp src/matPclConverter.cpp src/Image_Safety.cpp)
add_dependencies(pointcloudlistener ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
add_executable(pointcloudlistener_node src/pcl_listener.cpp src/matPclConverter.cpp src/Image_Safety.cpp)
target_link_libraries(pointcloudlistener_node ${OpenCV_LIBRARIES} ${catkin_LIBRARIES} ${PCL_LIBRARIES})