undefined reference to `vtable for boost::detail::thread_data_base' - codeblocks

I've trying to solve this error whole day without result.
Compiling with codeblocks+ mingw + cmake
image
||=== Build: all in otclient (compiler: GNU GCC Compiler) ===|
undefined reference to `vtable for boost::detail::thread_data_base'|
undefined reference to `boost::thread::start_thread_noexcept()'|
undefined reference to `boost::thread::join_noexcept()'|
undefined reference to `boost::detail::thread_data_base::~thread_data_base()'|
undefined reference to `boost::detail::thread_data_base::~thread_data_base()'|
||error: ld returned 1 exit status|
CMakeFiles\otclient.dir\build.make|2272|recipe for target 'otclient.exe' failed|
CMakeFiles\Makefile2|71|recipe for target 'CMakeFiles/otclient.dir/all' failed|
C:\Users\Tomek\Desktop\compile\Makefile|128|recipe for target 'all' failed|
||=== Build failed: 9 error(s), 0 warning(s) (8 minute(s), 25 second(s)) ===|

My cmakeLists:
cmake_minimum_required(VERSION 3.6)
project(otclient)
set(VERSION "0.6.6")
option(FRAMEWORK_SOUND "Use SOUND " ON)
option(FRAMEWORK_GRAPHICS "Use GRAPHICS " ON)
option(FRAMEWORK_XML "Use XML " ON)
option(FRAMEWORK_NET "Use NET " ON)
option(FRAMEWORK_SQL "Use SQL" OFF)
include(src/framework/CMakeLists.txt)
include(src/client/CMakeLists.txt)
# functions map for reading backtraces
if(NOT APPLE)
set(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -Wl,-Map=${PROJECT_NAME}.map")
endif()
option(USE_PCH "Use precompiled header (speed up compile)" OFF)
set(executable_SOURCES
src/main.cpp
)
# add executable icon for win32 platforms
if(WIN32)
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/otcicon.o
COMMAND ${CMAKE_RC_COMPILER}
-I${CMAKE_CURRENT_SOURCE_DIR}/src
-i${CMAKE_CURRENT_SOURCE_DIR}/src/otcicon.rc
-o ${CMAKE_CURRENT_BINARY_DIR}/otcicon.o)
set(executable_SOURCES ${executable_SOURCES} otcicon.o)
endif()
if(MINGW)
add_definitions(-DWIN32)
endif()
add_definitions(-D"VERSION=\\"${VERSION}\\"")
# add client executable
set(CMAKE_CXX_STANDARD 11)
find_package(Boost COMPONENTS thread system REQUIRED)
include_directories(${Boost_INCLUDE_DIR})
add_executable(${PROJECT_NAME} ${framework_SOURCES} ${client_SOURCES} ${executable_SOURCES})
target_link_libraries(${PROJECT_NAME} ${framework_LIBRARIES} ${Boost_LIBRARIES})
target_include_directories(${PROJECT_NAME} PRIVATE ${Boost_INCLUDE_DIRS})
if(USE_PCH)
include(cotire)
cotire(${PROJECT_NAME})
message(STATUS "Use precompiled header: ON")
else()
message(STATUS "Use precompiled header: OFF")
endif()
# installation
set(DATA_INSTALL_DIR share/${PROJECT_NAME})
install(TARGETS ${PROJECT_NAME}
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
install(FILES README.md BUGS LICENSE AUTHORS init.lua ${PROJECT_NAME}rc.lua DESTINATION ${DATA_INSTALL_DIR})
install(DIRECTORY data modules DESTINATION ${DATA_INSTALL_DIR} PATTERN ".git" EXCLUDE)
# add "make run"
add_custom_target(run COMMAND ${PROJECT_NAME} DEPENDS ${PROJECT_NAME} WORKING_DIRECTORY ${CMAKE_PROJECT_DIR})
add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)

Related

Cmake with "undefined references" Despite Finding Boost Libs

cmake 2.8.12 correctly shows:
Boost version: 1.56.0
Found the following Boost libraries:
system
thread
log
log_setup
And the generated link.txt shows full, correct path to the .so files, but every Boost call is simply "In function...undefined reference to boost..." with no cxx11 or ABI or any other hints.
CMakeFiles/proj.dir/src/proj.cc.o: In function `proj::init()':
/code/proj/src/proj.cc:31: undefined reference to `boost::log::v2s_mt_posix::core::get()'
This is running on an old box, for example using libc-2.13.so on a 32bit processor. I compiled the boost libraries on the box yesterday and am trying to compile this on the box but am getting nowhere. I compiled cmake on the box as well.
Searching dozens of questions here has gotten me nowhere. Any suggestions on what is wrong? How to investigate the issue?
set(PROJ_NAME my-proj)
set(HEADERS
headers/proj.h
)
set(SOURCES
src/proj.cc
)
set(MAIN_FILE src/main.cc)
if(COMMAND cmake_policy)
cmake_policy(SET CMP0003 NEW)
endif(COMMAND cmake_policy)
add_executable (${PROJ_NAME} ${SOURCES}
${HEADERS} ${MAIN_FILE})
target_include_directories ( ${PROJ_NAME}
PUBLIC headers
PRIVATE .
PRIVATE /usr/local/lib/
)
set( Boost_LIBRARY_DIR /usr/local/lib )
find_package(Boost COMPONENTS system thread log log_setup REQUIRED)
link_directories(${Boost_LIBRARY_DIR})
target_link_libraries ( ${PROJ_NAME} -pthread ${Boost_LIBRARIES} )
I think that
set( Boost_LIBRARY_DIR /usr/local/lib )
is wrong and interferes badly with Find_Package. If you want to provide a hint, use e.g. BOOST_ROOT as documented:
BOOST_ROOT=~/custom/boost cmake .
Here's a fixed-up / simplified self-contained example that works:
File CMakeLists.txt
set(PROJ_NAME my-proj)
find_package(Boost 1.65.0 COMPONENTS system thread log log_setup REQUIRED)
set(HEADERS
headers/proj.h
)
set(SOURCES
src/proj.cc
)
set(MAIN_FILE src/main.cc)
if(COMMAND cmake_policy)
cmake_policy(SET CMP0003 NEW)
endif(COMMAND cmake_policy)
add_executable (${PROJ_NAME} ${SOURCES}
${HEADERS} ${MAIN_FILE})
target_include_directories ( ${PROJ_NAME}
PUBLIC headers
PRIVATE .
PRIVATE /usr/local/lib/
)
link_directories(${Boost_LIBRARY_DIR})
target_link_libraries ( ${PROJ_NAME} -pthread ${Boost_LIBRARIES} )
File headers/proj.h
File src/main.cc
int main() {
}
File src/proj.cc
#include <boost/thread.hpp>
void foo() {
boost::thread_group tg;
tg.create_thread([]{});
tg.join_all();
}
Proof of the pudding:
cmake .
CMake Warning (dev) in CMakeLists.txt:
No project() command is present. The top-level CMakeLists.txt file must
contain a literal, direct call to the project() command. Add a line of
code such as
project(ProjectName)
near the top of the file, but after cmake_minimum_required().
CMake is pretending there is a "project(Project)" command on the first
line.
This warning is for project developers. Use -Wno-dev to suppress it.
-- The C compiler identification is GNU 7.5.0
-- The CXX compiler identification is GNU 7.5.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
-- Found Boost: /usr/include (found suitable version "1.65.1", minimum required is "1.65.0") found components: system thread log log_setup chrono date_time atomic filesystem regex
CMake Warning (dev) in CMakeLists.txt:
No cmake_minimum_required command is present. A line of code such as
cmake_minimum_required(VERSION 3.22)
should be added at the top of the file. The version specified may be lower
if you wish to support older CMake versions for this project. For more
information run "cmake --help-policy CMP0000".
This warning is for project developers. Use -Wno-dev to suppress it.
-- Configuring done
-- Generating done
-- Build files have been written to: /tmp/q
 sehe  /  tmp  q  make
[ 66%] Building CXX object CMakeFiles/my-proj.dir/src/proj.o
[ 66%] Building CXX object CMakeFiles/my-proj.dir/src/main.o
[100%] Linking CXX executable my-proj
[100%] Built target my-proj
 sehe  /  tmp  q  ldd my-proj
linux-vdso.so.1 (0x00007ffd917e4000)
libboost_system.so.1.65.1 => /usr/lib/x86_64-linux-gnu/libboost_system.so.1.65.1 (0x00007f40c25bd000)
libboost_thread.so.1.65.1 => /usr/lib/x86_64-linux-gnu/libboost_thread.so.1.65.1 (0x00007f40c2398000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f40c2179000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f40c1d6c000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f40c1b54000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f40c1763000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f40c155b000)
/lib64/ld-linux-x86-64.so.2 (0x00007f40c29e7000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f40c11bd000)
NOTES
Note that if you use a too-recent boost then maybe the dependencies might be incorrect:
CMake Warning at /usr/share/cmake-3.22/Modules/FindBoost.cmake:1369 (message):
New Boost version may have incorrect or missing dependencies and imported
targets
Call Stack (most recent call first):
/usr/share/cmake-3.22/Modules/FindBoost.cmake:1492 (_Boost_COMPONENT_DEPENDENCIES)
/usr/share/cmake-3.22/Modules/FindBoost.cmake:2102 (_Boost_MISSING_DEPENDENCIES)
CMakeLists.txt:5 (find_package)
On my system, e.g. in order to use Boost 1.78 successfully, I have to add Boost System manually. Linker errors:
make
[ 33%] Building CXX object CMakeFiles/my-proj.dir/src/proj.o
[ 66%] Building CXX object CMakeFiles/my-proj.dir/src/main.o
[100%] Linking CXX executable my-proj
CMakeFiles/my-proj.dir/src/proj.o: In function `__static_initialization_and_destruction_0(int, int)':
proj.cc:(.text+0x6a1): undefined reference to `boost::system::generic_category()'
proj.cc:(.text+0x6ad): undefined reference to `boost::system::generic_category()'
proj.cc:(.text+0x6b9): undefined reference to `boost::system::system_category()'
CMakeFiles/my-proj.dir/src/proj.o: In function `boost::system::error_category::std_category::equivalent(int, std::error_condition const&) const':
proj.cc:(.text._ZNK5boost6system14error_category12std_category10equivalentEiRKSt15error_condition[_ZNK5boost6system14error_category12std_category10equivalentEiRKSt15error_condition]+0xb8): undefined reference to `boost::system::generic_category()'
proj.cc:(.text._ZNK5boost6system14error_category12std_category10equivalentEiRKSt15error_condition[_ZNK5boost6system14error_category12std_category10equivalentEiRKSt15error_condition]+0xf3): undefined reference to `boost::system::generic_category()'
CMakeFiles/my-proj.dir/src/proj.o: In function `boost::system::error_category::std_category::equivalent(std::error_code const&, int) const':
proj.cc:(.text._ZNK5boost6system14error_category12std_category10equivalentERKSt10error_codei[_ZNK5boost6system14error_category12std_category10equivalentERKSt10error_codei]+0xb8): undefined reference to `boost::system::generic_category()'
proj.cc:(.text._ZNK5boost6system14error_category12std_category10equivalentERKSt10error_codei[_ZNK5boost6system14error_category12std_category10equivalentERKSt10error_codei]+0xf3): undefined reference to `boost::system::generic_category()'
proj.cc:(.text._ZNK5boost6system14error_category12std_category10equivalentERKSt10error_codei[_ZNK5boost6system14error_category12std_category10equivalentERKSt10error_codei]+0x1d2): undefined reference to `boost::system::generic_category()'
CMakeFiles/my-proj.dir/src/proj.o:proj.cc:(.text._ZN5boost16thread_exceptionC2EiPKc[_ZN5boost16thread_exceptionC5EiPKc]+0x28): more undefined references to `boost::system::generic_category()' follow
collect2: error: ld returned 1 exit status
CMakeFiles/my-proj.dir/build.make:121: recipe for target 'my-proj' failed
make[2]: *** [my-proj] Error 1
CMakeFiles/Makefile2:82: recipe for target 'CMakeFiles/my-proj.dir/all' failed
make[1]: *** [CMakeFiles/my-proj.dir/all] Error 2
Makefile:90: recipe for target 'all' failed
make: *** [all] Error 2
Fix:
target_link_libraries ( ${PROJ_NAME} boost_system )
I hope that it is not too late to drop my answer here.
TLDR: When Boost is installed using package managers such as Homebrew or macports often it is compiled using clang++. But on your project side, one might be using a different compiler, leading to undefined references in the linkage stage.
In order to use the compiler that you want to use in your project, you will have to use a version of Boost compiled with the same compiler. to achieve this you can customize Boost compilation on macos as follows:
In the Bootstrap stage use:
./bootstrap.sh --prefix=/usr/local/Cellar/boost_gcc --with-toolset=gcc --without-libraries=python,mpi
Install the headers-only part as follows:
./b2 headers
Customize the compiler to build the libraries by adding a file named user-config.jam with the following line in it:
using gcc : : /usr/local/bin/g++-11 ;
Compile and install the library as follows:
./b2 -d2 -j12 --layout=tagged-1.66 --user-config=user-config.jam install threading=multi,single link=shared,static
I hope that it helps.

How to install static libz.dll.a,libssl.dll.a, etc on MinGW/MSYS2?

I'm getting this on my project's linking process (compiles with cmake):
[100%] Linking CXX executable roosek2.exe
/usr/lib/gcc/x86_64-pc-msys/9.1.0/../../../../x86_64-pc-msys/bin/ld: cannot find -lC:/msys64/mingw64/lib/libz.dll.a
/usr/lib/gcc/x86_64-pc-msys/9.1.0/../../../../x86_64-pc-msys/bin/ld: cannot find -lC:/msys64/mingw64/lib/libssl.dll.a
/usr/lib/gcc/x86_64-pc-msys/9.1.0/../../../../x86_64-pc-msys/bin/ld: cannot find -lC:/msys64/mingw64/lib/libcrypto.dll.a
/usr/lib/gcc/x86_64-pc-msys/9.1.0/../../../../x86_64-pc-msys/bin/ld: cannot find -lC:/msys64/mingw64/lib/libzstd.dll.a
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/roosek2.dir/build.make:578: roosek2.exe] Error 1
make[2]: Leaving directory '/home/LZ/roosek_ocr2'
make[1]: *** [CMakeFiles/Makefile2:77: CMakeFiles/roosek2.dir/all] Error 2
make[1]: Leaving directory '/home/LZ/roosek_ocr2'
make: *** [Makefile:84: all] Error 2
This happens when I compile with static qt5 from MSYS2 in MinGW shell. Here's my CMakeLists.txt:
cmake_minimum_required(VERSION 3.5)
project(roosek2 LANGUAGES CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(Qt5 COMPONENTS Core Quick REQUIRED)
add_executable(roosek2
main.cpp
qml.qrc
ImageStream.cpp
YuvUtils.cpp
CameraView.cpp
)
add_library(ctmedia_codec MODULE IMPORTED)
add_library(ctstream MODULE IMPORTED)
add_library(maincore MODULE IMPORTED)
#link_directories(${CMAKE_CURRENT_SOURCE_DIR}/win_bin/lib/x64)
set_target_properties(ctmedia_codec PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/win_bin/lib/x64/CTMedia.lib)
set_target_properties(ctstream PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/win_bin/lib/x64/CTStream.lib)
set_target_properties(maincore PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/win_bin/lib/x64/WPMainCore.lib)
include_directories("include")
target_compile_definitions(roosek2
PRIVATE $<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:QT_QML_DEBUG>)
target_link_libraries(roosek2
PRIVATE Qt5::Core Qt5::Quick ctmedia_codec ctstream maincore)
How do I install these libraries? Why are they being required? Do I really need them?
Install these packages:
For X86_64 (64 bit):
pacman -S mingw-w64-x86_64-openssl mingw-w64-x86_64-zlib mingw-w64-x86_64-zstd
For X86 (32 bit):
pacman -S mingw-w64-i686-openssl mingw-w64-i686-zlib mingw-w64-i686-zstd

Failed to link OpenSSL using MinGW/Cmake (TLS_method,`SSL_CTX_ctrl', .etc..)

I'm going crazy to link OpenSSL with project that I'm implementing using MinGW and setting the project with CMake Gui.
It basically fails to link properly with the OpenSSL libraries.
Here's my CMake settings -> https://ibb.co/5Y0TB5Y.
Here there are the CMakeLists.txt that I used in my project:
1. Main CMakeLists.txt
`cmake_minimum_required (VERSION 2.6)
project (MyPluginDesignProject)
SET (BOOST_ROOT "C:\\Program Files\\boost_1_68_0")
SET (BOOST_INCLUDEDIR "C:\\Program Files\\boost_1_68_0\\include")
SET (BOOST_LIBRARYDIR "C:\\Program Files\\boost\\lib")
SET (BOOST_MIN_VERSION "1.68.0")
set (Boost_NO_BOOST_CMAKE ON)
FIND_PACKAGE(Boost ${BOOST_MIN_VERSION} REQUIRED)
if (NOT Boost_FOUND)
message(FATAL_ERROR "Fatal error: Boost (version >= 1.55) required.")
else()
message(STATUS "Setting up BOOST")
message(STATUS " Includes - ${Boost_INCLUDE_DIRS}")
message(STATUS " Library - ${Boost_LIBRARY_DIRS}")
SET (Boost_INCLUDE_DIRS "C:\\Program Files\\boost\\lib")
include_directories(${Boost_INCLUDE_DIRS})
link_directories(${Boost_LIBRARY_DIRS})
endif (NOT Boost_FOUND)
message("Binary path " ${PROJECT_SOURCE_DIR})
message("Source path " ${PROJECT_BINARY_DIR})
#define the path relative the headers
set (PLUGIN_INCLUDES ${PROJECT_SOURCE_DIR}/Headers)
#telle the compiler to check the headers in the PLUGIN_INCLUDES path for the project's headers
include_directories(${PLUGIN_INCLUDES})
add_subdirectory(Plugins\\MyPlugin)
#define the variable PROJECT_SOURCE that includes all the cpp within the "Headers" folder
set(PROJECT_INCLUDES Headers/GameInstance.h)
#define the variable PROJECT_SOURCE that includes all the cpp within the "Source" folder
set(PROJECT_SOURCE
Source/main.cpp
Source/GameInstance.cpp
)
add_executable(MyPluginDesignProject ${PROJECT_SOURCE})
#Links the library to the program :
# keyword: PRIVATE
target_link_libraries (MyPluginDesignProject PRIVATE MyPlugin)`
2 Plugin CMakeLists.txt
`cmake_minimum_required (VERSION 2.6)
add_subdirectory(ThirdParty\\Simple-Web-Server)
file(GLOB
MYPLUGIN_SERVER_PLUGIN_HEADERS Headers/*.h
)
file(GLOB
MYPLUGIN_SERVER_PLUGIN_SOURCES Source/*.cpp
)
file(GLOB
SIMPLE_WEB_SERVER ThirdParty/Simple-Web-Server/*.hpp
)
add_library(
MyPlugin #name of the library
STATIC #STATIC library . other option: SHARED - MODULE. STATIC is default
${MYPLUGIN_SERVER_PLUGIN_HEADERS}
${MYPLUGIN_SERVER_PLUGIN_SOURCES}
${SIMPLE_WEB_SERVER}
)
find_package(OpenSSL REQUIRED)
if (OPENSSL_FOUND)
include_directories(${OPENSSL_INCLUDE_DIR})
target_link_libraries(MyPlugin PUBLIC ${OPENSSL_LIBRARIES})
endif()
#definition of the include path of the library that will be usedd for linking
#keyword: the "PUBLIC" keyword means that abyone who's including this library, will include also all the
#includes included in this library.
#if the keyword is "PRIVATE" then the program that includes this library won't automatically include its libraries
target_include_directories(MyPlugin PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/Headers)
target_include_directories(MyPlugin PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/ThirdParty/Simple-Web-Server)
target_link_libraries(MyPlugin PUBLIC ${OPENSSL_LIBRARIES})
target_link_libraries (MyPlugin PUBLIC simple-web-server)
target_compile_definitions(MyPlugin PUBLIC MYPLUGIN_SERVER_PLUGIN_VERSION=1.2.0)`
SimpleWebServer CMakeLists.txt (included in the plugin CMakeLists.txt)
`
cmake_minimum_required (VERSION 3.0)
project (Simple-Web-Server)
option(USE_STANDALONE_ASIO "set ON to use standalone Asio instead of Boost.Asio" OFF)
option(BUILD_TESTING "set ON to build library tests" OFF)
if(NOT MSVC)
add_compile_options(-std=c++11 -Wall -Wextra -Wsign-conversion)
else()
add_compile_options(/W1)
endif()
add_library(simple-web-server INTERFACE)
target_include_directories(simple-web-server INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
find_package(Threads REQUIRED)
target_link_libraries(simple-web-server INTERFACE ${CMAKE_THREAD_LIBS_INIT})
# TODO 2020 when Debian Jessie LTS ends:
# Remove Boost system, thread, regex components; use Boost::<component> aliases; remove Boost target_include_directories
if(USE_STANDALONE_ASIO)
target_compile_definitions(simple-web-server INTERFACE USE_STANDALONE_ASIO)
include(CheckIncludeFileCXX)
CHECK_INCLUDE_FILE_CXX(asio.hpp HAVE_ASIO)
if(NOT HAVE_ASIO)
message(FATAL_ERROR "Standalone Asio not found")
endif()
else()
find_package(Boost 1.53.0 COMPONENTS system thread REQUIRED)
target_link_libraries(simple-web-server INTERFACE ${Boost_LIBRARIES})
target_include_directories(simple-web-server INTERFACE ${Boost_INCLUDE_DIR})
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9)
target_compile_definitions(simple-web-server INTERFACE USE_BOOST_REGEX)
find_package(Boost 1.53.0 COMPONENTS regex REQUIRED)
target_link_libraries(simple-web-server INTERFACE ${Boost_LIBRARIES})
target_include_directories(simple-web-server INTERFACE ${Boost_INCLUDE_DIR})
endif()
endif()
if(WIN32)
target_link_libraries(simple-web-server INTERFACE ws2_32 wsock32)
endif()
if(APPLE)
set(OPENSSL_ROOT_DIR "/usr/local/opt/openssl")
endif()
find_package(OpenSSL)
if(OPENSSL_FOUND)
message(STATUS "Using OpenSSL ${OPENSSL_VERSION}")
include_directories(${OPENSSL_INCLUDE_DIRS})
target_compile_definitions(simple-web-server INTERFACE HAVE_OPENSSL)
message ("OpenSSL library is " ${OPENSSL_LIBRARIES})
target_link_libraries(simple-web-server INTERFACE ${OPENSSL_LIBRARIES})
target_link_libraries(simple-web-server INTERFACE OpenSSL::SSL)
target_include_directories(simple-web-server INTERFACE ${OPENSSL_INCLUDE_DIR})
endif()
# If Simple-Web-Server is not a sub-project:
if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
add_executable(http_examples http_examples.cpp)
target_link_libraries(http_examples simple-web-server)
find_package(Boost 1.53.0 COMPONENTS system thread filesystem REQUIRED)
target_link_libraries(http_examples ${Boost_LIBRARIES})
target_include_directories(http_examples PRIVATE ${Boost_INCLUDE_DIR})
if(OPENSSL_FOUND)
add_executable(https_examples https_examples.cpp)
target_link_libraries(https_examples simple-web-server)
target_link_libraries(https_examples ${Boost_LIBRARIES})
target_include_directories(https_examples PRIVATE ${Boost_INCLUDE_DIR})
endif()
set(BUILD_TESTING ON)
install(FILES server_http.hpp client_http.hpp server_https.hpp client_https.hpp crypto.hpp utility.hpp status_code.hpp DESTINATION include/simple-web-server)
endif()
if(BUILD_TESTING)
enable_testing()
add_subdirectory(tests)
endif()`
I really don't understand what I'm doing wrong. I've tried to use both the openssl *.a and the *.lib libraries and I had the same result. My OpenSSL version is 1.1.0k and Boost is 1.68.
I also tried to set CMAKE_CXX_FLAGS = -lssl -lcrypto but the output says that ld.exe can't find the libraries. Any help?
Output:
"C:\Program Files\CMake\bin\cmake.exe" -E cmake_link_script CMakeFiles\MyProjectDesignProject.dir\link.txt --verbose=1
"C:\Program Files\CMake\bin\cmake.exe" -E remove -f CMakeFiles\MyProjectDesignProject.dir/objects.a
C:\MinGw\mingw32\bin\ar.exe cr CMakeFiles\MyProjectDesignProject.dir/objects.a #CMakeFiles\MyProjectDesignProject.dir\objects1.rsp
C:\MinGw\mingw32\bin\g++.exe -Wl,--whole-archive CMakeFiles\MyProjectDesignProject.dir/objects.a -Wl,--no-whole-archive -o MyProjectDesignProject.exe -Wl,--out-implib,libMyProjectDesignProject.dll.a -Wl,--major-image-version,0,--minor-image-version,0 #CMakeFiles\MyProjectDesignProject.dir\linklibs.rsp
CMakeFiles\MyProjectDesignProject.dir/objects.a(main.cpp.obj):main.cpp:(.text$_ZN5boost4asio3ssl6detail17openssl_init_base7do_initD1Ev[__ZN5boost4asio3ssl6detail17openssl_init_base7do_initD1Ev]+0x11): undefined reference to `CONF_modules_unload'
CMakeFiles\MyProjectDesignProject.dir/objects.a(main.cpp.obj):main.cpp:(.text$_ZNK5boost4asio5error6detail12ssl_category7messageB5cxx11Ei[__ZNK5boost4asio5error6detail12ssl_category7messageB5cxx11Ei]+0x11): undefined reference to `ERR_reason_error_string'
Plugins/MyProject/libMyProject.a(MyProjectMatch.cpp.obj):MyProjectMatch.cpp:(.text+0x1c0): undefined reference to `OPENSSL_sk_num'
Plugins/MyProject/libMyProject.a(MyProjectMatch.cpp.obj):MyProjectMatch.cpp:(.text+0x1da): undefined reference to `OPENSSL_sk_value'
Plugins/MyProject/libMyProject.a(MyProjectMatch.cpp.obj):MyProjectMatch.cpp:(.text$_ZN5boost4asio3ssl7contextC1ENS1_12context_base6methodE[__ZN5boost4asio3ssl7contextC1ENS1_12context_base6methodE]+0x2b): undefined reference to `ERR_clear_error'
Plugins/MyProject/libMyProject.a(MyProjectMatch.cpp.obj):MyProjectMatch.cpp:(.text$_ZN5boost4asio3ssl7contextC1ENS1_12context_base6methodE[__ZN5boost4asio3ssl7contextC1ENS1_12context_base6methodE]+0x79): undefined reference to `TLS_method'
Plugins/MyProject/libMyProject.a(MyProjectMatch.cpp.obj):MyProjectMatch.cpp:(.text$_ZN5boost4asio3ssl7contextC1ENS1_12context_base6methodE[__ZN5boost4asio3ssl7contextC1ENS1_12context_base6methodE]+0x81): undefined reference to `SSL_CTX_new'
Plugins/MyProject/libMyProject.a(MyProjectMatch.cpp.obj):MyProjectMatch.cpp:(.text$_ZN5boost4asio3ssl7contextC1ENS1_12context_base6methodE[__ZN5boost4asio3ssl7contextC1ENS1_12context_base6methodE]+0xba): undefined reference to `SSL_CTX_ctrl'
Plugins/MyProject/libMyProject.a(MyProjectMatch.cpp.obj):MyProjectMatch.cpp:(.text$_ZN5boost4asio3ssl7contextC1ENS1_12context_base6methodE[__ZN5boost4asio3ssl7contextC1ENS1_12context_base6methodE]+0xdf): undefined reference to `SSL_CTX_ctrl'
Plugins/MyProject/libMyProject.a(MyProjectMatch.cpp.obj):MyProjectMatch.cpp:(.text$_ZN5boost4asio3ssl7contextC1ENS1_12context_base6methodE[__ZN5boost4asio3ssl7contextC1ENS1_12context_base6methodE]+0xe9): undefined reference to `TLS_client_method'
Plugins/MyProject/libMyProject.a(MyProjectMatch.cpp.obj):MyProjectMatch.cpp:(.text$_ZN5boost4asio3ssl7contextC1ENS1_12context_base6methodE[__ZN5boost4asio3ssl7contextC1ENS1_12context_base6methodE]+0xf1): undefined reference to `SSL_CTX_new'
Plugins/MyProject/libMyProject.a(MyProjectMatch.cpp.obj):MyProjectMatch.cpp:(.text$_ZN5boost4asio3ssl7contextC1ENS1_12context_base6methodE[__ZN5boost4asio3ssl7contextC1ENS1_12context_base6methodE]+0x159): undefined reference to `TLS_server_method'
Plugins/MyProject/libMyProject.a(MyProjectMatch.cpp.obj):MyProjectMatch.cpp:(.text$_ZN5boost4asio3ssl7contextC1ENS1_12context_base6methodE[__ZN5boost4asio3ssl7contextC1ENS1_12context_base6methodE]+0x161): undefined reference to `SSL_CTX_new'
Plugins/MyProject/libMyProject.a(MyProjectMatch.cpp.obj):MyProjectMatch.cpp:(.text$_ZN5boost4asio3ssl7contextC1ENS1_12context_base6methodE[__ZN5boost4asio3ssl7contextC1ENS1_12context_base6methodE]+0x1c9): undefined reference to `TLS_method'
Plugins/MyProject/libMyProject.a(MyProjectMatch.cpp.obj):MyProjectMatch.cpp:(.text$_ZN5boost4asio3ssl7contextC1ENS1_12context_base6methodE[__ZN5boost4asio3ssl7contextC1ENS1_12context_base6methodE]+0x239): undefined reference to `TLS_client_method'
Plugins/MyProject/libMyProject.a(MyProjectMatch.cpp.obj):MyProjectMatch.cpp:(.text$_ZN5boost4asio3ssl7contextC1ENS1_12context_base6methodE[__ZN5boost4asio3ssl7contextC1ENS1_12context_base6methodE]+0x2a9): undefined reference to `TLS_server_method'
Plugins/MyProject/libMyProject.a(MyProjectMatch.cpp.obj):MyProjectMatch.cpp:(.text$_ZN5boost4asio3ssl7contextC1ENS1_12context_base6methodE[__ZN5boost4asio3ssl7contextC1ENS1_12context_base6methodE]+0x72e): undefined reference to `ERR_get_error'
Plugins/MyProject/libMyProject.a(MyProjectMatch.cpp.obj):MyProjectMatch.cpp:(.text$_ZN5boost4asio3ssl7contextD1Ev[__ZN5boost4asio3ssl7contextD1Ev]+0x1f): undefined reference to `SSL_CTX_get_default_passwd_cb_userdata'
Plugins/MyProject/libMyProject.a(MyProjectMatch.cpp.obj):MyProjectMatch.cpp:(.text$_ZN5boost4asio3ssl7contextD1Ev[__ZN5boost4asio3ssl7contextD1Ev]+0x5a): undefined reference to `SSL_CTX_set_default_passwd_cb_userdata'
Plugins/MyProject/libMyProject.a(MyProjectMatch.cpp.obj):MyProjectMatch.cpp:(.text$_ZN5boost4asio3ssl7contextD1Ev[__ZN5boost4asio3ssl7contextD1Ev]+0x6f): undefined reference to `SSL_CTX_get_ex_data'
Plugins/MyProject/libMyProject.a(MyProjectMatch.cpp.obj):MyProjectMatch.cpp:(.text$_ZN5boost4asio3ssl7contextD1Ev[__ZN5boost4asio3ssl7contextD1Ev]+0x8d): undefined reference to `SSL_CTX_get_ex_data'
Plugins/MyProject/libMyProject.a(MyProjectMatch.cpp.obj):MyProjectMatch.cpp:(.text$_ZN5boost4asio3ssl7contextD1Ev[__ZN5boost4asio3ssl7contextD1Ev]+0xc4): undefined reference to `SSL_CTX_set_ex_data'
Plugins/MyProject/libMyProject.a(MyProjectMatch.cpp.obj):MyProjectMatch.cpp:(.text$_ZN5boost4asio3ssl7contextD1Ev[__ZN5boost4asio3ssl7contextD1Ev]+0xd1): undefined reference to `SSL_CTX_free'
Plugins/MyProject/libMyProject.a(MyProjectMatch.cpp.obj):MyProjectMatch.cpp:(.text$_ZN5boost4asio3ssl7context11set_optionsElRNS_6system10error_codeE[__ZN5boost4asio3ssl7context11set_optionsElRNS_6system10error_codeE]+0x19): undefined reference to `SSL_CTX_set_options'
Plugins/MyProject/libMyProject.a(MyProjectMatch.cpp.obj):MyProjectMatch.cpp:(.text$_ZN5boost4asio3ssl7context15set_verify_modeEiRNS_6system10error_codeE[__ZN5boost4asio3ssl7context15set_verify_modeEiRNS_6system10error_codeE]+0x12): undefined reference to `SSL_CTX_get_verify_callback'
Plugins/MyProject/libMyProject.a(MyProjectMatch.cpp.obj):MyProjectMatch.cpp:(.text$_ZN5boost4asio3ssl7context15set_verify_modeEiRNS_6system10error_codeE[__ZN5boost4asio3ssl7context15set_verify_modeEiRNS_6system10error_codeE]+0x2c): undefined reference to `SSL_CTX_set_verify'
Plugins/MyProject/libMyProject.a(MyProjectMatch.cpp.obj):MyProjectMatch.cpp:(.text$_ZN5boost4asio3ssl7context16load_verify_fileERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERNS_6system10error_codeE[__ZN5boost4asio3ssl7context16load_verify_fileERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERNS_6system10error_codeE]+0xb): undefined reference to `ERR_clear_error'
Plugins/MyProject/libMyProject.a(MyProjectMatch.cpp.obj):MyProjectMatch.cpp:(.text$_ZN5boost4asio3ssl7context16load_verify_fileERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERNS_6system10error_codeE[__ZN5boost4asio3ssl7context16load_verify_fileERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERNS_6system10error_codeE]+0x2e): undefined reference to `SSL_CTX_load_verify_locations'
Plugins/MyProject/libMyProject.a(MyProjectMatch.cpp.obj):MyProjectMatch.cpp:(.text$_ZN5boost4asio3ssl7context16load_verify_fileERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERNS_6system10error_codeE[__ZN5boost4asio3ssl7context16load_verify_fileERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERNS_6system10error_codeE]+0x44): undefined reference to `ERR_get_error'
Plugins/MyProject/libMyProject.a(MyProjectMatch.cpp.obj):MyProjectMatch.cpp:(.text$_ZN5boost4asio3ssl7context24set_default_verify_pathsERNS_6system10error_codeE[__ZN5boost4asio3ssl7context24set_default_verify_pathsERNS_6system10error_codeE]+0x18): undefined reference to `SSL_CTX_set_default_verify_paths'
Plugins/MyProject/libMyProject.a(MyProjectMatch.cpp.obj):MyProjectMatch.cpp:(.text$_ZN5boost4asio3ssl7context24set_default_verify_pathsERNS_6system10error_codeE[__ZN5boost4asio3ssl7context24set_default_verify_pathsERNS_6system10error_codeE]+0x2e): undefined reference to `ERR_get_error'
Plugins/MyProject/libMyProject.a(MyProjectMatch.cpp.obj):MyProjectMatch.cpp:(.text$_ZN5boost4asio3ssl7context26use_certificate_chain_fileERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERNS_6system10error_codeE[__ZN5boost4asio3ssl7context26use_certificate_chain_fileERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERNS_6system10error_codeE]+0xb): undefined reference to `ERR_clear_error'
Plugins/MyProject/libMyProject.a(MyProjectMatch.cpp.obj):MyProjectMatch.cpp:(.text$_ZNK5boost4asio3ssl20rfc2818_verificationclEbRNS1_14verify_contextE[__ZNK5boost4asio3ssl20rfc2818_verificationclEbRNS1_14verify_contextE]+0x38e): undefined reference to `X509_NAME_ENTRY_get_data'
Plugins/MyProject/libMyProject.a(MyProjectMatch.cpp.obj):MyProjectMatch.cpp:(.text$_ZN5boost4asio3ssl6detail6engineC1EP10ssl_ctx_st[__ZN5boost4asio3ssl6detail6engineC1EP10ssl_ctx_st]+0x11): undefined reference to `SSL_new'
Plugins/MyProject/libMyProject.a(MyProjectMatch.cpp.obj):MyProjectMatch.cpp:(.text$_ZN5boost4asio3ssl6detail6engineC1EP10ssl_ctx_st[__ZN5boost4asio3ssl6detail6engineC1EP10ssl_ctx_st]+0x2d): undefined reference to `ERR_get_error'
Plugins/MyProject/libMyProject.a(MyProjectMatch.cpp.obj):MyProjectMatch.cpp:(.text$_ZN5boost4asio3ssl6detail6engineC1EP10ssl_ctx_st[__ZN5boost4asio3ssl6detail6engineC1EP10ssl_ctx_st]+0x7b): undefined reference to `SSL_ctrl'
Plugins/MyProject/libMyProject.a(MyProjectMatch.cpp.obj):MyProjectMatch.cpp:(.text$_ZN5boost4asio3ssl6detail6engineC1EP10ssl_ctx_st[__ZN5boost4asio3ssl6detail6engineC1EP10ssl_ctx_st]+0xa0): undefined reference to `SSL_ctrl'
Plugins/MyProject/libMyProject.a(MyProjectMatch.cpp.obj):MyProjectMatch.cpp:(.text$_ZN5boost4asio3ssl6detail6engineC1EP10ssl_ctx_st[__ZN5boost4asio3ssl6detail6engineC1EP10ssl_ctx_st]+0xc5): undefined reference to `SSL_ctrl'
Plugins/MyProject/libMyProject.a(MyProjectMatch.cpp.obj):MyProjectMatch.cpp:(.text$_ZN5boost4asio3ssl6detail6engineC1EP10ssl_ctx_st[__ZN5boost4asio3ssl6detail6engineC1EP10ssl_ctx_st]+0xf1): undefined reference to `BIO_new_bio_pair'
Plugins/MyProject/libMyProject.a(MyProjectMatch.cpp.obj):MyProjectMatch.cpp:(.text$_ZN5boost4asio3ssl6detail6engineD1Ev[__ZN5boost4asio3ssl6detail6engineD1Ev]+0x38): undefined reference to `SSL_get_ex_data'
Plugins/MyProject/libMyProject.a(MyProjectMatch.cpp.obj):MyProjectMatch.cpp:(.text$_ZN5boost4asio3ssl6detail6engineD1Ev[__ZN5boost4asio3ssl6detail6engineD1Ev]+0x64): undefined reference to `SSL_set_ex_data'
Plugins/MyProject/libMyProject.a(MyProjectMatch.cpp.obj):MyProjectMatch.cpp:(.text$_ZN5boost4asio3ssl6detail6engineD1Ev[__ZN5boost4asio3ssl6detail6engineD1Ev]+0x72): undefined reference to `BIO_free'
Plugins/MyProject/libMyProject.a(MyProjectMatch.cpp.obj):MyProjectMatch.cpp:(.text$_ZN5boost4asio3ssl6detail6engineD1Ev[__ZN5boost4asio3ssl6detail6engineD1Ev]+0x7f): undefined reference to `SSL_free'
Plugins/MyProject/libMyProject.a(MyProjectMatch.cpp.obj):MyProjectMatch.cpp:(.text$_ZN5boost4asio3ssl6detail6engine10get_outputERKNS0_14mutable_bufferE[__ZN5boost4asio3ssl6detail6engine10get_outputERKNS0_14mutable_bufferE]+0x30): undefined reference to `BIO_read'
Plugins/MyProject/libMyProject.a(MyProjectMatch.cpp.obj):MyProjectMatch.cpp:(.text$_ZN5boost4asio3ssl6detail6engine9put_inputERKNS0_12const_bufferE[__ZN5boost4asio3ssl6detail6engine9put_inputERKNS0_12const_bufferE]+0x30): undefined reference to `BIO_write'
Plugins/MyProject/libMyProject.a(MyProjectMatch.cpp.obj):MyProjectMatch.cpp:(.text$_ZNK5boost4asio3ssl6detail6engine14map_error_codeERNS_6system10error_codeE[__ZNK5boost4asio3ssl6detail6engine14map_error_codeERNS_6system10error_codeE]+0x62): undefined reference to `BIO_ctrl'
Plugins/MyProject/libMyProject.a(MyProjectMatch.cpp.obj):MyProjectMatch.cpp:(.text$_ZNK5boost4asio3ssl6detail6engine14map_error_codeERNS_6system10error_codeE[__ZNK5boost4asio3ssl6detail6engine14map_error_codeERNS_6system10error_codeE]+0x8f): undefined reference to `SSL_get_shutdown'
Plugins/MyProject/libMyProject.a(MyProjectMatch.cpp.obj):MyProjectMatch.cpp:(.text$_ZN5boost4asio3ssl6detail6engine7performEMS3_FiPvjES4_jRNS_6system10error_codeEPj[__ZN5boost4asio3ssl6detail6engine7performEMS3_FiPvjES4_jRNS_6system10error_codeEPj]+0x13): undefined reference to `BIO_ctrl_pending'
Plugins/MyProject/libMyProject.a(MyProjectMatch.cpp.obj):MyProjectMatch.cpp:(.text$_ZN5boost4asio3ssl6detail6engine7performEMS3_FiPvjES4_jRNS_6system10error_codeEPj[__ZN5boost4asio3ssl6detail6engine7performEMS3_FiPvjES4_jRNS_6system10error_codeEPj]+0x1b): undefined reference to `ERR_clear_error'
Plugins/MyProject/libMyProject.a(MyProjectMatch.cpp.obj):MyProjectMatch.cpp:(.text$_ZN5boost4asio3ssl6detail6engine7performEMS3_FiPvjES4_jRNS_6system10error_codeEPj[__ZN5boost4asio3ssl6detail6engine7performEMS3_FiPvjES4_jRNS_6system10error_codeEPj]+0x74): undefined reference to `SSL_get_error'
Plugins/MyProject/libMyProject.a(MyProjectMatch.cpp.obj):MyProjectMatch.cpp:(.text$_ZN5boost4asio3ssl6detail6engine7performEMS3_FiPvjES4_jRNS_6system10error_codeEPj[__ZN5boost4asio3ssl6detail6engine7performEMS3_FiPvjES4_jRNS_6system10error_codeEPj]+0x8d): undefined reference to `BIO_ctrl_pending'
Plugins/MyProject/libMyProject.a(MyProjectMatch.cpp.obj):MyProjectMatch.cpp:(.text$_ZN5boost4asio3ssl6detail6engine9do_acceptEPvj[__ZN5boost4asio3ssl6detail6engine9do_acceptEPvj]+0x12): undefined reference to `SSL_accept'
Plugins/MyProject/libMyProject.a(MyProjectMatch.cpp.obj):MyProjectMatch.cpp:(.text$_ZN5boost4asio3ssl6detail6engine10do_connectEPvj[__ZN5boost4asio3ssl6detail6engine10do_connectEPvj]+0x12): undefined reference to `SSL_connect'
Plugins/MyProject/libMyProject.a(MyProjectMatch.cpp.obj):MyProjectMatch.cpp:(.text$_ZN5boost4asio3ssl6detail6engine7do_readEPvj[__ZN5boost4asio3ssl6detail6engine7do_readEPvj]+0x30): undefined reference to `SSL_read'
Plugins/MyProject/libMyProject.a(MyProjectMatch.cpp.obj):MyProjectMatch.cpp:(.text$_ZN5boost4asio3ssl6detail6engine8do_writeEPvj[__ZN5boost4asio3ssl6detail6engine8do_writeEPvj]+0x30): undefined reference to `SSL_write'
Plugins/MyProject/libMyProject.a(MyProjectMatch.cpp.obj):MyProjectMatch.cpp:(.text$_ZN9SimpleWeb6ClientIN5boost4asio3ssl6streamINS2_19basic_stream_socketINS2_2ip3tcpEEEEEE9handshakeERKSt10shared_ptrINS_10ClientBaseIS9_E7SessionEE[__ZN9SimpleWeb6ClientIN5boost4asio3ssl6streamINS2_19basic_stream_socketINS2_2ip3tcpEEEEEE9handshakeERKSt10shared_ptrINS_10ClientBaseIS9_E7SessionEE]+0x51): undefined reference to `SSL_ctrl'
collect2.exe: error: ld returned 1 exit status
make[2]: *** [CMakeFiles\MyProjectDesignProject.dir\build.make:115: MyProjectDesignProject.exe] Error 1
make[2]: Leaving directory 'D:/MyProject_Repos/Cpp_Plugin_Repo/cpp-plugin-repo/server-cpp/Build'
make[1]: *** [CMakeFiles\Makefile2:80: CMakeFiles/MyProjectDesignProject.dir/all] Error 2
make[1]: Leaving directory 'D:/MyProject_Repos/Cpp_Plugin_Repo/cpp-plugin-repo/server-cpp/Build'
make: *** [Makefile:86: all] Error 2

undefined reference to symbol '_ZN5boost6system15system_categoryEv' /

this is not the first time I meet this error, but [previous solution][1] doesn't make sense.
[100%] Linking CXX executable ../bin/qttest
/usr/bin/x86_64-linux-gnu-ld: CMakeFiles/qttest.dir/src/main.cpp.o:
undefined reference to symbol '_ZN5boost6system15system_categoryEv'
/usr/lib/x86_64-linux-gnu/libboost_system.so: error adding symbols:
DSO missing from command line collect2: error: ld returned 1 exit
status
here is my cmakelists
cmake_minimum_required(VERSION 2.4.6)
set(OpenCV_DIR "/usr/local/opencv-2.4.9/share/OpenCV")
include_directories("/usr/local/opencv-2.4.9/include")
include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)
find_package(Qt4 COMPONENTS QtCore QtGui)
find_package(OpenCV 2.4.9 REQUIRED)
INCLUDE(${QT_USE_FILE})
ADD_DEFINITIONS(${QT_DEFINITIONS})
rosbuild_init()
rosbuild_genmsg()
find_package(Boost COMPONENTS system REQUIRED)
set(qt_srcs
src/mainwindow.cpp
src/listnerthr.cpp
src/ros_thr.cpp
src/CreatDataBuffer.cpp
src/CreatBuffer.cpp
src/pid_controller.cpp
src/low_pass_filter.cpp
src/plot_publisher.cpp)
set(qt_hdrs
src/mainwindow.h
src/listnerthr.h
src/ros_thr.h
src/CreatDataBuffer.h
src/HelperFunctions.h
src/CreatBuffer.h
src/pid_controller.h
src/low_pass_filter.h
src/plot_publisher.h)
qt4_automoc(${qt_srcs})
QT4_WRAP_CPP(qt_moc_srcs ${qt_hdrs})
QT4_WRAP_UI(uis_h src/mainwindow.ui)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)
rosbuild_add_executable(qttest src/main.cpp
${uis_h} ${qt_srcs} ${qt_moc_srcs})
target_link_libraries(qttest ${QT_LIBRARIES}${Boost_LIBARAIES }${OpenCV_LIBARAIES})
any clues would be appreciated.
I got another problem after changing the cmakelists
*** No rule to make target '/usr/lib/x86_64-linux-gnu/libboost_system.so/usr/lib/x86_64-linux-gnu/libboost_system.so', needed by '../bin/qttest'. Stop. CMakeFiles/Makefile2:425: recipe for target 'CMakeFiles/qttest.dir/all' failed –
You should pass boost libraries to the target_link_libraries command. The smallest change to your file will be as follows:
target_link_libraries(qttest ${QT_LIBRARIES} ${LIBS})
But since you are using find_package for Boost and you do not actually use your LIBS variable anywhere, you should stick with something like this:
find_package(Boost COMPONENTS system REQUIRED)
...
target_link_libraries(qttest ${QT_LIBRARIES} ${OpenCV_LIBS} ${Boost_LIBRARIES})
And remove LIBS altogether.

Trying to add Boost libraries to Cmake.txt (Clion Ide)

I see a lot of questions that are similar to this though not the same.
I'm having an issue getting boost recognized/working in Cmake using Clion I've tried a handful of ways including the incboost template included with Clion, moving on.
Cmake version 3.4
Boost version 1.60.0
find_package(Boost)
if (Boost_FOUND)
include_directories(${Boost_INCLUDE_DIR})
endif()
That's the auto generated incboost I mentioned above, This produces no results.
Second attempt is the following
set(Boost_Dir "C:\\Program Files (x86)\\boost_1_60_0\\")
find_package(Boost 1.60.0 COMPONENTS filesystem)
include_directories(${Boost_Dir})
CmakeFiles\Svp.dir/objects.a(main.cpp.obj):
In function`_static_initialization_and_destruction_0':
C:/PROGRA~2/BOOST_~1/boost/system/error_code.hpp:221: undefined reference
to `boost::system::generic_category()'
C:/PROGRA~2/BOOST_~1/boost/system/error_code.hpp:222: undefined
reference to `boost::system::generic_category()'
C:/PROGRA~2/BOOST_~1/boost/system/error_code.hpp:223: undefined
reference to `boost::system::system_category()'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: *** [Svp.exe] Error 1
CMakeFiles\Svp.dir\build.make:96: recipe for target 'Svp.exe' failed
CMakeFiles\Makefile2:66: recipe for target 'CMakeFiles/Svp.dir/all' failed
mingw32-make.exe[2]: *** [CMakeFiles/Svp.dir/all] Error 2
CMakeFiles\Makefile2:78: recipe for target 'CMakeFiles/Svp.dir/rule' failed
mingw32-make.exe[1]: *** [CMakeFiles/Svp.dir/rule] Error 2
Makefile:117: recipe for target 'Svp' failed
mingw32-make.exe: *** [Svp] Error 2
My Third attempt produces this
set(boost "C:\\Program Files (x86)\\boost_1_60_0\\boost\\")
INCLUDE_DIRECTORIES(${boost})
fatal error: boost/filesystem/config.hpp: No such file or directory
# include <boost/filesystem/config.hpp>
^
compilation terminated.
mingw32-make.exe[3]: *** [CMakeFiles/Svp.dir/main.cpp.obj] Error 1
mingw32-make.exe[2]: *** [CMakeFiles/Svp.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles/Svp.dir/rule] Error 2
And finally the solutions given here How do you add boost libraries in CMakeLists.txt have not changed my error output.
here's how I use it, in a portable way, in my projects:
if (WIN32)
set(BOOST_ROOT "C:/Program Files (x86)/boost_1_60_0/")
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREAD ON)
include_directories(${BOOST_ROOT})
link_directories(${BOOST_ROOT}/stage/lib) # add this before add_executable()
endif()
# Here call your add_executable method
# add_executable(TARGET_NAME ... )
if(NOT MSVC)
find_package(Boost REQUIRED COMPONENTS date_time filesystem wserialization system serialization thread regex)
if (Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
target_link_libraries(TARGET_NAME ${Boost_LIBRARIES})
endif()
endif()
You sometime need to specify the Boost_USE_STATIC_LIBS and Boost_USE_MULTITHREAD variables to help find_package find boost.
Also please specify the correct path to boost library with set(BOOST_ROOT, $path). Moreover, specify the boost packages you need in find_package. For instance
find_package(Boost REQUIRED COMPONENTS date_time filesystem thread regex)
if you only need the date_time filesystem thread regex packages
let me know if it works or not for you.

Resources