Home > OS >  Make failing with not used function
Make failing with not used function

Time:06-18

I am trying to build my code. After I do cmake .. from a build directory I do make -j8 and I get

[ 90%] Building CXX object common/CMakeFiles/common.dir/src/utils/path_util.cpp.o
[ 95%] Linking CXX executable myproj
CMakeFiles/myproj.dir/main.cpp.o: In function `cv::String::~String()':
main.cpp:(.text._ZN2cv6StringD2Ev[_ZN2cv6StringD5Ev] 0x14): undefined reference to `cv::String::deallocate()'
CMakeFiles/myproj.dir/main.cpp.o: In function `cv::String::operator=(cv::String const&)':
main.cpp:(.text._ZN2cv6StringaSERKS0_[_ZN2cv6StringaSERKS0_] 0x28): undefined reference to `cv::String::deallocate()'
collect2: error: ld returned 1 exit status
CMakeFiles/myproj.dir/build.make:95: recipe for target 'myproj' failed
make[2]: *** [myproj] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/myproj.dir/all' failed
make[1]: *** [CMakeFiles/myproj.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....

The curious thing is that nowhere in the code I use cv::String.

I have also put

#Search for dependencies
set(MIN_OPENCV_VERSION "3.4.11" CACHE STRING "OpenCV version")
find_package(OpenCV ${MIN_OPENCV_VERSION} REQUIRED
   COMPONENTS core
   PATHS /usr/local/opencv-${MIN_OPENCV_VERSION}
   NO_DEFAULT_PATH
)

in several CMakeLists.txt files and cmake finds opencv

What could be the problem?

EDIT

I set the VERBOSE environment variable to 1 as stated here

and I got

[ 90%] Building CXX object common/CMakeFiles/common.dir/src/utils/path_util.cpp.o
cd /home/user/ws/src/build/common && /usr/bin/c     -I/usr/local/include/eigen3 -isystem /usr/local/opencv-3.4.11/include -isystem /usr/local/opencv-3.4.11/include/opencv -I/home/user/ws/src/common/include -I/home/user/ws/src/common/src -isystem /usr/local  -fPIC   -o CMakeFiles/common.dir/src/utils/path_util.cpp.o -c /home/user/ws/src/common/src/utils/path_util.cpp
[ 95%] Linking CXX executable road_info
/usr/bin/cmake -E cmake_link_script CMakeFiles/myproj.dir/link.txt --verbose=1
/usr/bin/c      -rdynamic CMakeFiles/myproj.dir/main.cpp.o  -o myproj mainpub_lib/mainpub.a 
CMakeFiles/myproj.dir/main.cpp.o: In function `cv::String::~String()':
main.cpp:(.text._ZN2cv6StringD2Ev[_ZN2cv6StringD5Ev] 0x14): undefined reference to `cv::String::deallocate()'
CMakeFiles/myproj.dir/main.cpp.o: In function `cv::String::operator=(cv::String const&)':
main.cpp:(.text._ZN2cv6StringaSERKS0_[_ZN2cv6StringaSERKS0_] 0x28): undefined reference to `cv::String::deallocate()'
collect2: error: ld returned 1 exit status
CMakeFiles/myproj.dir/build.make:95: recipe for target 'myproj' failed
make[2]: *** [myproj] Error 1
make[2]: Leaving directory '/home/user/ws/src/build'
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/myproj.dir/all' failed
make[1]: *** [CMakeFiles/myproj.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....

CodePudding user response:

First, thanks @fabian for the help and pointers

I finally realized that the problem was not in my main.cpp but in a hpp file that main calls. This one.hpp file included another hpp file that was the one that caused the problem (When I commented it, the problem disapeared)

So what I did was change the CMakeLists.txt of the second level (the one dealing with the problematic hpp file) and added

target_link_libraries(mainpub PRIVATE ${OpenCV_LIBS})

With this the problem was solved

To allow for a verbose make I did export VERBOSE=1 because my make version is old. With the verbose output I could see that mainpub was the only library linked

What strikes me strange is that mainpub was apparently being built even with the problem instead the main build was signaled as problematic

  • Related