This question already has answers here:
CMake link to external library
(6 answers)
Closed 2 years ago.
I've just started to use CLion as my IDE after mainly using code::blocks on Linux for the last year or so. However I'm finding it really difficult to set up a project that worked and compiled fine in code::blocks because I just don't understand cmake yet.
Here's a quick description of my project - it consists of a main file that is calling a few header and source files, which all in the same directory. In the main file I'm also calling an external header file ("coupling.h", which is located in "/opt/package/API_SRC_Files/Coupling") which describes some classes relating to coupling to that software. The "coupling.h" file in turn references some files in "/opt/package/API_SRC_Files/Coupling". I also need to link to a shared library file "libcoupling.so" that is located in "/opt/package/lib".
Setting this up in code::blocks was pretty easy - just go to build options, and the respective paths to the search directories, and the path to the linked file and then build. Compiles in a few seconds.
I've tried to setup the project in CLion and CMake but I'm truly lost and I don't really understand why CMake is not finding the "coupling.h" file and throws countless "undefined reference to " errors. I'm sure I'll also have a problem setting up the shared library and I'm scared to even think about the difference in debug and release versions at the moment!
Here's my current CMake.txt file, hopefully someone can help. I'm using CLion 2020.1 on Fedora.
cmake_minimum_required(VERSION 3.16)
project(MBD VERSION 0.6.1)
set(CMAKE_CXX_STANDARD 14)
# add extra include directories
include_directories(.)
include_directories(/opt/package/API_SRC_Files)
include_directories(/opt/package/API_SRC_Files/Core)
include_directories(/opt/package/API_SRC_Files/Coupling)
set(PROJECT_HEADERS
coupling_utilities.h
geometry.h
io.h
shapelib.h
pid.h
spline.h
)
set(PROJECT_SOURCES
main.cpp
io.cpp
coupling_utilities.cpp
shapelib.cpp
pid.cpp
)
# add extra lib directories
link_directories(/opt/package/lib)
add_executable(MBD ${PROJECT_SOURCES} ${PROJECT_HEADERS})
Here's the error log from the output related to the include_directories():
/snap/clion/114/bin/cmake/linux/bin/cmake --build /home/user/CLionProjects/mbd/cmake-build-debug --target mbd -- -j 24
-- Configuring done
-- Generating done
-- Build files have been written to: /home/user/CLionProjects/mbd/cmake-build-debug
[ 16%] Linking CXX executable mbd
/usr/bin/ld: CMakeFiles/mbd.dir/main.cpp.o: in function `main':
/home/user/CLionProjects/mbd/main.cpp:224: undefined reference to `NApi::Coupling::getGeometryId(char const*, int&)'
/usr/bin/ld: /home/user/CLionProjects/mbd/main.cpp:260: undefined reference to `NApi::Coupling::getTimeStep(double&)'
/usr/bin/ld: /home/user/CLionProjects/mbd/main.cpp:268: undefined reference to `NApi::Coupling::getTime(double&)'
/usr/bin/ld: /home/user/CLionProjects/mbd/main.cpp:273: undefined reference to `NApi::Coupling::setTime(double const&)'
/usr/bin/ld: /home/user/CLionProjects/mbd/main.cpp:276: undefined reference to `NApi::Coupling::getTime(double&)'
/usr/bin/ld: /home/user/CLionProjects/mbd/main.cpp:285: undefined reference to `NApi::Coupling::setGridCellSize(double const&)'
/usr/bin/ld: /home/user/CLionProjects/mbd/main.cpp:288: undefined reference to `NApi::Coupling::setNumberOfCores(int const&)'
/usr/bin/ld: /home/user/CLionProjects/mbd/main.cpp:343: undefined reference to `NApi::Coupling::getGeometryPosition(int, NApi::C3dValue&, NApi::C3x3Matrix&)'
/usr/bin/ld: /home/user/CLionProjects/mbd/main.cpp:345: undefined reference to `NApi::Coupling::getGeometryTranslation(int, NApi::C3dValue&)'
/usr/bin/ld: /home/user/CLionProjects/mbd/main.cpp:348: undefined reference to `NApi::Coupling::getGeometryVelocity(int, NApi::C3dValue&, NApi::C3dValue&)'
/usr/bin/ld: /home/user/CLionProjects/mbd/main.cpp:442: undefined reference to `NApi::Coupling::isConnected() const'
/usr/bin/ld: /home/user/CLionProjects/mbd/main.cpp:444: undefined reference to `NApi::Coupling::getGeometryForces(int, NApi::C3dValue&, NApi::C3dValue&)'
/usr/bin/ld: /home/user/CLionProjects/mbd/main.cpp:531: undefined reference to `NApi::Coupling::isConnected() const'
/usr/bin/ld: /home/user/CLionProjects/mbd/main.cpp:534: undefined reference to `NApi::Coupling::setGeometryMotion(int, NApi::C3dValue const&, NApi::C3x3Matrix const&, NApi::C3dValue const&, NApi::C3dValue const&, double, bool)'
/usr/bin/ld: /home/user/CLionProjects/mbd/main.cpp:554: undefined reference to `NApi::Coupling::isConnected() const'
/usr/bin/ld: /home/user/CLionProjects/mbd/main.cpp:556: undefined reference to `NApi::Coupling::simulate(double const&, double)'
/usr/bin/ld: CMakeFiles/mbd.dir/main.cpp.o: in function `__static_initialization_and_destruction_0(int, int)':
/home/user/CLionProjects/mbd/main.cpp:74: undefined reference to `NApi::Coupling::ICoupling()'
/usr/bin/ld: /home/user/CLionProjects/mbd/main.cpp:74: undefined reference to `NApi::Coupling::~ICoupling()'
/usr/bin/ld: CMakeFiles/mbd.dir/coupling_utilities.cpp.o: in function `connect(NApi::Coupling&)':
/home/user/CLionProjects/mbd/coupling_utilities.cpp:54: undefined reference to `NApi::Coupling::initialiseCoupling()'
/usr/bin/ld: /home/user/CLionProjects/mbd/coupling_utilities.cpp:67: undefined reference to `NApi::Coupling::connectCoupling(bool, char const*)'
/usr/bin/ld: /home/user/CLionProjects/mbd/coupling_utilities.cpp:90: undefined reference to `NApi::Coupling::connectCoupling(bool, char const*)'
/usr/bin/ld: CMakeFiles/mbd.dir/coupling_utilities.cpp.o: in function `getResumeTimestep(NApi::Coupling&, double, double)':
/home/user/CLionProjects/mbd/coupling_utilities.cpp:109: undefined reference to `NApi::Coupling::getNumberOfTimesteps(unsigned int&)'
/usr/bin/ld: /home/user/CLionProjects/mbd/coupling_utilities.cpp:136: undefined reference to `NApi::Coupling::getTimesteps(double*, unsigned int&, unsigned int)'
collect2: error: ld returned 1 exit status
gmake[3]: *** [CMakeFiles/mbd.dir/build.make:144: mbd] Error 1
gmake[2]: *** [CMakeFiles/Makefile2:76: CMakeFiles/mbd.dir/all] Error 2
gmake[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/mbd.dir/rule] Error 2
gmake: *** [Makefile:118: mbd] Error 2
Here is how I would write the cmakelists.txt file:
cmake_minimum_required(VERSION 3.16)
project(MBD VERSION 0.6.1)
set(CMAKE_CXX_STANDARD 14)
set(API_SRC_Files /opt/package/API_SRC_Files) # ${API_SRC_Files}
set(SRC_FILES
main.cpp
coupling_utilities.h coupling_utilities.cpp
geometry.h
io.h io.cpp
pid.h pid.cpp
shapelib.h shapelib.cpp
spline.h
)
# add extra include directories
include_directories(
includes
.
${API_SRC_Files}
${API_SRC_Files}/Core
${API_SRC_Files}/Coupling
)
# add extra lib directories
link_directories(/opt/package/lib)
add_executable(${PROJECT_NAME} ${SRC_FILES})
Use something like the API_SRC_Files variable for two reasons: reduces errors from having to repeat the same path information, makes it easier if the library is ever moved to a new location. The same thing with using the PROJECT_NAME variable. The comment is to remind myself how to utilize the variable later on in the file.
Combine your SRC_FILES and SRC_HEADERS into one array with source and matching header on the same line. This helps to make sure both are listed. Please note when you tell Clion you want to add a new C++ Class, it will be in the form class.cpp class.h, and not alphabetized. I always list the main.cpp, first.
The dot, ., in the include_directories may or may not be necessary.
Hope this helps.
Related
I'm developing a dynamic C++17 library that uses SQLite. It's a CMake project and the requirement for it to be dynamic comes because I plan to mainly use the library through JNI.
So, in my project I build SQLite as a static library:
add_library(sqlite3 STATIC "${sqlite3_SOURCE_DIR}/sqlite3.c") # STATIC to efficiently link to SHARED main library
set_target_properties(sqlite3 PROPERTIES POSITION_INDEPENDENT_CODE ON) # Required to link STATIC to SHARED
target_include_directories(sqlite3 PUBLIC "${sqlite3_SOURCE_DIR}")
And my main library as shared:
add_library(${PROJECT_NAME} SHARED <library sources>)
target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_17)
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) # To include headers without using relative paths
target_link_libraries(${PROJECT_NAME} PRIVATE sqlite3)
Then if I link my library to some executable like this it builds and runs absolutely fine on my PC:
add_executable(app <app's sources>)
target_compile_features(app PUBLIC cxx_std_17)
target_include_directories(app PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} <main library src dir>) # Including the main library like this is a temporary solution, because there is no separate include dir yet
target_link_libraries(app PUBLIC ${PROJECT_NAME})
But when I try to build it in GitHub Actions I get these errors:
[100%] Linking CXX executable app
/usr/bin/ld: ../src/mylib.so: undefined reference to `pthread_mutexattr_destroy'
/usr/bin/ld: ../src/mylib.so: undefined reference to `pthread_create'
/usr/bin/ld: ../src/mylib.so: undefined reference to `dlopen'
/usr/bin/ld: ../src/mylib.so: undefined reference to `pthread_mutex_trylock'
/usr/bin/ld: ../src/mylib.so: undefined reference to `dlclose'
/usr/bin/ld: ../src/mylib.so: undefined reference to `dlerror'
/usr/bin/ld: ../src/mylib.so: undefined reference to `dlsym'
/usr/bin/ld: ../src/mylib.so: undefined reference to `pthread_mutexattr_settype'
/usr/bin/ld: ../src/mylib.so: undefined reference to `pthread_join'
/usr/bin/ld: ../src/mylib.so: undefined reference to `pthread_mutexattr_init'
collect2: error: ld returned 1 exit status
I can fix it by linking the library target to ${CMAKE_DL_LIBS} and Threads::Threads, but I'm not sure if I'm doing what should be done and not just silencing some other mistakes of mine.
To be clear, I don't use any of the functions mentioned in the errors above in the code of my library.
The questions are:
Why does the original code work on my PC and doesn't on GitHub Actions?
Is what I did the right way to fix this?
I'm building the project locally on Ubuntu 22.04 (WSL) with a compiler identified as GNU 11.3.0, while GitHub Actions runs Ubuntu 20.04 using GNU 9.4.0 compiler.
I'm fairly new to C++ / CMake, but I'd like to create a project with FLTK using CMAKE and CONAN as package manager. I'm using Windows 11, but trying to get it to run under WSL (Ubuntu 20.04). My WSL-version supports GUI applications.
When I install everything without Conan and compile the official "fltk-hello-world" from the command line using fltk-config, everything works okay. However, when I try to set it up using Conan und Cmake I get following errors:
/usr/bin/ld: /home/bfl/.conan/data/fltk/1.3.8/_/_/package/b6898709771003e31b8ea824ee836cf119580bd8/lib/libfltk.a(fl_font.cxx.o): in function `Fl_Font_Descriptor::Fl_Font_Descriptor(char const*, int, int)':
fl_font.cxx:(.text+0x232): undefined reference to `XftFontOpenXlfd'
/usr/bin/ld: fl_font.cxx:(.text+0x47e): undefined reference to `XftFontMatch'
/usr/bin/ld: fl_font.cxx:(.text+0x48f): undefined reference to `XftFontOpenPattern'
/usr/bin/ld: fl_font.cxx:(.text+0x4e1): undefined reference to `XftFontOpen'
/usr/bin/ld: /home/bfl/.conan/data/fltk/1.3.8/_/_/package/b6898709771003e31b8ea824ee836cf119580bd8/lib/libfltk.a(fl_font.cxx.o): in function `Fl_Xlib_Graphics_Driver::width(char const*, int)':
fl_font.cxx:(.text+0x954): undefined reference to `XftTextExtents32'
/usr/bin/ld: /home/bfl/.conan/data/fltk/1.3.8/_/_/package/b6898709771003e31b8ea824ee836cf119580bd8/lib/libfltk.a(fl_font.cxx.o): in function `Fl_Xlib_Graphics_Driver::width(unsigned int)':
fl_font.cxx:(.text+0xa5e): undefined reference to `XftTextExtents32'
/usr/bin/ld: /home/bfl/.conan/data/fltk/1.3.8/_/_/package/b6898709771003e31b8ea824ee836cf119580bd8/lib/libfltk.a(fl_font.cxx.o): in function `Fl_Xlib_Graphics_Driver::text_extents(char const*, int, int&, int&, int&, int&)':
fl_font.cxx:(.text+0xb07): undefined reference to `XftTextExtents32'
/usr/bin/ld: /home/bfl/.conan/data/fltk/1.3.8/_/_/package/b6898709771003e31b8ea824ee836cf119580bd8/lib/libfltk.a(fl_font.cxx.o): in function `Fl_Xlib_Graphics_Driver::draw(char const*, int, int, int)':
fl_font.cxx:(.text+0x1140): undefined reference to `XftDrawChange'
/usr/bin/ld: fl_font.cxx:(.text+0x1176): undefined reference to `XftDrawSetClip'
/usr/bin/ld: fl_font.cxx:(.text+0x1209): undefined reference to `XftDrawString32'
/usr/bin/ld: fl_font.cxx:(.text+0x12d9): undefined reference to `XftDrawCreate'
/usr/bin/ld: /home/bfl/.conan/data/fltk/1.3.8/_/_/package/b6898709771003e31b8ea824ee836cf119580bd8/lib/libfltk.a(fl_font.cxx.o): in function `Fl_Xlib_Graphics_Driver::rtl_draw(char const*, int, int, int)':
fl_font.cxx:(.text+0x149b): undefined reference to `XftTextExtents32'
/usr/bin/ld: fl_font.cxx:(.text+0x14cc): undefined reference to `XftDrawChange'
/usr/bin/ld: fl_font.cxx:(.text+0x1502): undefined reference to `XftDrawSetClip'
/usr/bin/ld: fl_font.cxx:(.text+0x1595): undefined reference to `XftDrawString32'
/usr/bin/ld: fl_font.cxx:(.text+0x15f9): undefined reference to `XftDrawCreate'
/usr/bin/ld: /home/bfl/.conan/data/fltk/1.3.8/_/_/package/b6898709771003e31b8ea824ee836cf119580bd8/lib/libfltk.a(fl_font.cxx.o): in function `fl_destroy_xft_draw(unsigned long)':
fl_font.cxx:(.text+0x10d9): undefined reference to `XftDrawChange'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/hello.dir/build.make:84: bin/hello] Error 1
make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/hello.dir/all] Error 2
make: *** [Makefile:84: all] Error 2
So I assume that i am probably not linking XFT? But I am not sure how to do that, do I need to include the correct name in target-link-libraries? My Cmake-File looks like this:
cmake_minimum_required(VERSION 3.2.3)
project(Hello VERSION 0.1.0)
set(EXECUTABLE_NAME hello)
set(EXE_SOURCES hello.cc)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
add_executable(${EXECUTABLE_NAME} ${EXE_SOURCES})
target_include_directories(hello PUBLIC ${FLTK_INCLUDE_DIRS})
target_link_libraries(hello
${CONAN_LIBS})
I'm grateful for any suggestion.
Thanks,
GB
The conan recipe for fltk does not correctly deal with the cmake system of fltk.
Fltk auto-detects if the system it compiles on has Xft. If it does, then it enables the HAS_XFT variable and compiles some code into the library that uses it.
Conan does not pick up on this and doesn't add Xft to the dependent libraries.
The easiest way around this bug is to manually add the xft dependency.
If you have libXft installed on your system you can simply add an entry of Xft to the target_link_libraries of the target that uses fltk.
Like this:
target_link_libraries(hello ${CONAN_LIBS} Xft)
I have used boost/json inside my C++ project which I have created under windows. There the dependency was installed with vcpkg (vcpkg.exe install boost-json). Now I want to port this project to Ubuntu. But I have no clue how to install the library under Linux. Probably this is obvious to a C++ veteran but I couldn't get it to work. I can't find any hints in the git project or on the official website.
I have already tried:
using CMake to build and install the library
including the code via add_library in my CMakeLists.txt
Using it as header-only by copying only the include folder
What is the best practice to include such a library in a project and what are the steps to achieve it? Is there a tutorial for such tasks? My biggest problem is, I don`t know what to google for.
I hope someone can help me, thank you in advance.
EDIT:
As proposed by #vre, I built boost 1.78.0 from source. CMake finds now the boost version with version 1.78.0 and the include error is gone. Nevertheless it is still not working as the linking under Linux is failing. The following output I get:
/usr/bin/ld: CMakeFiles/Server.dir/main.cpp.o: in function `parse_server_config_json(std::filesystem::__cxx11::path)':
main.cpp:(.text+0x511): undefined reference to `boost::json::parse(boost::basic_string_view<char, std::char_traits<char> >, boost::json::storage_ptr, boost::json::parse_options const&)'
/usr/bin/ld: main.cpp:(.text+0x544): undefined reference to `boost::json::value::~value()'
/usr/bin/ld: main.cpp:(.text+0x589): undefined reference to `boost::json::object::operator[](boost::basic_string_view<char, std::char_traits<char> >)'
/usr/bin/ld: main.cpp:(.text+0x5d0): undefined reference to `boost::json::object::operator[](boost::basic_string_view<char, std::char_traits<char> >)'
/usr/bin/ld: main.cpp:(.text+0x615): undefined reference to `boost::json::object::operator[](boost::basic_string_view<char, std::char_traits<char> >)'
/usr/bin/ld: main.cpp:(.text+0x662): undefined reference to `boost::json::object::operator[](boost::basic_string_view<char, std::char_traits<char> >)'
/usr/bin/ld: main.cpp:(.text+0x6af): undefined reference to `boost::json::object::operator[](boost::basic_string_view<char, std::char_traits<char> >)'
/usr/bin/ld: CMakeFiles/Server.dir/main.cpp.o:main.cpp:(.text+0x758): more undefined references to `boost::json::object::operator[](boost::basic_string_view<char, std::char_traits<char> >)' follow
/usr/bin/ld: CMakeFiles/Server.dir/main.cpp.o: in function `parse_server_config_json(std::filesystem::__cxx11::path)':
main.cpp:(.text+0xb46): undefined reference to `boost::json::object::~object()'
/usr/bin/ld: main.cpp:(.text+0xbb4): undefined reference to `boost::json::value::~value()'
/usr/bin/ld: main.cpp:(.text+0xd4f): undefined reference to `boost::json::object::~object()'
/usr/bin/ld: CMakeFiles/Server.dir/main.cpp.o: in function `boost::json::object::object(boost::json::object const&)':
main.cpp:(.text._ZN5boost4json6objectC2ERKS1_[_ZN5boost4json6objectC5ERKS1_]+0x4a): undefined reference to `boost::json::object::object(boost::json::object const&, boost::json::storage_ptr)'
/usr/bin/ld: CMakeFiles/Server.dir/main.cpp.o: in function `boost::json::value::as_object()':
main.cpp:(.text._ZN5boost4json5value9as_objectEv[_ZN5boost4json5value9as_objectEv]+0x66): undefined reference to `boost::json::detail::throw_invalid_argument(char const*, boost::source_location const&)'
/usr/bin/ld: CMakeFiles/Server.dir/main.cpp.o: in function `boost::json::value::as_array()':
main.cpp:(.text._ZN5boost4json5value8as_arrayEv[_ZN5boost4json5value8as_arrayEv]+0x66): undefined reference to `boost::json::detail::throw_invalid_argument(char const*, boost::source_location const&)'
/usr/bin/ld: CMakeFiles/Server.dir/main.cpp.o: in function `boost::json::value::as_string() const':
main.cpp:(.text._ZNK5boost4json5value9as_stringEv[_ZNK5boost4json5value9as_stringEv]+0x66): undefined reference to `boost::json::detail::throw_invalid_argument(char const*, boost::source_location const&)'
/usr/bin/ld: CMakeFiles/Server.dir/main.cpp.o: in function `boost::json::value::as_int64()':
main.cpp:(.text._ZN5boost4json5value8as_int64Ev[_ZN5boost4json5value8as_int64Ev]+0x66): undefined reference to `boost::json::detail::throw_invalid_argument(char const*, boost::source_location const&)'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/Server.dir/build.make:102: Server] Error 1
make[1]: *** [CMakeFiles/Makefile2:140: CMakeFiles/Server.dir/all] Error 2
make: *** [Makefile:84: all] Error 2
I also added as mentioned by #GP8:
find_package(
Boost 1.78 REQUIRED
COMPONENTS json
)
Edit2:
I forgot to link boost-json. After adding the following to my CMakeLists.txt the build was successfull under linux:
target_link_libraries(${PROJECT_NAME}
Boost::boost
Boost::json
)
You should first install boost using the following command : sudo apt-get install libboost-all-dev
To get Boost libraries included in your project you must find the package this way :
find_package(
Boost 1.65 REQUIRED
COMPONENTS json
)
You can then, tell CMake to with which file to create your executable and against which libraries to link :
add_execublable( anyExecutable main.cpp )
target_link_libraries( exeLINK_PUBLIC ${Boost_LIBRARIES})
#GPB outlines the general procedure.
If your CMake/FindBoost doesn't support Boost Json yet, the simplest thing to do is to
#include <boost/json/src.hpp>
in exactly 1 (one) translation unit that participates in your linked binary.
See Header Only
I have been trying very hard to set up OpenVINO for my C++ programme. But the official guide was very unclear to me (partially because I am a very beginner). I was struggling to understand how it finds "InferenceEngine_LIBRARIES" (or "OpenCV_LIBS") without even defining it.
I have tried to understand some examples in GitHub but sadly many of them are for older versions. I was wondering if I could have a minimum demo of the CMakeLists.txt to use the OpenVINO. Thank you very much.
--- Updates ---
Thanks for the comments. I understand some things were handled by CMake behind the scene. Going to the point, here is my CMakeLists file
cmake_minimum_required(VERSION 3.21)
project(openvino)
set(CMAKE_CXX_STANDARD 14)
# OpenVINO
set(ngraph_DIR "/opt/intel/openvino_2021/deployment_tools/ngraph/cmake")
find_package(ngraph REQUIRED)
set(InferenceEngine_DIR "/opt/intel/openvino_2021/deployment_tools/inference_engine/share")
find_package(InferenceEngine REQUIRED)
set(OpenCV_DIR "/opt/intel/openvino_2021/opencv/cmake")
find_package(OpenCV REQUIRED)
add_executable(openvino main.cpp)
target_link_libraries(
${PROJECT_NAME}
PRIVATE ${InferenceEngine_LIBRARIES}
${OpenCV_LIBS}
${NGRAPH_LIBRARIES})
And my "main.cpp" is just
#include <inference_engine.hpp>
int main() {
InferenceEngine::Core core;
InferenceEngine::ExecutableNetwork executable_network;
executable_network = core.LoadNetwork("./models/decoder.xml", "CPU");
auto infer_request = executable_network.CreateInferRequest();
return 0;
}
But When I build it, I got the following error, and I would like to ask for any help. Thank you very much!
====================[ Build | openvino | Debug ]================================
/home/kent/.local/share/JetBrains/Toolbox/apps/CLion/ch-0/213.6777.58/bin/cmake/linux/bin/cmake --build /media/kent/DISK2/CLionProjects/openvino/cmake-build-debug --target openvino
[2/2] Linking CXX executable openvino
FAILED: openvino
: && /usr/bin/c++ -g CMakeFiles/openvino.dir/main.cpp.o -o openvino -Wl,-rpath,/opt/intel/openvino_2021/opencv/lib:/opt/intel/openvino_2021/deployment_tools/inference_engine/lib/intel64:/opt/intel/openvino_2021/deployment_tools/ngraph/lib /opt/intel/openvino_2021/opencv/lib/libopencv_gapi.so.4.5.3 /opt/intel/openvino_2021/opencv/lib/libopencv_highgui.so.4.5.3 /opt/intel/openvino_2021/opencv/lib/libopencv_ml.so.4.5.3 /opt/intel/openvino_2021/opencv/lib/libopencv_objdetect.so.4.5.3 /opt/intel/openvino_2021/opencv/lib/libopencv_photo.so.4.5.3 /opt/intel/openvino_2021/opencv/lib/libopencv_stitching.so.4.5.3 /opt/intel/openvino_2021/opencv/lib/libopencv_video.so.4.5.3 /opt/intel/openvino_2021/opencv/lib/libopencv_videoio.so.4.5.3 /opt/intel/openvino_2021/opencv/lib/libopencv_dnn.so.4.5.3 /opt/intel/openvino_2021/deployment_tools/inference_engine/lib/intel64/libinference_engine.so /opt/intel/openvino_2021/deployment_tools/inference_engine/lib/intel64/libinference_engine_c_api.so /opt/intel/openvino_2021/deployment_tools/ngraph/lib/libngraph.so /opt/intel/openvino_2021/opencv/lib/libopencv_imgcodecs.so.4.5.3 /opt/intel/openvino_2021/opencv/lib/libopencv_calib3d.so.4.5.3 /opt/intel/openvino_2021/opencv/lib/libopencv_features2d.so.4.5.3 /opt/intel/openvino_2021/opencv/lib/libopencv_flann.so.4.5.3 /opt/intel/openvino_2021/opencv/lib/libopencv_imgproc.so.4.5.3 /opt/intel/openvino_2021/opencv/lib/libopencv_core.so.4.5.3 && :
/usr/bin/ld: warning: libtbb.so.2, needed by /opt/intel/openvino_2021/deployment_tools/inference_engine/lib/intel64/libinference_engine.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: /opt/intel/openvino_2021/deployment_tools/inference_engine/lib/intel64/libinference_engine.so: undefined reference to `tbb::interface7::internal::task_arena_base::internal_max_concurrency(tbb::interface7::task_arena const*)'
/usr/bin/ld: /opt/intel/openvino_2021/deployment_tools/inference_engine/lib/intel64/libinference_engine.so: undefined reference to `tbb::interface7::internal::task_arena_base::internal_initialize()'
/usr/bin/ld: /opt/intel/openvino_2021/deployment_tools/inference_engine/lib/intel64/libinference_engine.so: undefined reference to `tbb::internal::task_scheduler_observer_v3::observe(bool)'
/usr/bin/ld: /opt/intel/openvino_2021/deployment_tools/inference_engine/lib/intel64/libinference_engine.so: undefined reference to `tbb::internal::concurrent_vector_base_v3::internal_grow_by(unsigned long, unsigned long, void (*)(void*, void const*, unsigned long), void const*)'
/usr/bin/ld: /opt/intel/openvino_2021/deployment_tools/inference_engine/lib/intel64/libinference_engine.so: undefined reference to `tbb::internal::concurrent_vector_base_v3::~concurrent_vector_base_v3()'
/usr/bin/ld: /opt/intel/openvino_2021/deployment_tools/inference_engine/lib/intel64/libinference_engine.so: undefined reference to `tbb::internal::NFS_Allocate(unsigned long, unsigned long, void*)'
/usr/bin/ld: /opt/intel/openvino_2021/deployment_tools/inference_engine/lib/intel64/libinference_engine.so: undefined reference to `tbb::internal::concurrent_vector_base_v3::internal_clear(void (*)(void*, unsigned long))'
/usr/bin/ld: /opt/intel/openvino_2021/deployment_tools/inference_engine/lib/intel64/libinference_engine.so: undefined reference to `tbb::interface7::internal::task_arena_base::internal_current_slot()'
/usr/bin/ld: /opt/intel/openvino_2021/deployment_tools/inference_engine/lib/intel64/libinference_engine.so: undefined reference to `tbb::internal::allocate_via_handler_v3(unsigned long)'
/usr/bin/ld: /opt/intel/openvino_2021/deployment_tools/inference_engine/lib/intel64/libinference_engine.so: undefined reference to `tbb::interface7::internal::task_arena_base::internal_execute(tbb::interface7::internal::delegate_base&) const'
/usr/bin/ld: /opt/intel/openvino_2021/deployment_tools/inference_engine/lib/intel64/libinference_engine.so: undefined reference to `tbb::interface7::internal::task_arena_base::internal_terminate()'
/usr/bin/ld: /opt/intel/openvino_2021/deployment_tools/inference_engine/lib/intel64/libinference_engine.so: undefined reference to `tbb::internal::NFS_Free(void*)'
/usr/bin/ld: /opt/intel/openvino_2021/deployment_tools/inference_engine/lib/intel64/libinference_engine.so: undefined reference to `tbb::internal::thread_get_id_v3()'
/usr/bin/ld: /opt/intel/openvino_2021/deployment_tools/inference_engine/lib/intel64/libinference_engine.so: undefined reference to `tbb::internal::deallocate_via_handler_v3(void*)'
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
The linker error shows that it cannot find the TBB symbols. The TBB library should be pointed to by the TBB_DIR variable. You don't have to set those variables manually using cmake's set() function. Instead - in the shell where you compile your own app - you can source OpenVINO's setupvars.sh script. Just run something like: source /opt/intel/openvino_2021/bin/setupvars.sh and re-run the compiler.
I can see you're using CLion, not the terminal directly. In that case you can try adding the variable manually. The TBB location might be slightly different between the OV versions but in general it should point to a subdirectory of /opt/intel/openvino_2021 - just browse the installation directory and try to find it or source setupvars.sh in the terminal and copy the TBB_DIR env var value to your IDE.
I am trying to build my project using CMake but I am having error linking required libraries. I have this CMakeLists.txt in the root folder of my project:
cmake_minimum_required(VERSION 2.6)
project(test)
add_subdirectory(src)
And in my src folder, alongside my source files I have this CMakeLists.txt:
set (CMAKE_CXX_FLAGS "Wall -std=c++11" )
set (CMAKE_EXE_LINKER_FLAGS "-lSDL2 -lGL" )
file (GLOB SRCS *.cpp *.h )
add_executable(engine ${SRCS} )
I then go into the build folder and do cmake .. and it runs without any errors. When I do make, the compilation runs without any errors as well, but when it gets to the linking part, I get these errors:
CMakeFiles/test.dir/Application.cpp.o: In function `Application::onExecute()':
Application.cpp:(.text+0x41): undefined reference to `SDL_GetTicks'
Application.cpp:(.text+0x4e): undefined reference to `SDL_GetTicks'
Application.cpp:(.text+0xd7): undefined reference to `SDL_PollEvent'
CMakeFiles/test.dir/Application.cpp.o: In function `Application::render()':
Application.cpp:(.text+0x17b): undefined reference to `glClearColor'
Application.cpp:(.text+0x185): undefined reference to `glClear'
Application.cpp:(.text+0x194): undefined reference to `SDL_GL_SwapWindow'
CMakeFiles/test.dir/Application.cpp.o: In function `Application::cleanUp()':
Application.cpp:(.text+0x1b2): undefined reference to `SDL_GL_DeleteContext'
Application.cpp:(.text+0x1c1): undefined reference to `SDL_DestroyWindow'
Application.cpp:(.text+0x1c6): undefined reference to `SDL_Quit'
CMakeFiles/test.dir/Application.cpp.o: In function `Application::initialize()':
Application.cpp:(.text+0x1de): undefined reference to `SDL_Init'
Application.cpp:(.text+0x1ea): undefined reference to `SDL_GetError'
Application.cpp:(.text+0x22b): undefined reference to `SDL_CreateWindow'
Application.cpp:(.text+0x243): undefined reference to `SDL_GetError'
Application.cpp:(.text+0x25a): undefined reference to `SDL_Quit'
Application.cpp:(.text+0x270): undefined reference to `SDL_GL_SetAttribute'
Application.cpp:(.text+0x27f): undefined reference to `SDL_GL_SetAttribute'
Application.cpp:(.text+0x28e): undefined reference to `SDL_GL_SetAttribute'
Application.cpp:(.text+0x29d): undefined reference to `SDL_GL_CreateContext'
Application.cpp:(.text+0x2af): undefined reference to `glGetString'
collect2: error: ld returned 1 exit status
make[2]: *** [src/test] Error 1
make[1]: *** [src/CMakeFiles/test.dir/all] Error 2
make: *** [all] Error 2
I have the correct includes in my header files and I was able to compile and run using only make so I think the linker flags I tell CMake aren't being passed to the compiler. How can I fix this?
You have to use the cmake command target_link_libraries to reference SDL libs.