Linking boost_numpy3 with CMAKE - c++

TL;DR When updating from CMake 3.10 to CMake 3.11.1 on archlinux, the following configuration line:
find_package(Boost COMPONENTS python3 COMPONENTS numpy3 REQUIRED)
leads to CMake linking against 3 different libraries
-- Boost version: 1.66.0
-- Found the following Boost libraries:
-- python3
-- numpy3
-- python
instead of the previous behaviour:
-- Boost version: 1.66.0
-- Found the following Boost libraries:
-- python3
-- numpy3
resulting in a linker error.
I use CMake to build a piece of software that relies on Boost python, and, since a couple of days ago, it seems that the line
find_package(Boost COMPONENTS numpy3 REQUIRED)
is no longer sufficient for CMake to understand that it should link the program against the Boost python3 library, and it uses the Boost library python instead.
Here is a minimal working example to reproduce what I am talking about.
test.cpp
#include <iostream>
using namespace std;
int main()
{
cout << "Hello, world!" << endl;
}
CMakeList.txt
set(CMAKE_VERBOSE_MAKEFILE ON)
find_package(PythonLibs 3 REQUIRED)
find_package(Boost COMPONENTS numpy3 REQUIRED)
add_executable (test test.cpp)
target_link_libraries(test ${Boost_LIBRARIES} ${PYTHON_LIBRARIES})
With this configuration of CMake, a linker error will occur, and the error persists when I change the line adding numpy to
find_package(Boost COMPONENTS python3 COMPONENTS numpy3 REQUIRED)
Here is the result of cmake . && make:
/home/rastapopoulos/test $ cmake .
-- Boost version: 1.66.0
-- Found the following Boost libraries:
-- numpy3
-- python
CMake Warning (dev) in CMakeLists.txt:
No cmake_minimum_required command is present. A line of code such as
cmake_minimum_required(VERSION 3.11)
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: /home/rastapopoulos/test
/home/rastapopoulos/test $ make
/usr/bin/cmake -H/home/rastapopoulos/test -B/home/rastapopoulos/test --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/cmake -E cmake_progress_start /home/rastapopoulos/test/CMakeFiles /home/rastapopoulos/test/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory '/home/rastapopoulos/test'
make -f CMakeFiles/test.dir/build.make CMakeFiles/test.dir/depend
make[2]: Entering directory '/home/rastapopoulos/test'
cd /home/rastapopoulos/test && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/rastapopoulos/test /home/rastapopoulos/test /home/rastapopoulos/test /home/rastapopoulos/test /home/rastapopoulos/test/CMakeFi
les/test.dir/DependInfo.cmake --color=
make[2]: Leaving directory '/home/rastapopoulos/test'
make -f CMakeFiles/test.dir/build.make CMakeFiles/test.dir/build
make[2]: Entering directory '/home/rastapopoulos/test'
[ 50%] Linking CXX executable test
/usr/bin/cmake -E cmake_link_script CMakeFiles/test.dir/link.txt --verbose=1
/usr/bin/c++ -rdynamic CMakeFiles/test.dir/test.o -o test -lboost_numpy3 -lboost_python -lpython3.6m
/usr/lib/gcc/x86_64-pc-linux-gnu/7.3.1/../../../../lib/libboost_python.so: undefined reference to `PyString_Size'
/usr/lib/gcc/x86_64-pc-linux-gnu/7.3.1/../../../../lib/libboost_python.so: undefined reference to `PyUnicodeUCS4_FromEncodedObject'
/usr/lib/gcc/x86_64-pc-linux-gnu/7.3.1/../../../../lib/libboost_python.so: undefined reference to `PyFile_FromString'
/usr/lib/gcc/x86_64-pc-linux-gnu/7.3.1/../../../../lib/libboost_python.so: undefined reference to `PyString_Type'
/usr/lib/gcc/x86_64-pc-linux-gnu/7.3.1/../../../../lib/libboost_python.so: undefined reference to `PyInt_Type'
/usr/lib/gcc/x86_64-pc-linux-gnu/7.3.1/../../../../lib/libboost_python.so: undefined reference to `PyString_FromString'
/usr/lib/gcc/x86_64-pc-linux-gnu/7.3.1/../../../../lib/libboost_python.so: undefined reference to `PyUnicodeUCS4_AsWideChar'
/usr/lib/gcc/x86_64-pc-linux-gnu/7.3.1/../../../../lib/libboost_python.so: undefined reference to `PyString_FromStringAndSize'
/usr/lib/gcc/x86_64-pc-linux-gnu/7.3.1/../../../../lib/libboost_python.so: undefined reference to `Py_InitModule4_64'
/usr/lib/gcc/x86_64-pc-linux-gnu/7.3.1/../../../../lib/libboost_python.so: undefined reference to `PyString_FromFormat'
/usr/lib/gcc/x86_64-pc-linux-gnu/7.3.1/../../../../lib/libboost_python.so: undefined reference to `PyNumber_Divide'
/usr/lib/gcc/x86_64-pc-linux-gnu/7.3.1/../../../../lib/libboost_python.so: undefined reference to `PyNumber_InPlaceDivide'
/usr/lib/gcc/x86_64-pc-linux-gnu/7.3.1/../../../../lib/libboost_python.so: undefined reference to `PyInt_AsLong'
/usr/lib/gcc/x86_64-pc-linux-gnu/7.3.1/../../../../lib/libboost_python.so: undefined reference to `PyString_InternFromString'
/usr/lib/gcc/x86_64-pc-linux-gnu/7.3.1/../../../../lib/libboost_python.so: undefined reference to `PyClass_Type'
/usr/lib/gcc/x86_64-pc-linux-gnu/7.3.1/../../../../lib/libboost_python.so: undefined reference to `PyString_AsString'
/usr/lib/gcc/x86_64-pc-linux-gnu/7.3.1/../../../../lib/libboost_python.so: undefined reference to `PyInt_FromLong'
/usr/lib/gcc/x86_64-pc-linux-gnu/7.3.1/../../../../lib/libboost_python.so: undefined reference to `PyFile_AsFile'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/test.dir/build.make:90: test] Error 1
make[2]: Leaving directory '/home/rastapopoulos/test'
make[1]: *** [CMakeFiles/Makefile2:71: CMakeFiles/test.dir/all] Error 2
make[1]: Leaving directory '/home/rastapopoulos/test'
make: *** [Makefile:87: all] Error 2
Has anyone experienced a similar problem and managed to solve it? I use cmake 3.11.1, boost 1.66.0-2, and run an updated version of Archlinux.

This bug is due to an invalid dependency description in FindBoost.cmake
set(_Boost_NUMPY_DEPENDENCIES python)
This has been fixed at https://github.com/Kitware/CMake/commit/c747d4ccb349f87963a8d1da69394bc4db6b74ed
Please use latest one, or you can rewrite it manually:
set(_Boost_NUMPY_DEPENDENCIES python${component_python_version})

CMake 3.10 does not properly support Boost 1.66. The Boost dependencies are hard-coded and if they chance, CMake has to adopt.
Delete the build directory and reconfigure. The configure step uses cached variables which prevents re-detection with the newer routines.

Related

C++ Tensorflow lite, undefined reference on some functions

I'm trying to build and run a project using tensorflow lite on my debian 11 intel x86_64 architecture. So far I've followed the official documentation and the official github example.
Here are the steps I've followed:
On ~/Desktop/ I ran git clone https://github.com/tensorflow/tensorflow.git tensorflow_src
mkdir tflite_build & cd ~/Desktop/tflite_build
cmake ../tensorflow_src/tensorflow/lite
cmake --build . I've removed the -J flag regardless of what the docs says because it causes my pc to freeze.
mkdir ~/Desktop/tf_test & cd ~/Desktop/tf_test
Create a CMakeLists.txt and a main.cpp file inside tf_testdirectory.
Put the main code from the minimal example on the github repo provided above then this code in CMake:
cmake_minimum_required(VERSION 3.16)
project(minimal C CXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DTFLITE_DISABLE_TELEMETRY=1")
set(TENSORFLOW_SOURCE_DIR "" CACHE PATH
"Directory that contains the TensorFlow project" )
if(NOT TENSORFLOW_SOURCE_DIR)
get_filename_component(TENSORFLOW_SOURCE_DIR
"/home/user/Desktop/tensorflow_src" ABSOLUTE)
endif()
add_subdirectory(
"${TENSORFLOW_SOURCE_DIR}/tensorflow/lite"
"${CMAKE_CURRENT_BINARY_DIR}/tensorflow-lite" EXCLUDE_FROM_ALL)
add_executable(minimal minimal.cc)
target_link_libraries(minimal tensorflow-lite)
Created the folder tf_Test/build and ran cmake .. inside it.
After cmake is completed I run make inside the build directory and I'm getting the following error:
...
[100%] Linking CXX executable minimal
/usr/bin/ld: tensorflow-lite/libtensorflow-lite.a(interpreter.cc.o): in function `tflite::impl::Interpreter::ReportTelemetrySettings(char const*)':
interpreter.cc:(.text+0x292f): undefined reference to `tflite::telemetry::TelemetryReportSettings(TfLiteContext*, char const*, TfLiteTelemetryInterpreterSettings const*)'
/usr/bin/ld: tensorflow-lite/libtensorflow-lite.a(subgraph.cc.o): in function `tflite::Subgraph::Invoke()':
subgraph.cc:(.text+0x41c0): undefined reference to `tflite::telemetry::TelemetryReportEvent(TfLiteContext*, char const*, TfLiteStatus)'
/usr/bin/ld: tensorflow-lite/libtensorflow-lite.a(subgraph.cc.o): in function `tflite::Subgraph::ModifyGraphWithDelegate(TfLiteDelegate*)':
subgraph.cc:(.text+0x6ad0): undefined reference to `tflite::telemetry::TelemetryReportEvent(TfLiteContext*, char const*, TfLiteStatus)'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/minimal.dir/build.make:184: minimal] Error 1
make[1]: *** [CMakeFiles/Makefile2:1408: CMakeFiles/minimal.dir/all] Error 2
make: *** [Makefile:149: all] Error 2
Notice that it's not saying this for all the functions. For example this works std::unique_ptr<tflite::FlatBufferModel> model = tflite::FlatBufferModel::BuildFromFile(filename); without errors.
These tree are causing trouble: tflite::ops::builtin::BuiltinOpResolver resolver; std::unique_ptr<tflite::Interpreter> interpreter; tflite::InterpreterBuilder(*model, resolver)(&interpreter);
Note: I've trimmed some code compare to the github example for the sake of testing it, so only the above 4 lines are present on my main.
Why am I getting this error? I've tried compiling with bazel aswell but I'm getting the same error. What am I missing?
Probably it is missing from the CMakeLists file
Update CMakeLists.txt and add
tensorflow/lite/profiling/telemetry/telemetry.cc and
tensorflow/lite/profiling/telemetry/telemetry.h
to TFLITE_PROFILER_SRCS
It is also worth creating issue on Tensorflow repo for the team

CMake + MSys2 undefined references to everything (including c++ runtime)

I'm playing around with developing a cross-platform C++ project. Things build fine on Linux, but on Windows (10) + MSys2 I've run into a strange issue. Compile works fine (picks up my include dirs, etc.), but linking fails with all sorts of undefined reference errors to a static imported library I have, and even the C++ runtime.
I've tried setting CMAKE_C[XX]_COMPILER, CMAKE_MAKE_PROGRAM, but the output from the configuration step is always the same:
$ cmake ..
-- The C compiler identification is GNU 10.2.0
-- The CXX compiler identification is GNU 10.2.0
System is unknown to cmake, create:
Platform/MINGW64_NT-10.0-19041 to use this system, please post your config file on discourse.cmake.org so it can be added to cmake
-- Detecting C compiler ABI info
System is unknown to cmake, create:
Platform/MINGW64_NT-10.0-19041 to use this system, please post your config file on discourse.cmake.org so it can be added to cmake
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /mingw64/bin/cc.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
System is unknown to cmake, create:
Platform/MINGW64_NT-10.0-19041 to use this system, please post your config file on discourse.cmake.org so it can be added to cmake
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /mingw64/bin/CC.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: <....>
As mentioned earlier the compile works, but linking the executable fails spectacularly. Here is my minimal working example:
$ cat ../CMakeLists.txt
project(example)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
add_executable(example
main.cpp
)
Here is an sample of the output (the rest is omitted for brevity):
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/example.dir/main.cpp.obj:main.cpp:(.text+0x51): undefined reference to `std::ios_base::Init::~Init()'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/example.dir/main.cpp.obj:main.cpp:(.text+0x81): undefined reference to `std::ios_base::Init::Init()'
Adding -v to cmake produces the following commands.
Compile:
/mingw64/bin/CC.exe -std=gnu++17 -o CMakeFiles/example.dir/main.cpp.obj -c /home/.../Development/minex/main.cpp
Link:
/mingw64/bin/CC.exe CMakeFiles/example.dir/main.cpp.obj -o example
CC.exe seems off... and it's used if I set the CXX compiler flag or not...
I also tried generating "MSYS2 Makefiles" but that also fails (doesn't know the generator).
I can reproduce the output by running
$ CC main.cpp -o example
while
$ g++ main.cpp -o example
works fine.
CMake version is 3.18.4.
Edit: This is the entire output of running make VERBOSE=1 (using mingw64-cmake seems to produce the same output, except the 'entering directory' and 'leaving directory' paths are absolute windows paths):
$ cat log
/usr/bin/cmake.exe -S/home/<...>/Development/minex -B/home/<...>/Development/minex/build --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/cmake.exe -E cmake_progress_start /home/<...>/Development/minex/build/CMakeFiles /home/<...>/Development/minex/build//CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory '/home/<...>/Development/minex/build'
make -f CMakeFiles/example.dir/build.make CMakeFiles/example.dir/depend
make[2]: Entering directory '/home/<...>/Development/minex/build'
cd /home/<...>/Development/minex/build && /usr/bin/cmake.exe -E cmake_depends "Unix Makefiles" /home/<...>/Development/minex /home/<...>/Development/minex /home/<...>/Development/minex/build /home/<...>/Development/minex/build /home/<...>/Development/minex/build/CMakeFiles/example.dir/DependInfo.cmake --color=
Dependee "/home/<...>/Development/minex/build/CMakeFiles/example.dir/DependInfo.cmake" is newer than depender "/home/<...>/Development/minex/build/CMakeFiles/example.dir/depend.internal".
Dependee "/home/<...>/Development/minex/build/CMakeFiles/CMakeDirectoryInformation.cmake" is newer than depender "/home/<...>/Development/minex/build/CMakeFiles/example.dir/depend.internal".
Scanning dependencies of target example
make[2]: Leaving directory '/home/<...>/Development/minex/build'
make -f CMakeFiles/example.dir/build.make CMakeFiles/example.dir/build
make[2]: Entering directory '/home/<...>/Development/minex/build'
[ 50%] Building CXX object CMakeFiles/example.dir/main.obj
/mingw64/bin/CC.exe -std=gnu++17 -o CMakeFiles/example.dir/main.obj -c /home/<...>/Development/minex/main.cpp
[100%] Linking CXX executable example
/usr/bin/cmake.exe -E cmake_link_script CMakeFiles/example.dir/link.txt --verbose=1
/mingw64/bin/CC.exe CMakeFiles/example.dir/main.obj -o example
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/example.dir/main.obj:main.cpp:(.text+0x23): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/example.dir/main.obj:main.cpp:(.text+0x32): undefined reference to `std::ostream::operator<<(std::ostream& (*)(std::ostream&))'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/example.dir/main.obj:main.cpp:(.text+0x51): undefined reference to `std::ios_base::Init::~Init()'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/example.dir/main.obj:main.cpp:(.text+0x81): undefined reference to `std::ios_base::Init::Init()'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/example.dir/main.obj:main.cpp:(.rdata$.refptr._ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_[.refptr._ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_]+0x0): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/example.dir/main.obj:main.cpp:(.rdata$.refptr._ZSt4cout[.refptr._ZSt4cout]+0x0): undefined reference to `std::cout'
collect2.exe: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/example.dir/build.make:103: example] Error 1
make[2]: Leaving directory '/home/<...>/Development/minex/build'
make[1]: *** [CMakeFiles/Makefile2:95: CMakeFiles/example.dir/all] Error 2
make[1]: Leaving directory '/home/<...>/Development/minex/build'
make: *** [Makefile:103: all] Error 2
Solution:
I was setting CMAKE_CXX_COMPILER wrong :/. I was doing it from memory, and I just did
CMAKE_CXX_COMPILER=... cmake ..
not
cmake .. -DCMAKE_CXX_COMPILER=...
However! It's still weird that CC is used to successfully compile cpp files, but it can't link the object files.
If you are using mingw64 compiler in MSYS2 make sure you are using mingw64 version of cmake too.
Using cmake not aligned with gcc e.g.:
MINGW64
# which gcc
/mingw64/bin/gcc
MINGW64
# which cmake
/usr/bin/cmake
Will led to following error when running cmake:
...
-- The CXX compiler identification is GNU 10.2.0
System is unknown to cmake, create:
Platform/MINGW64_NT-10.0-19041 to use this system, please post your config file on discourse.cmake.org so it can be added to cmake
...
and linker error in build step.
So make sure you install mingw64 version of cmake:
MINGW64
pacman -S mingw-w64-x86_64-cmake
You need to close terminal and open it again after cmake is installed. Then make sure you have aligned versions of gcc and cmake installed:
MINGW64
# which gcc
/mingw64/bin/gcc
MINGW64
# which cmake
/mingw64/bin/cmake
Now cmake should work properly.
You have these errors because you are trying to compile/link c++ program with a c compiler. For example the two undefined references you are mentioning are part of libstdc++. It is used by default when using g++ but not with CC. If you want to use CC you have to add it manually -lstdc++.
The easiest way is to compile and link c++ programs by using g++.
For some reason the /mingw64/bin/CC.exe is considered as the CXX compiler and the working detection is skipped. to avoid the skipp of the working detection you can add set(CMAKE_CXX_COMPILER_WORKS 1). to modify the compiler it self you can set CMAKE_CXX_COMPILER as explained in CMAKE_CXX_COMPILER or set CXX as explained in CXX . be careful to clean the cache.

CMake can't find Boost_LIBRARIES variable

Final Edit: Solved.
Guys the problem occured because of the "WinSock32".
I've added
target_link_libraries(modernC__ -lws2_32)
and the code has been builded.
I have been using the Boost library on CLion in Ubuntu for about 1 year. But this week I also decided to install it on the Windows operating system.
so I downloaded the Boost library on GitHub and installed the Boost library using Find.Boost first and then "Find.Boost".
After writing the necessary commands in CMake settings section in CLion, I noticed that the variable $ {Boost_LIBRARIES} is empty.
When I don't use the message () function, the "CMake" part of the project does not give an error, but I get the error "undefined reference" after "build". Below are the CMake commands I wrote on CLion and the errors I received.
cmake_minimum_required(VERSION 3.16)
project(modernC__)
set(CMAKE_CXX_STANDARD 17)
find_package(Boost 1.66.0)
message(${Boost_INCLUDE_DIR})
message(${Boost_FOUND})
message(${Boost_LIBRARY_DIRS})
IF (Boost_FOUND)
include_directories(${Boost_INCLUDE_DIR})
add_executable(modernC__
main.cpp
#concurrencyExampleOne.cpp
#adapterExampleOne.cpp
)
target_link_libraries(modernC__ ${Boost_LIBRARIES})
message(${Boost_LIBRARIES})
endif()
My output is:
"C:\Program Files\JetBrains\CLion 2020.1.1\bin\cmake\win\bin\cmake.exe" -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - MinGW Makefiles" C:\Users\Berke\CLionProjects\modernC++
C:/boost/include/boost-1_66
TRUE
C:/boost/lib
CMake Error at CMakeLists.txt:22 (message):
message called with incorrect number of arguments
-- Configuring incomplete, errors occurred!
In this case, obviously Cmake is currently unable to find the .lib files that should link to my code.
My question is; How can I permanently drop .lib files into this variable, or is there any other way to do this?
If I do not use "message(${Boost_LIBRARIES}" so the compiler gives me this error;
[ 50%] Linking CXX executable modernC__.exe
CMakeFiles\modernC__.dir/objects.a(main.cpp.obj): In function `ZNK5boost6system14error_category12std_category10equivalentEiRKSt15error_condition':
C:/boost/include/boost-1_66/boost/system/error_code.hpp:676: undefined reference to `boost::system::generic_category()'
C:/boost/include/boost-1_66/boost/system/error_code.hpp:679: undefined reference to `boost::system::generic_category()'
CMakeFiles\modernC__.dir/objects.a(main.cpp.obj): In function `ZNK5boost6system14error_category12std_category10equivalentERKSt10error_codei':
C:/boost/include/boost-1_66/boost/system/error_code.hpp:706: undefined reference to `boost::system::generic_category()'
C:/boost/include/boost-1_66/boost/system/error_code.hpp:709: undefined reference to `boost::system::generic_category()'
C:/boost/include/boost-1_66/boost/system/error_code.hpp:721: undefined reference to `boost::system::generic_category()'
CMakeFiles\modernC__.dir/objects.a(main.cpp.obj): In function `ZN5boost4asio5error19get_system_categoryEv':
C:/boost/include/boost-1_66/boost/asio/error.hpp:230: undefined reference to `boost::system::system_category()'
CMakeFiles\modernC__.dir/objects.a(main.cpp.obj): In function `ZN5boost4asio6detail17winsock_init_base7startupERNS2_4dataEhh':
C:/boost/include/boost-1_66/boost/asio/detail/impl/winsock_init.ipp:39: undefined reference to `_imp__WSAStartup#8'
CMakeFiles\modernC__.dir/objects.a(main.cpp.obj): In function `ZN5boost4asio6detail17winsock_init_base7cleanupERNS2_4dataE':
C:/boost/include/boost-1_66/boost/asio/detail/impl/winsock_init.ipp:56: undefined reference to `_imp__WSACleanup#0'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: *** [CMakeFiles\modernC__.dir\build.make:86: modernC__.exe] Error 1
mingw32-make.exe[2]: *** [CMakeFiles\Makefile2:75: CMakeFiles/modernC__.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:82: CMakeFiles/modernC__.dir/rule] Error 2
mingw32-make.exe: *** [Makefile:117: modernC__] Error 2
I think, you should specify boost libraries (as components) explicitly.
And you should add libraries to target.
Like this:
find_package(Boost COMPONENTS filesystem system locale context REQUIRED)
...
target_link_libraries(${PROJECT_NAME}
...
${Boost_FILESYSTEM_LIBRARY}
${Boost_SYSTEM_LIBRARY}
${Boost_LOCALE_LIBRARY}
${Boost_CONTEXT_LIBRARY}
...
)

undefined reference to `USER_ERROR__inconsistent_build_configuration__see_dlib_faq_1_'

So when I use the command make I get the following error:
[jalal#goku c++]$ make
[ 25%] Building CXX object CMakeFiles/TestSVM.dir/TestSVM.cpp.o
[ 50%] Linking CXX executable TestSVM
CMakeFiles/TestSVM.dir/TestSVM.cpp.o: In function `__static_initialization_and_destruction_0(int, int)':
TestSVM.cpp:(.text+0x28c3): undefined reference to `USER_ERROR__inconsistent_build_configuration__see_dlib_faq_1_'
TestSVM.cpp:(.text+0x28cf): undefined reference to `USER_ERROR__inconsistent_build_configuration__see_dlib_faq_2'
collect2: error: ld returned 1 exit status
make[2]: *** [TestSVM] Error 1
make[1]: *** [CMakeFiles/TestSVM.dir/all] Error 2
make: *** [all] Error 2
The files look like:
[jalal#goku c++]$ ls
CMakeCache.txt CMakeFiles CMakeLists.txt Makefile TestSVM.cpp TrainSVM.cpp cmake_install.cmake json.hpp trained_svms
I built the dlib in /scratch2/dlib from source using this repo:https://github.com/davisking/dlib
by following these commands:
mkdir build; cd build; cmake .. -DUSE_AVX_INSTRUCTIONS=1; cmake --build .
I am not sure how I should fix this problem.
I followed the following commands in the git repo I cloned:
$ cd c++
$ cmake .
$ make
https://github.com/sausax/pose_estimation
Additionally not sure how to make sense out of this for fixing the bug
https://github.com/davisking/dlib/blob/master/dlib/test_for_odr_violations.cpp
As the commenter said, don't forget to link to dlib! You can do this in CMake with:
target_link_libraries(<YOUR APP> dlib::dlib)
I wasn't able to get plain dlib to link, but I tried ${dlib_LIBRARIES} and finally CMake clued me in with:
CMake Warning at lib/cmake/dlib/dlibConfig.cmake:42 (message):
The variable 'dlib_LIBRARIES' is deprecated! Instead, simply use
target_link_libraries(your_app dlib::dlib). See
http://dlib.net/examples/CMakeLists.txt.html for an example.
I too was distracted by the ENABLE_ASSERTS pointing to the FAQ, but that was due to me having the includes without the linked library.

OpenCV 3.0 source code installation troubleshooting

I installed OpenCV3.0 using the source code obtained from itseez github repo. I set the install prefix as /home/ubuntu/installed_libs/. All went well. I even set ldconfig path in /etc/ld.so.conf.d/local.conf and then sudo ldconfig.
However in my project (CMake) I cannot find the newly installed directory.
When I do cmake ../ in the build directory it throws the following error.
I did some changes as suggested in the answers.
cmake_minimum_required(VERSION 2.8)
project( DisplayImage )
set(OpenCV_DIR /home/ubuntu/installed_libs/share/OpenCV)
find_package( OpenCV )
add_executable( DisplayImage DisplayImage.cpp )
target_link_libraries( DisplayImage ${OpenCV_LIBRARIES} )
message(STATUS "OpenCV_FOUND=${OpenCV_FOUND}")
message(STATUS "OpenCV_INCLUDES=${OpenCV_INCLUDE_DIR}")
message(STATUS "OpenCV_LIBRARIES=${OpenCV_LIBRARIES}")
message(STATUS "OpenCV_DEFINATIONS=${OpenCV_DEFINATIONS}")
message(STATUS "OpenCV_DIR=${OpenCV_DIR}")
Now cmake happens successfully.
$ cmake ..
-- The C compiler identification is GNU 4.8.4
-- The CXX compiler identification is GNU 4.8.4
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Found CUDA: /usr/local/cuda (found suitable exact version "6.5")
-- OpenCV_FOUND=1
-- OpenCV_INCLUDES=
-- OpenCV_LIBRARIES=opencv_videostab;opencv_videoio;opencv_video;opencv_ts;opencv_superres;opencv_stitching;opencv_shape;opencv_photo;opencv_objdetect;opencv_ml;opencv_imgproc;opencv_imgcodecs;opencv_highgui;opencv_hal;opencv_flann;opencv_features2d;opencv_cudev;opencv_cudawarping;opencv_cudastereo;opencv_cudaoptflow;opencv_cudaobjdetect;opencv_cudalegacy;opencv_cudaimgproc;opencv_cudafilters;opencv_cudafeatures2d;opencv_cudacodec;opencv_cudabgsegm;opencv_cudaarithm;opencv_core;opencv_calib3d
-- OpenCV_DEFINATIONS=
-- OpenCV_DIR=/home/ubuntu/installed_libs/share/OpenCV
-- Configuring done
-- Generating done
-- Build files have been written to: /home/ubuntu/ctry/opencvtest/build
However, when I do a make, I get an error :
Scanning dependencies of target DisplayImage
[100%] Building CXX object CMakeFiles/DisplayImage.dir/DisplayImage.cpp.o
Linking CXX executable DisplayImage
CMakeFiles/DisplayImage.dir/DisplayImage.cpp.o: In function `main':
DisplayImage.cpp:(.text+0x94): undefined reference to `cv::imread(std::string const&, int)'
DisplayImage.cpp:(.text+0x108): undefined reference to `cv::namedWindow(std::string const&, int)'
DisplayImage.cpp:(.text+0x14e): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
DisplayImage.cpp:(.text+0x15e): undefined reference to `cv::imshow(std::string const&, cv::_InputArray const&)'
collect2: error: ld returned 1 exit status
make[2]: *** [DisplayImage] Error 1
make[1]: *** [CMakeFiles/DisplayImage.dir/all] Error 2
make: *** [all] Error 2
I know this is a linking error. How should I fix this?
Verbose make display incase it is helpful.
$ make VERBOSE=1
/usr/bin/cmake -H/home/ubuntu/ctry/opencvtest -B/home/ubuntu/ctry/opencvtest/build --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/cmake -E cmake_progress_start /home/ubuntu/ctry/opencvtest/build/CMakeFiles /home/ubuntu/ctry/opencvtest/build/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory `/home/ubuntu/ctry/opencvtest/build'
make -f CMakeFiles/DisplayImage.dir/build.make CMakeFiles/DisplayImage.dir/depend
make[2]: Entering directory `/home/ubuntu/ctry/opencvtest/build'
cd /home/ubuntu/ctry/opencvtest/build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/ubuntu/ctry/opencvtest /home/ubuntu/ctry/opencvtest /home/ubuntu/ctry/opencvtest/build /home/ubuntu/ctry/opencvtest/build /home/ubuntu/ctry/opencvtest/build/CMakeFiles/DisplayImage.dir/DependInfo.cmake --color=
make[2]: Leaving directory `/home/ubuntu/ctry/opencvtest/build'
make -f CMakeFiles/DisplayImage.dir/build.make CMakeFiles/DisplayImage.dir/build
make[2]: Entering directory `/home/ubuntu/ctry/opencvtest/build'
Linking CXX executable DisplayImage
/usr/bin/cmake -E cmake_link_script CMakeFiles/DisplayImage.dir/link.txt --verbose=1
/usr/bin/c++ CMakeFiles/DisplayImage.dir/DisplayImage.cpp.o -o DisplayImage -L/usr/local/cuda/lib -rdynamic /home/ubuntu/installed_libs/lib/libopencv_videostab.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_videoio.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_video.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_ts.a /home/ubuntu/installed_libs/lib/libopencv_superres.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_stitching.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_shape.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_photo.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_objdetect.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_ml.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_imgproc.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_imgcodecs.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_highgui.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_hal.a /home/ubuntu/installed_libs/lib/libopencv_flann.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_features2d.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_cudev.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_cudawarping.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_cudastereo.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_cudaoptflow.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_cudaobjdetect.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_cudalegacy.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_cudaimgproc.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_cudafilters.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_cudafeatures2d.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_cudacodec.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_cudabgsegm.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_cudaarithm.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_core.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_calib3d.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_cudawarping.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_objdetect.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_cudafilters.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_cudaarithm.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_features2d.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_ml.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_highgui.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_videoio.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_imgcodecs.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_flann.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_video.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_imgproc.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_core.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_cudev.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_hal.a -ldl -lm -lpthread -lrt -lcudart -lnppc -lnppi -lnpps -lcufft -lcudart -lnppc -lnppi -lnpps -lcufft -Wl,-rpath,/usr/local/cuda/lib:/home/ubuntu/installed_libs/lib
CMakeFiles/DisplayImage.dir/DisplayImage.cpp.o: In function `main':
DisplayImage.cpp:(.text+0x94): undefined reference to `cv::imread(std::string const&, int)'
DisplayImage.cpp:(.text+0x108): undefined reference to `cv::namedWindow(std::string const&, int)'
DisplayImage.cpp:(.text+0x14e): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
DisplayImage.cpp:(.text+0x15e): undefined reference to `cv::imshow(std::string const&, cv::_InputArray const&)'
collect2: error: ld returned 1 exit status
make[2]: *** [DisplayImage] Error 1
make[2]: Leaving directory `/home/ubuntu/ctry/opencvtest/build'
make[1]: *** [CMakeFiles/DisplayImage.dir/all] Error 2
make[1]: Leaving directory `/home/ubuntu/ctry/opencvtest/build'
make: *** [all] Error 2
You should check the output of:
ldconfig -p | grep -i opencv
pkg-config --cflags opencv
pkg-config --libs opencv
If nothing is listed, then you ldconfig may configured incorrectly. If the system-installed version of OpenCV is listed, it may be a problem of the search order.
In either case, you could try to configure the CMAKE_MODULE_PATH of your project DisplayImage, which is searched by CMake before standard system locations. So, assuming your in your build directory of DisplayImage is $SRC_DIR/build, configure your project like this
cmake -DCMAKE_MODULE_PATH="/home/ubuntu/installed_libs/<OpenCV directory>" <other options> ..
Also interesting: what happens in the background of find_package().
You can add
set(OpenCV_DIR /home/ubuntu/installed_libs/share/OpenCV)
to your CMakeLists, so it looks something like
cmake_minimum_required(VERSION 2.8)
project( DisplayImage )
set(OpenCV_DIR /home/ubuntu/installed_libs/share/OpenCV)
find_package( OpenCV REQUIRED 3.0 )
add_executable( DisplayImage DisplayImage.cpp )
target_link_libraries( DisplayImage ${OpenCV_LIBS} )