OpenCV SFM module has undefined references to other OpenCV modules - c++

I have built OpenCV 4.5.5 from source on Ubuntu 20.04.4 LTS with the sfm contrib module and I am trying to use it for scene reconstruction. The libraries were built successfully, however, whenever I call cv::sfm::reconstruct, I get the following linker errors when tying to build my program:
/usr/bin/ld: /usr/local/lib/x86_64-linux-gnu/libopencv_sfm.so.4.5.5: undefined reference to `cv::FlannBasedMatcher::add(cv::_InputArray const&)'
/usr/bin/ld: /usr/local/lib/x86_64-linux-gnu/libopencv_sfm.so.4.5.5: undefined reference to `cv::Mat::copyTo(cv::_OutputArray const&) const'
/usr/bin/ld: /usr/local/lib/x86_64-linux-gnu/libopencv_sfm.so.4.5.5: undefined reference to `cv::DescriptorMatcher::knnMatch(cv::_InputArray const&, std::vector<std::vector<cv::DMatch, std::allocator<cv::DMatch> >, std::allocator<std::vector<cv::DMatch, std::allocator<cv::DMatch> > > >&, int, cv::_InputArray const&, bool)'
/usr/bin/ld: /usr/local/lib/x86_64-linux-gnu/libopencv_sfm.so.4.5.5: undefined reference to `libmv::MotionFromEssential(Eigen::Matrix<double, 3, 3, 0, 3, 3> const&, std::__debug::vector<Eigen::Matrix<double, 3, 3, 0, 3, 3>, std::allocator<Eigen::Matrix<double, 3, 3, 0, 3, 3> > >*, std::__debug::vector<Eigen::Matrix<double, 3, 1, 0, 3, 1>, std::allocator<Eigen::Matrix<double, 3, 1, 0, 3, 1> > >*)'
/usr/bin/ld: /usr/local/lib/x86_64-linux-gnu/libopencv_sfm.so.4.5.5: undefined reference to `libmv::correspondence::nRobustViewMatching::computeCrossMatch(std::__debug::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&)'
collect2: error: ld returned 1 exit status
I have tried recompiling OpenCV with the sfm module and all its dependencies a number of different ways but nothing seems to solve this problem.
The issue seems to be that libopencv_sfm.so is being linked incorrectly somehow and can't find symbols from the other OpenCV modules. I have checked that the linker can find cv::FlannBasedMatcher::add when not called by libopencv_sfm.so and it works when called directly from my program. Running ldconfig on /usr/local/lib/x86_64-linux-gnu also didn't work.
Here's how I'm linking my code against OpenCV with CMake (note: not the top-level CMakeLists):
# Target name
project(sfmPointCloud)
# Setting variables
set(SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src")
set(INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include")
# Creating executable target
add_executable(
${PROJECT_NAME}
"${INCLUDE_DIR}/logger.h"
"${SRC_DIR}/main.cpp"
"${SRC_DIR}/cmdline_parser.cpp"
"${SRC_DIR}/sfmPointCloud.cpp"
)
# Setting target's properties
set_target_properties(
${PROJECT_NAME} PROPERTIES
LINKER_LANGUAGE CXX
CXX_STANDARD 20
)
# Instruct basic signature of `find_package` function to fall back to "Config"
# mode immediately instead of trying "Module" mode first since no libraries used
# provide a Find Module
set(CMAKE_FIND_PACKAGE_PREFER_CONFIG TRUE)
# Setting up OpenCV
message(STATUS "Searching for OpenCV package")
find_package(
OpenCV 4.5.5 REQUIRED
COMPONENTS core imgcodecs imgproc features2d calib3d xfeatures2d sfm
)
# Setting include directories and linking libraries
target_include_directories(
${PROJECT_NAME}
PRIVATE ${INCLUDE_DIR} # internal header files
PRIVATE "/usr/local/include/opencv4" # opencv2/
)
target_link_libraries(${PROJECT_NAME} ${OpenCV_LIBS})

Related

"undefined reference to .." error after make command

I am trying to include some libraries i downloaded using vcpkg. I want to use all of them from vcpkg instead of system libraries.
I am able to run cmake .. command in build directory. It is successful.
Then i run make command but i am getting lots of "undefined reference to" error for all libraries i linked.
Here is CmakeLists.txt:
set(CMAKE_TOOLCHAIN_FILE "/home/ubuntu-user/Desktop/flight-simulator/vcpkg/scripts/buildsystems/vcpkg.cmake")
set(PROJECT_NAME Simulator)
cmake_minimum_required(VERSION 3.12)
project(${PROJECT_NAME})
##OPENGL
find_package(OpenGL REQUIRED)
include_directories(${OPENGL_INCLUDE_DIRS})
##GLAD
find_path(GLAD_INCLUDE_DIR glad/glad.h)
find_library(GLAD_LIBRARY glad)
#message(${GLAD_INCLUDE_DIR})
#ASSIMP
find_library(ASSIMP_LIBRARY assimp)
#IMGUI
set(IMGUI_DIR ./libs/imgui-implot)
add_library(imgui STATIC
${IMGUI_DIR}/imgui_impl_glfw.cpp
${IMGUI_DIR}/imgui.cpp
)
#SOURCES
FILE(GLOB SOURCES
"src/Data.cpp"
"src/Frames.cpp"
"src/Model.cpp"
"src/main.cpp"
)
#EXECUTABLE
ADD_EXECUTABLE(${PROJECT_NAME} ${SOURCES})
target_include_directories(${PROJECT_NAME} PRIVATE ${IMGUI_DIR})
target_include_directories(${PROJECT_NAME} PRIVATE ${GLAD_INCLUDE_DIR})
target_link_libraries(${PROJECT_NAME} imgui ${OPENGL_LIBRARIES} assimp ${GLAD_LIBRARY})
Sample error log:
/usr/bin/ld: imgui_impl_glfw.cpp:(.text+0x1535): undefined reference to `glfwSetCursor'
/usr/bin/ld: imgui_impl_glfw.cpp:(.text+0x154e): undefined reference to `glfwSetInputMode'
/usr/bin/ld: libimgui.a(imgui_impl_glfw.cpp.o): in function `ImGui_ImplGlfw_UpdateGamepads()':
imgui_impl_glfw.cpp:(.text+0x15e8): undefined reference to `glfwGetGamepadState'
/usr/bin/ld: libimgui.a(imgui_impl_glfw.cpp.o): in function `ImGui_ImplGlfw_NewFrame()':
imgui_impl_glfw.cpp:(.text+0x1bb5): undefined reference to `glfwGetWindowSize'
/usr/bin/ld: imgui_impl_glfw.cpp:(.text+0x1bcf): undefined reference to `glfwGetFramebufferSize'
/usr/bin/ld: imgui_impl_glfw.cpp:(.text+0x1c4a): undefined reference to `glfwGetTime'
/usr/bin/ld: libimgui.a(imgui.cpp.o): in function `ImGuiStyle::ImGuiStyle()':
imgui.cpp:(.text+0xe23): undefined reference to `ImGui::StyleColorsDark(ImGuiStyle*)'
/usr/bin/ld: libimgui.a(imgui.cpp.o): in function `ImBezierCubicClosestPoint(ImVec2 const&, ImVec2 const&, ImVec2 const&, ImVec2 const&, ImVec2 const&, int)':
imgui.cpp:(.text+0x2614): undefined reference to `ImBezierCubicCalc(ImVec2 const&, ImVec2 const&, ImVec2 const&, ImVec2 const&, float)'
/usr/bin/ld: libimgui.a(imgui.cpp.o): in function `ImGuiTextFilter::Draw(char const*, float)':
imgui.cpp:(.text+0x564d): undefined reference to `ImGui::InputText(char const*, char*, unsigned long, int, int (*)(ImGuiInputTextCallbackData*), void*)'
/usr/bin/ld: libimgui.a(imgui.cpp.o): in function `ImGuiListClipper_SeekCursorAndSetupPrevLine(float, float)':
imgui.cpp:(.text+0x652f): undefined reference to `ImGui::TableEndRow(ImGuiTable*)'
/usr/bin/ld: libimgui.a(imgui.cpp.o): in function `ImGuiListClipper::Begin(int, float)':
I tried writing add_library instead of add_executable and make completed successfully. But then i don't have any executable output.
You are using imgui-plot which still requires ImGUI environment. ImGUI Plot Docs here. ImGUI example for GLFW3 and OpenGL3 here
You didn't link GLFW.
target_link_libraries(${PROJECT_NAME} ${OPENGL_LIBRARIES} glfw3 imgui assimp ${GLAD_LIBRARY})

Cmake link libmapnik c++

I am unable to connect Mapnik via cmake to my application.
I tried to do like this:
cmake_minimum_required(VERSION 3.1)
project(MapnikTest)
set(MAPNIK_LIB "/usr/local/lib/libmapnik.so.3.1.0") dont work
#set(MAPNIK_LIB "/usr/local/lib/libmapnik.so") dont work
set(MAPNIK_INCLUDE_DIR "/usr/local/include/mapnik") work
#find_package(mapnik REQUIRED) dont work
#find_package(Mapnik REQUIRED) dont work
include_directories(${MAPNIK_INCLUDE_DIR})
add_executable(${PROJECT_NAME} main.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE ${MAPNIK_LIB})
The thing is, I don't have mapnikConfig.cmake in /usr/local/bin/cmake
Can't connect the library directly. Include he sees.
I edited already LD_LIBRARY_PATH it didn't help either.
/usr/bin/ld: CMakeFiles/MapnikTest.dir/main.cpp.o: in function `main':
main.cpp:(.text+0x3b): undefined reference to `mapnik::Map::Map(int, int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/usr/bin/ld: main.cpp:(.text+0xb8): undefined reference to `mapnik::load_map(mapnik::Map&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
/usr/bin/ld: main.cpp:(.text+0x1b9): undefined reference to `void mapnik::save_to_file<mapnik::image<mapnik::rgba8_t> >(mapnik::image<mapnik::rgba8_t> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/usr/bin/ld: CMakeFiles/MapnikTest.dir/main.cpp.o: in function `icu_66::UnicodeString::hashCode() const':
main.cpp:(.text._ZNK6icu_6613UnicodeString8hashCodeEv[_ZNK6icu_6613UnicodeString8hashCodeEv]+0x18): undefined reference to `icu_66::UnicodeString::doHashCode() const'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/MapnikTest.dir/build.make:104: MapnikTest] Error 1
make[1]: *** [CMakeFiles/Makefile2:95: CMakeFiles/MapnikTest.dir/all] Error 2
make: *** [Makefile:103: all] Error 2
(dont work mean this)
Find where you have mapnikConfig.cmake or mapnik-config.cmake and set mapnik_DIR to it. Like this:
cmake -Dmapnik_DIR="/path/to/config" ..
and it should be
find_package(mapnik REQUIRED)
Edit
When I inspect github more carefully it turn out that cmake config was introduced recently, after last release. So my answer will become valid for next release of this library.
You can inspect this change to see how import that library.
Original (valid after next release 3.2):
Based on demo form Mapnik repo it should go like this:
cmake_minimum_required(VERSION 3.1)
project(MapnikTest)
find_package(mapnik REQUIRED)
add_executable(${PROJECT_NAME} main.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE mapnik::agg mapnik::mapnik)
Didn't test it, but should work. I can see library provides proper config.

conan built C++ program suddenly not linking

I am writing a project in C++ and utilizing conan + cmake to manage the dependencies.. I just now started looking to upgrade to latest versions of my client and thrift dependency (v0.13 to v0.15) but it suddenly complains at the linking stage...
tried adding thriftnb , CONAN_PKG::thriftnb, event ... but nothing seems to change
-- Conan: Adjusting output directories
-- Conan: Using cmake targets configuration
-- Library thriftz found /home/emcp/.conan/data/thrift/0.13.0/_/_/package/44b3a17b9712eb98c7cab65c26ec70335992ff20/lib/libthriftz.a
-- Library thriftnb found /home/emcp/.conan/data/thrift/0.13.0/_/_/package/44b3a17b9712eb98c7cab65c26ec70335992ff20/lib/libthriftnb.a
-- Library thrift found /home/emcp/.conan/data/thrift/0.13.0/_/_/package/44b3a17b9712eb98c7cab65c26ec70335992ff20/lib/libthrift.a
-- Library twsapi found /home/emcp/.conan/data/ibsapi/10.10.01/bonks/prod/package/2a30b7d6ea2202e5393ebda51c8729dd2162b9f8/lib/libtwsapi.a
-- Library boost_contract found /home/emcp/.conan/data/boost/1.78.0/_/_/package/adf48b8e4446dcb68f440fe42ff08878d5c7feed/lib/libboost_contract.a
-- Library boost_coroutine found /home/emcp/.conan/data/boost/1.78.0/_/_/package/adf48b8e4446dcb68f440fe42ff08878d5c7feed/lib/libboost_coroutine.a
-- Library boost_fiber_numa found /home/emcp/.conan/data/boost/1.78.0/_/_/package/adf48b8e4446dcb68f440fe42ff08878d5c7feed/lib/libboost_fiber_numa.a
-- Library boost_fiber found /home/emcp/.conan/data/boost/1.78.0/_/_/package/adf48b8e4446dcb68f440fe42ff08878d5c7feed/lib/libboost_fiber.a
-- Library boost_context found /home/emcp/.conan/data/boost/1.78.0/_/_/package/adf48b8e4446dcb68f440fe42ff08878d5c7feed/lib/libboost_context.a
-- Library boost_graph found /home/emcp/.conan/data/boost/1.78.0/_/_/package/adf48b8e4446dcb68f440fe42ff08878d5c7feed/lib/libboost_graph.a
-- Library boost_iostreams found /home/emcp/.conan/data/boost/1.78.0/_/_/package/adf48b8e4446dcb68f440fe42ff08878d5c7feed/lib/libboost_iostreams.a
-- Library boost_json found /home/emcp/.conan/data/boost/1.78.0/_/_/package/adf48b8e4446dcb68f440fe42ff08878d5c7feed/lib/libboost_json.a
-- Library boost_locale found /home/emcp/.conan/data/boost/1.78.0/_/_/package/adf48b8e4446dcb68f440fe42ff08878d5c7feed/lib/libboost_locale.a
-- Library boost_log_setup found /home/emcp/.conan/data/boost/1.78.0/_/_/package/adf48b8e4446dcb68f440fe42ff08878d5c7feed/lib/libboost_log_setup.a
-- Library boost_log found /home/emcp/.conan/data/boost/1.78.0/_/_/package/adf48b8e4446dcb68f440fe42ff08878d5c7feed/lib/libboost_log.a
-- Library boost_math_c99 found /home/emcp/.conan/data/boost/1.78.0/_/_/package/adf48b8e4446dcb68f440fe42ff08878d5c7feed/lib/libboost_math_c99.a
-- Library boost_math_c99f found /home/emcp/.conan/data/boost/1.78.0/_/_/package/adf48b8e4446dcb68f440fe42ff08878d5c7feed/lib/libboost_math_c99f.a
-- Library boost_math_c99l found /home/emcp/.conan/data/boost/1.78.0/_/_/package/adf48b8e4446dcb68f440fe42ff08878d5c7feed/lib/libboost_math_c99l.a
-- Library boost_math_tr1 found /home/emcp/.conan/data/boost/1.78.0/_/_/package/adf48b8e4446dcb68f440fe42ff08878d5c7feed/lib/libboost_math_tr1.a
-- Library boost_math_tr1f found /home/emcp/.conan/data/boost/1.78.0/_/_/package/adf48b8e4446dcb68f440fe42ff08878d5c7feed/lib/libboost_math_tr1f.a
-- Library boost_math_tr1l found /home/emcp/.conan/data/boost/1.78.0/_/_/package/adf48b8e4446dcb68f440fe42ff08878d5c7feed/lib/libboost_math_tr1l.a
-- Library boost_nowide found /home/emcp/.conan/data/boost/1.78.0/_/_/package/adf48b8e4446dcb68f440fe42ff08878d5c7feed/lib/libboost_nowide.a
-- Library boost_program_options found /home/emcp/.conan/data/boost/1.78.0/_/_/package/adf48b8e4446dcb68f440fe42ff08878d5c7feed/lib/libboost_program_options.a
-- Library boost_random found /home/emcp/.conan/data/boost/1.78.0/_/_/package/adf48b8e4446dcb68f440fe42ff08878d5c7feed/lib/libboost_random.a
-- Library boost_regex found /home/emcp/.conan/data/boost/1.78.0/_/_/package/adf48b8e4446dcb68f440fe42ff08878d5c7feed/lib/libboost_regex.a
-- Library boost_stacktrace_addr2line found /home/emcp/.conan/data/boost/1.78.0/_/_/package/adf48b8e4446dcb68f440fe42ff08878d5c7feed/lib/libboost_stacktrace_addr2line.a
-- Library boost_stacktrace_backtrace found /home/emcp/.conan/data/boost/1.78.0/_/_/package/adf48b8e4446dcb68f440fe42ff08878d5c7feed/lib/libboost_stacktrace_backtrace.a
-- Library boost_stacktrace_basic found /home/emcp/.conan/data/boost/1.78.0/_/_/package/adf48b8e4446dcb68f440fe42ff08878d5c7feed/lib/libboost_stacktrace_basic.a
-- Library boost_stacktrace_noop found /home/emcp/.conan/data/boost/1.78.0/_/_/package/adf48b8e4446dcb68f440fe42ff08878d5c7feed/lib/libboost_stacktrace_noop.a
-- Library boost_timer found /home/emcp/.conan/data/boost/1.78.0/_/_/package/adf48b8e4446dcb68f440fe42ff08878d5c7feed/lib/libboost_timer.a
-- Library boost_type_erasure found /home/emcp/.conan/data/boost/1.78.0/_/_/package/adf48b8e4446dcb68f440fe42ff08878d5c7feed/lib/libboost_type_erasure.a
-- Library boost_thread found /home/emcp/.conan/data/boost/1.78.0/_/_/package/adf48b8e4446dcb68f440fe42ff08878d5c7feed/lib/libboost_thread.a
-- Library boost_chrono found /home/emcp/.conan/data/boost/1.78.0/_/_/package/adf48b8e4446dcb68f440fe42ff08878d5c7feed/lib/libboost_chrono.a
-- Library boost_container found /home/emcp/.conan/data/boost/1.78.0/_/_/package/adf48b8e4446dcb68f440fe42ff08878d5c7feed/lib/libboost_container.a
-- Library boost_date_time found /home/emcp/.conan/data/boost/1.78.0/_/_/package/adf48b8e4446dcb68f440fe42ff08878d5c7feed/lib/libboost_date_time.a
-- Library boost_unit_test_framework found /home/emcp/.conan/data/boost/1.78.0/_/_/package/adf48b8e4446dcb68f440fe42ff08878d5c7feed/lib/libboost_unit_test_framework.a
-- Library boost_prg_exec_monitor found /home/emcp/.conan/data/boost/1.78.0/_/_/package/adf48b8e4446dcb68f440fe42ff08878d5c7feed/lib/libboost_prg_exec_monitor.a
-- Library boost_test_exec_monitor found /home/emcp/.conan/data/boost/1.78.0/_/_/package/adf48b8e4446dcb68f440fe42ff08878d5c7feed/lib/libboost_test_exec_monitor.a
-- Library boost_exception found /home/emcp/.conan/data/boost/1.78.0/_/_/package/adf48b8e4446dcb68f440fe42ff08878d5c7feed/lib/libboost_exception.a
-- Library boost_wave found /home/emcp/.conan/data/boost/1.78.0/_/_/package/adf48b8e4446dcb68f440fe42ff08878d5c7feed/lib/libboost_wave.a
-- Library boost_filesystem found /home/emcp/.conan/data/boost/1.78.0/_/_/package/adf48b8e4446dcb68f440fe42ff08878d5c7feed/lib/libboost_filesystem.a
-- Library boost_atomic found /home/emcp/.conan/data/boost/1.78.0/_/_/package/adf48b8e4446dcb68f440fe42ff08878d5c7feed/lib/libboost_atomic.a
-- Library boost_wserialization found /home/emcp/.conan/data/boost/1.78.0/_/_/package/adf48b8e4446dcb68f440fe42ff08878d5c7feed/lib/libboost_wserialization.a
-- Library boost_serialization found /home/emcp/.conan/data/boost/1.78.0/_/_/package/adf48b8e4446dcb68f440fe42ff08878d5c7feed/lib/libboost_serialization.a
-- Library event_extra found /home/emcp/.conan/data/libevent/2.1.12/_/_/package/6b0981c427aa0eb8bea05add2094df29ed639799/lib/libevent_extra.a
-- Library event_openssl found /home/emcp/.conan/data/libevent/2.1.12/_/_/package/6b0981c427aa0eb8bea05add2094df29ed639799/lib/libevent_openssl.a
-- Library event_pthreads found /home/emcp/.conan/data/libevent/2.1.12/_/_/package/6b0981c427aa0eb8bea05add2094df29ed639799/lib/libevent_pthreads.a
-- Library event_core found /home/emcp/.conan/data/libevent/2.1.12/_/_/package/6b0981c427aa0eb8bea05add2094df29ed639799/lib/libevent_core.a
-- Library z found /home/emcp/.conan/data/zlib/1.2.11/_/_/package/6af9cc7cb931c5ad942174fd7838eb655717c709/lib/libz.a
-- Library bz2 found /home/emcp/.conan/data/bzip2/1.0.8/_/_/package/da606cf731e334010b0bf6e85a2a6f891b9f36b0/lib/libbz2.a
-- Library backtrace found /home/emcp/.conan/data/libbacktrace/cci.20210118/_/_/package/6af9cc7cb931c5ad942174fd7838eb655717c709/lib/libbacktrace.a
-- Library ssl found /home/emcp/.conan/data/openssl/1.1.1m/_/_/package/6af9cc7cb931c5ad942174fd7838eb655717c709/lib/libssl.a
-- Library crypto found /home/emcp/.conan/data/openssl/1.1.1m/_/_/package/6af9cc7cb931c5ad942174fd7838eb655717c709/lib/libcrypto.a
-- Conan: Adjusting default RPATHs Conan policies
-- Conan: Adjusting language standard
-- Current conanbuildinfo.cmake directory: /ibs-api-thrift/servers/cpp_server/build_cmake
-- Conan: Compiler GCC>=5, checking major version 9
-- Conan: Checking correct version: 9
-- Configuring done
-- Generating done
-- Build files have been written to: /ibsapi-thrift/servers/cpp_server/build_cmake
...
[100%] Linking CXX executable bin/jokers_server
/usr/bin/ld: CMakeFiles/jokers_server.dir/src/gen-cpp/jokers.cpp.o: in function `ibsapithrift::jokersConcurrentClient::recv_connect(int)':
jokers.cpp:(.text+0x63f8): undefined reference to `apache::thrift::async::TConcurrentClientSyncInfo::updatePending(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, apache::thrift::protocol::TMessageType, int)'
/usr/bin/ld: jokers.cpp:(.text+0x6416): undefined reference to `apache::thrift::async::TConcurrentClientSyncInfo::getPending(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, apache::thrift::protocol::TMessageType&, int&)'
/usr/bin/ld: CMakeFiles/jokers_server.dir/src/gen-cpp/jokers.cpp.o: in function `ibsapithrift::jokersConcurrentClient::recv_disconnect(int)':
jokers.cpp:(.text+0x6968): undefined reference to `apache::thrift::async::TConcurrentClientSyncInfo::updatePending(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, apache::thrift::protocol::TMessageType, int)'
/usr/bin/ld: jokers.cpp:(.text+0x6986): undefined reference to `apache::thrift::async::TConcurrentClientSyncInfo::getPending(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, apache::thrift::protocol::TMessageType&, int&)'
/usr/bin/ld: CMakeFiles/jokers_server.dir/src/gen-cpp/jokers.cpp.o: in function `ibsapithrift::jokersConcurrentClient::recv_ping(int)':
jokers.cpp:(.text+0x6ed8): undefined reference to `apache::thrift::async::TConcurrentClientSyncInfo::updatePending(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, apache::thrift::protocol::TMessageType, int)'
/usr/bin/ld: jokers.cpp:(.text+0x6ef6): undefined reference to `apache::thrift::async::TConcurrentClientSyncInfo::getPending(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, apache::thrift::protocol::TMessageType&, int&)'
/usr/bin/ld: CMakeFiles/jokers_server.dir/src/gen-cpp/jokers.cpp.o: in function `ibsapithrift::jokersConcurrentClient::recv_ib_status(std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&, int)':
jokers.cpp:(.text+0xa098): undefined reference to `apache::thrift::async::TConcurrentClientSyncInfo::updatePending(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, apache::thrift::protocol::TMessageType, int)'
/usr/bin/ld: jokers.cpp:(.text+0xa0b6): undefined reference to `apache::thrift::async::TConcurrentClientSyncInfo::getPending(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, apache::thrift::protocol::TMessageType&, int&)'
/usr/bin/ld: CMakeFiles/jokers_server.dir/src/gen-cpp/jokers.cpp.o: in function `ibsapithrift::jokersConcurrentClient::recv_request_news(std::vector<ibsapithrift::NewsResponse, std::allocator<ibsapithrift::NewsResponse> >&, int)':
jokers.cpp:(.text+0xd378): undefined reference to `apache::thrift::async::TConcurrentClientSyncInfo::updatePending(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, apache::thrift::protocol::TMessageType, int)'
/usr/bin/ld: jokers.cpp:(.text+0xd396): undefined reference to `apache::thrift::async::TConcurrentClientSyncInfo::getPending(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, apache::thrift::protocol::TMessageType&, int&)'
/usr/bin/ld: CMakeFiles/jokers_server.dir/src/gen-cpp/jokers.cpp.o: in function `ibsapithrift::jokersConcurrentClient::recv_request_historical(std::vector<ibsapithrift::HistoricalResponse, std::allocator<ibsapithrift::HistoricalResponse> >&, int)':
jokers.cpp:(.text+0xe4f8): undefined reference to `apache::thrift::async::TConcurrentClientSyncInfo::updatePending(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, apache::thrift::protocol::TMessageType, int)'
/usr/bin/ld: jokers.cpp:(.text+0xe516): undefined reference to `apache::thrift::async::TConcurrentClientSyncInfo::getPending(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, apache::thrift::protocol::TMessageType&, int&)'
/usr/bin/ld: CMakeFiles/jokers_server.dir/src/gen-cpp/jokers.cpp.o: in function `ibsapithrift::jokersConcurrentClient::recv_request_matching_symbols(std::vector<ibsapithrift::MatchingSymbolResponse, std::allocator<ibsapithrift::MatchingSymbolResponse> >&, int)':
jokers.cpp:(.text+0xf678): undefined reference to `apache::thrift::async::TConcurrentClientSyncInfo::updatePending(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, apache::thrift::protocol::TMessageType, int)'
/usr/bin/ld: jokers.cpp:(.text+0xf696): undefined reference to `apache::thrift::async::TConcurrentClientSyncInfo::getPending(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, apache::thrift::protocol::TMessageType&, int&)'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/jokers_server.dir/build.make:212: bin/jokers_server] Error 1
make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/jokers_server.dir/all] Error 2
make: *** [Makefile:84: all] Error 2
chmod: cannot access 'jokers_server': No such file or directory
My CMakeLists.txt
cmake_minimum_required(VERSION 2.8.12)
project(jokers_server)
add_compile_options(-std=c++17)
# Using the "cmake" generator
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)
FILE ( GLOB THRIFT_GEN_SRC src/gen-cpp/*.cpp )
FILE ( GLOB IBS_API_SRC src/ibs-client/*.cpp )
add_executable(jokers_server src/jokers_server.cpp src/threadsafe_stack.cpp ${THRIFT_GEN_SRC} ${IBS_API_SRC} )
target_link_libraries(jokers_server pthread CONAN_PKG::thrift CONAN_PKG::ibsapi)`
I did some digging that I might need to add lib event.. which conan had picked up in the dependencies but.. adding CONAN_PKG::libevent did nothing
EDIT: In the thrift documentation
https://github.com/apache/thrift/tree/master/lib/cpp#linking-against-thrift-1
You need to link your project that uses thrift against all the thrift
dependencies; in the case of libthrift, openssl, pthreads, and librt
and for libthriftnb, libevent.
In the project properties you must also set HAVE_CONFIG_H as force
include the config header: "windows/config.h"
any clue if I am needing to add something ? this was all working last time i built the project .. so I must have missed some dev tools locally that my previous machine had?
turned out.. by default conan doesn't do the new ABI.. so when I built it last, I'd had to set the default behavior.. and you can do this by the following command.. once i did this and rebuilt my ibs-api conan recipe.. and built thrift .. everything worked 100%
conan profile update settings.compiler.libcxx=libstdc++11 <MY_DEFAULT_PROFILE>

Linking yaml-cpp with conan

I'm using yaml-cpp from conan center, in my conan file, yaml-cpp/0.6.3, along with other dependencies.
The rest of the libraries link properly, so there must be something missing in my CMakeLists.txt file. (Maybe some extra definition...?)
Until now, with those lines:
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
set(CMAKE_CXX_STANDARD 20)
It worked fine (For other libraries, like bullet, glm...)
At link time, problems with missing implementation arise:
cmake --build build --config Debug --target all -- -j 10
/usr/bin/ld: CMakeFiles/my-project.dir/src/MySourceFile.cpp.o: in function `YAML::Node::Scalar[abi:cxx11]() const':
/home/my-user/.conan/data/yaml-cpp/0.6.3/_/_/package/82ef5eac51c38971dea2fd342dd55ddf2ddfbbc3/include/yaml-cpp/node/impl.h:169: undefined reference to `YAML::detail::node_data::empty_scalar[abi:cxx11]()'
/usr/bin/ld: CMakeFiles/my-project.dir/src/MySource.cpp.o: in function `tojson::loadyaml(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
/home/my-user/my-project/lib/nlohmann/tojson.hpp:162: undefined reference to `YAML::LoadFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
collect2: error: ld returned 1 exit status
Seems that the problem is that YAML::LoadFile appears to be undefined.
(I've tried using it without tojson also)
YAML::Node test = YAML::LoadFile("test.yaml");
The package is okay, but your profile is misconfigured.
undefined reference to `YAML::LoadFile(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&)'
collect2: error: ld returned 1 exit status
You have to update your libcxx setting:
conan profile update settings.compiler.libcxx=libstdc++11 default
More info about: https://docs.conan.io/en/latest/howtos/manage_gcc_abi.html

How to include a static library using cmake?

I want to add the library ixwebsocket my project. Following the instructions of the library I get the libixwebsocket.a (the compiled static library, correct me if I am wrong).
How I can use this .a file in my project?
For testing I have created the following program: main.cpp
#CMakeLists.txt
cmake_minimum_required(VERSION 3.0.0)
project(cpptest VERSION 0.1.0)
include(CTest)
enable_testing()
add_executable(cpptest main.cpp)
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)
target_link_libraries(cpptest "${CMAKE_SOURCE_DIR}/libixwebsocket.a")
//main.cpp
#include <iostream>
#include <ixwebsocket/IXNetSystem.h>
#include <ixwebsocket/IXWebSocket.h>
int main(int, char**) {
std::cout << "Hello, world!\n";
ix::WebSocket webSocket;
}
In the directory I have CMakeLists.txt, libixwebsocket.a and main.cpp.
I get a long list of undefined reference errors, the firsts ones:
[build] [ 50%] Linking CXX executable cpptest
[build] /usr/bin/ld: ../libixwebsocket.a(IXWebSocket.cpp.o): in function `ix::WebSocket::start()':
[build] IXWebSocket.cpp:(.text+0x2240): undefined reference to `pthread_create'
ld] /usr/bin/ld: ../libixwebsocket.a(IXWebSocket.cpp.o): in function `ix::WebSocket::checkConnection(bool)':
[build] IXWebSocket.cpp:(.text+0x5b8d): undefined reference to `pthread_cond_clockwait'
[build] /usr/bin/ld: ../libixwebsocket.a(IXWebSocketPerMessageDeflateCodec.cpp.o): in function `bool ix::WebSocketPerMessageDeflateCompressor::compressData<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&) [clone .part.0]':
[build] IXWebSocketPerMessageDeflateCodec.cpp:(.text+0x67): undefined reference to `deflate'
[build] /usr/bin/ld: ../libixwebsocket.a(IXWebSocketPerMessageDeflateCodec.cpp.o): in function `ix::WebSocketPerMessageDeflateCompressor::~WebSocketPerMessageDeflateCompressor()':
[build] IXWebSocketPerMessageDeflateCodec.cpp:(.text+0x35c): undefined reference to `deflateEnd'
[build] /usr/bin/ld: ../libixwebsocket.a(IXWebSocketPerMessageDeflateCodec.cpp.o): in function `ix::WebSocketPerMessageDeflateCompressor::init(unsigned char, bool)':
[build] IXWebSocketPerMessageDeflateCodec.cpp:(.text+0x3a6): undefined reference to `deflateInit2_'
[build] /usr/bin/ld: ../libixwebsocket.a(IXWebSocketPerMessageDeflateCodec.cpp.o): in function `ix::WebSocketPerMessageDeflateDecompressor::~WebSocketPerMessageDeflateDecompressor()':
[build] IXWebSocketPerMessageDeflateCodec.cpp:(.text+0x64c): undefined reference to `inflateEnd'
[build] /usr/bin/ld: ../libixwebsocket.a(IXWebSocketPerMessageDeflateCodec.cpp.o): in function `ix::WebSocketPerMessageDeflateDecompressor::init(unsigned char, bool)':
[build] IXWebSocketPerMessageDeflateCodec.cpp:(.text+0x685): undefined reference to `inflateInit2_'
[build] /usr/bin/ld: ../libixwebsocket.a(IXWebSocketPerMessageDeflateCodec.cpp.o): in function `ix::WebSocketPerMessageDeflateDecompressor::decompress(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&)':
[build] IXWebSocketPerMessageDeflateCodec.cpp:(.text+0x7d6): undefined reference to `inflate'
[build] /usr/bin/ld: ../libixwebsocket.a(IXWebSocketPerMessageDeflateCodec.cpp.o): in function `bool ix::WebSocketPerMessageDeflateCompressor::compressData<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::vector<unsigned char, std::allocator<unsigned char> > >(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::vector<unsigned char, std::allocator<unsigned char> >&) [clone .part.0]':
[build] IXWebSocketPerMessageDeflateCodec.cpp:(.text+0x90d): undefined reference to `deflate'
[build] /usr/bin/ld: ../libixwebsocket.a(IXSocketOpenSSL.cpp.o): in function `ix::SocketOpenSSL::openSSLInitialize()':
[build] IXSocketOpenSSL.cpp:(.text+0x1c): undefined reference to `OPENSSL_init_ssl'
[build] /usr/bin/ld: IXSocketOpenSSL.cpp:(.text+0x29): undefined reference to `OPENSSL_init_ssl'
How may these undefined refrence errors be resolved?
Thanks in advance!
It would be always best to use find_package() calls. This way you ensure that the library is indeed installed on your system, or is exported in the build tree.
If you have the library installed on your system you can use this call, like this:
find_package(ixwebsocket REQUIRED)
target_link_libraries(cpptest ixwebsocket::ixwebsocket)
In your case, since the library is compiled independently (and it is not a target in your tree), you need to use find_library(IXWEBSOCKET_LIB ixwebsocket) and specify additional hints/names if you have the library in your own location, following the docs.
I ran into a similar issue today, the library was linking just fine but a static lib is just a collection of .o files and has no understanding of it's own dependencies...
This command worked for me:
g++ -o output/myapp -std=c++17 myapp.cpp -Llib -framework CoreFoundation -framework Security -lmylib
I'm no expert in CMake but this answer seems to indicate that the below would achieve the same effect
target_link_libraries(program "-framework CoreFoundation" "-framework Security")
So if we apply it to your case:
#CMakeLists.txt
cmake_minimum_required(VERSION 3.0.0)
project(cpptest VERSION 0.1.0)
include(CTest)
enable_testing()
add_executable(cpptest main.cpp)
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)
target_link_libraries(cpptest "${CMAKE_SOURCE_DIR}/libixwebsocket.a" "-framework CoreFoundation")
I've got a feeling pthread_create is likely to live in CoreFoundation but I'm just guessing... You may need to try a few frameworks to find the right one.
Hope this helps a little :)