I am new to C++ and external dependencies.
Really don't know how to fix this compile error...
Error:
Undefined symbols for architecture x86_64:
"uS::TLS::Context::~Context()", referenced from:
CMakeLists.txt:
cmake_minimum_required(VERSION 2.8)
project( opencv )
add_definitions(
-std=c++11
)
find_package(OpenCV REQUIRED)
find_package(ZLIB REQUIRED)
include_directories(${ZLIB_INCLUDE_DIRS})
find_package(OpenSSL REQUIRED)
include_directories(${OPENSSL_INCLUDE_DIR})
add_executable( opencv main.cpp Camera.cpp Camera.h Communication.cpp Communication.h)
target_link_libraries( opencv
${OpenCV_LIBS}
${OPENSSL_LIBRARIES}
${ZLIB_LIBRARIES}
)
Related
I'm trying to set up a project project in Xcode with allegro. I installed allegro5 using homebrew. My CMakeLists.txt is as below:
set(SOURCE_FILES "main.cpp")
add_executable(core ${SOURCE_FILES})
if(WIN32)
# TODO.
else(APPLE)
set(ALLEGRO_INCLUDE "/usr/local/include")
set(ALLEGRO_LIB "/usr/local/lib")
set(ALLEGRO_DYLIB, "/usr/local/lib/*.dylib")
set(ALLEGRO_LINK_FLAGS "-lallegro -lallegro_main")
endif()
include_directories(${ALLEGRO_INCLUDE})
link_directories(${ALLEGRO_LIB})
file(GLOB LIBRARIES ${ALLEGRO_DYLIB})
target_link_libraries(core ${LIBRARIES} ${ALLEGRO_LINK_FLAGS})
However, I keep getting the error: ld: library not found for -lallegro
EDIT:
Edited CMakeLists.txt file:
set(SOURCE_FILES "main.cpp")
add_executable(core ${SOURCE_FILES})
if(WIN32)
# TODO.
else(APPLE)
set(ALLEGRO_INCLUDE "/usr/local/include")
set(ALLEGRO_LIB "/usr/local/lib")
set(ALLEGRO_DYLIB, "/usr/local/lib/*.dylib")
endif()
include_directories(${ALLEGRO_INCLUDE})
link_directories(${ALLEGRO_LIB})
file(GLOB LIBRARIES ${ALLEGRO_DYLIB})
target_link_libraries(core ${LIBRARIES} ${ALLEGRO_DYLIB})
And now I'm getting the error:
Undefined symbols for architecture x86_64:
"_main", referenced from:
implicit entry/start for main executable
(maybe you meant: __al_mangled_main)
ld: symbol(s) not found for architecture x86_64
You misunderstood target_link_libraries, you don't set the link flags here, but you indicate the list of libraries you want to target, so that would be:
target_link_libraries(core ${LIBRARIES} ${ALLEGRO_DYLIB})
Otherwise you will get flags like -l-lallegro.
I'm trying to use Matlab Engine with C++, but I have some problems.
This is my CMakeList.txt
cmake_minimum_required(VERSION 2.8)
project(test)
SET(PROJECT_PATH "/home/bruno/projects/Test")
SET(CMAKE_CXX_FLAGS "-std=c++0x")
SET(CMAKE_BUILD_TYPE "Debug")
SET(CMAKE_VERBOSE_MAKEFILE ON)
SET(CMAKE_USE_RELATIVE_PATHS ON)
find_package(Eigen3 REQUIRED)
include_directories(
${CMAKE_SOURCE_DIR}
)
include_directories (/home/bruno/MATLAB/R2017a/extern/include/)
link_directories(/home/bruno/MATLAB/R2017a/bin/glnxa64/)
include_directories(${EIGEN3_INCLUDE_DIR})
add_executable(${CMAKE_PROJECT_NAME} test.cpp)
target_link_libraries(${CMAKE_PROJECT_NAME} -pthread )
target_link_libraries( ${CMAKE_PROJECT_NAME} libeng.so )
target_link_libraries( ${CMAKE_PROJECT_NAME} libmx.so )
When I try to execute test.cpp, I get
/home/bruno/projects/test/test.cpp:44: undefined reference to `matOpen'
and other undefined reference. What's wrong?
You aren't linking to libmat.so:
target_link_libraries( ${CMAKE_PROJECT_NAME} libmx libeng libmat )
I'm currently trying to compile a program that uses Boost.Filesystem on macOS High Sierra 10.13.4. I'm also using gcc 7.3 to compile, which I manually installed using Homebrew. The program will compile, but then throws the following error during linking
Undefined symbols for architecture x86_64:
"boost::filesystem::path_traits::dispatch(boost::filesystem::directory_entry const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&)", referenced from:
boost::enable_if<boost::filesystem::path_traits::is_pathable<boost::decay<boost::filesystem::directory_entry>::type>, boost::filesystem::path&>::type boost::filesystem::path::operator=<boost::filesystem::directory_entry>(boost::filesystem::directory_entry const&) in world.cc.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
I'm using cmake to build, and my CMakeLists.txt file looks like this
cmake_minimum_required (VERSION 3.0)
MESSAGE(STATUS "Compiler: " ${CMAKE_CXX_COMPILER})
# variables for CMAKE
set(PROJECT sealab)
set(BINARY ${PROJECT}.out)
set(SRC_DIR src/)
set(INC_DIR inc/)
FILE(GLOB_RECURSE SRC ${SRC_DIR}/*.cc)
# library include dirs
set(IMGUI_INC libs/imgui/)
set(SPDLOG_INC libs/spdlog/include/)
set(JSON_INC libs/json/include/)
set(
LIB_INC
${IMGUI_INC}
${SPDLOG_INC}
${JSON_INC}
${GLM_INC}
)
# library src files
FILE(GLOB IMGUI_SRC ${IMGUI_INC}*.cpp)
FILE(GLOB SPDLOG_SRC ${SPDLOG_INC}*.cpp)
set(
LIB_SRC
${IMGUI_SRC}
${SPDLOG_SRC}
)
project(${PROJECT})
# version number
set(${PROJECT}_VERSION_MAJOR 0)
set(${PROJECT}_VERSION_MINOR 1)
# Compilation Database
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# C++ standard
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-unused-local-typedefs")
# threads
set(THREADS_PREFER_PTHREAD_FLAG ON)
# adding packages
find_package(OpenGL REQUIRED)
find_package(GLEW REQUIRED)
find_package(glfw3 3.2 REQUIRED)
find_package(Threads REQUIRED)
find_package(Assimp REQUIRED)
find_package(glm REQUIRED)
find_package(Boost COMPONENTS system filesystem REQUIRED)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_STATIC_RUNTIME ON)
# adding directories and source files
include_directories(
${OPENGL_INCLUDE_DIRS}
${GLEW_INCLUDE_DIRS}
${ASSIMP_INCLUDE_DIRS}
${GLM_INCLUDE_DIRS}
${Boost_INCLUDE_DIRS}
)
include_directories(${INC_DIR} ${LIB_INC})
link_directories(${INC_DIR} ${LIB_INC})
# adding source files
add_executable(${BINARY} ${SRC} ${LIB_SRC})
set_target_properties(${BINARY} PROPERTIES COTIRE_UNITY_TARGET_NAME "unity")
# linking libraries
target_link_libraries(
${BINARY}
OpenGL::GL
${GLEW_LIBRARIES}
Threads::Threads
${ASSIMP_LIBRARIES}
glfw
glm
${Boost_LIBRARIES}
)
I'm using the command cmake -DCMAKE_C_COMPILER=$CC -DCMAKE_CXX_COMPILER=$CXX . to generate the Makefile, and the environment variables $CC and $CXX are set to the versions of gcc and g++ created by Homebrew.
I've looked at several other stackoverflow answers where people have the same error, and all of those are the result of incorrect linking. I'm linking in the same way that the correct answers say to do, yet the error still persists. Am I still linking it incorrectly or is there something else going on here?
So I found out what was going on. This made me realized that maybe the bottled homebrew Boost 1.66.0 library wasn't built with GCC. I switched the compiler to clang, and now it compiles just fine.
I'm tring to use CMS and cannot link libraries that i compiled on my linux. My CMakeLists.txt:
project(region_algorithm)
SET_TARGET_PROPERTIES(PROPERTIES LINKER_LANGUAGE CXX)
cmake_minimum_required(VERSION 2.8)
aux_source_directory(. SRC_LIST)
add_executable(${PROJECT_NAME} ${SRC_LIST})
INCLUDE_DIRECTORIES(
/usr/local/include/activemq-cpp-3.8.3
/usr/local/apr/include/apr-1)
link_libraries(
/usr/local/lib/libactivemq-cpp.a
/usr/local/apr/lib/libapr-1.a)
When i'm building project i got errors like:
regionalgorithmconsumer.cpp:-1: error: undefined reference to
`decaf::util::concurrent::CountDownLatch::CountDownLatch(int)'
I am trying to do some Google Tests on my application and I met some conflicts between OpenCV and GTest:
/usr/lib/gcc/i686-linux-gnu/4.6/../../../../lib/libgtest.a(gtest-all.cc.o): In function `testing::internal::GTestLog::GTestLog(testing::internal::GTestLogSeverity, char const*, int)':
gtest-all.cc:(.text+0xdd84): multiple definition of `testing::internal::GTestLog::GTestLog(testing::internal::GTestLogSeverity, char const*, int)'
/usr/local/lib/libopencv_ts.a(ts_gtest.cpp.o):ts_gtest.cpp:(.text._ZN7testing8internal8GTestLogC2ENS0_16GTestLogSeverityEPKci+0x0): first defined here
...
The GTest is used in opencv_ts library. Does anyone kows how to resolve these multiple deinitions?
I think that if I add just the libraries that I use from OpenCV it will be resolved, but I do not know how to do this. I have tried:
target_link_libraries(${Exec8name}_test ${OpenCV}/opencv_core.so* ... )
target_link_libraries(${Exec8name}_test ${OpenCV_LIBS}/opencv_core.so* ... )
target_link_libraries(${Exec8name}_test ${OpenCV_LIBS_DIR}/opencv_core.so* ... )
etc, but I get just errors of not found or No rule to make tarket
I have tried to remove one of the two, but I get errors of
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 0 has invalid symbol index 11
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 1 has invalid symbol index 12
...
This is my CMakeLists.txt
cmake_minimum_required(VERSION 2.8)
option(test "Build all tests." OFF)
set(EXECUTABLE_NAME MyProj)
project(${EXECUTABLE_NAME})
set(CMAKE_CXX_FLAGS "-g -Wall")
include_directories( src/main/cpp
${Boost_INCLUDE_DIRS}
)
find_package(OpenCV REQUIRED)
find_package(Boost REQUIRED COMPONENTS filesystem
system
regex
program_options)
add_executable(${EXECUTABLE_NAME}_Sol2
src/main/cpp/main.cpp
src/main/cpp/solution2/MySol2.hpp
src/main/cpp/solution2/MySol2.cpp
)
target_link_libraries(${EXECUTABLE_NAME}_Sol2 ${OpenCV_LIBS}
${Boost_LIBRARIES}
)
if (test)
find_package(GTest REQUIRED)
enable_testing()
include_directories( ${GTEST_INCLUDE_DIRS} )
add_executable(${EXECUTABLE_NAME}_Sol2_test
src/test/cpp/test_Sol2.cpp
src/main/cpp/solution2/MySol2.hpp
src/main/cpp/solution2/MySol2.cpp
)
target_link_libraries(${EXECUTABLE_NAME}_Sol2_test ${OpenCV_LIBRARIES}
${Boost_LIBRARIES}
)
target_link_libraries(${EXECUTABLE_NAME}_Sol2_test ${GTEST_LIBRARIES}
pthread
)
add_test(${EXECUTABLE_NAME}_Sol2_test
${CMAKE_CURRENT_BINARY_DIR}/${EXECUTABLE_NAME}_Sol2_test
)
endif()
Can anyone tell me some ways to fix it?
The "opencv_ts" module contains gtest, so you could just include the required OpenCV modules excluded "ts" module insted of all. For example:
find_package(OpenCV REQUIRED core imgproc highgui)
Add just the libs that I need like
target_link_libraries(${EXECUTABLE_NAME}_Sol2 opencv_core
opencv_highgui
opencv_imgproc
...
)