Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How resolve the problem of undefined reference in CMake on linux ?

Hi,

I've written a code and I've used classes, however when I'm trying to compile the code using CMake I got these errors

        [azdoud@video-processor prototype02]$ cmake -DCMAKE_CXX_FLAGS="-std=c++11"
        -- Configuring done
        -- Generating done
        -- Build files have been written to: /home/azdoud/prototype02
        [azdoud@video-processor prototype02]$ make
        Scanning dependencies of target main
        [100%] Building CXX object CMakeFiles/main.dir/main.cpp.o
        Linking CXX executable main
        CMakeFiles/main.dir/main.cpp.o: In function `main':
        main.cpp:(.text+0x60e): undefined reference to `AdFeature::AdFeature(int, int, bool, cv::Mat)'
        main.cpp:(.text+0x668): undefined reference to `AdFeature::~AdFeature()'
        main.cpp:(.text+0xf19): undefined reference to `AdFeature::~AdFeature()'
        CMakeFiles/main.dir/main.cpp.o: In function `ProcessingSimilarty(cv::VideoCapture, std::vector<AdFeature, std::allocator<AdFeature> >, double, seekStep, std::string)':
        main.cpp:(.text+0x13f8): undefined reference to `AdFeature::get_frame()'
        main.cpp:(.text+0x170b): undefined reference to `AdFeature::set_found(bool)'
        main.cpp:(.text+0x1731): undefined reference to `AdFeature::set_indexLocationAD(int)'
        main.cpp:(.text+0x1750): undefined reference to `AdFeature::~AdFeature()'
        CMakeFiles/main.dir/main.cpp.o: In function `cleanAdFeature(std::vector<AdFeature, std::allocator<AdFeature> >)':
        main.cpp:(.text+0x1b77): undefined reference to `AdFeature::set_found(bool)'
        main.cpp:(.text+0x1b97): undefined reference to `AdFeature::set_indexLocationAD(int)'
        CMakeFiles/main.dir/main.cpp.o: In function `findAdLocation(std::vector<AdFeature, std::allocator<AdFeature> >, int, double, double)':
        CMakeFiles/main.dir/main.cpp.o: In function `void __gnu_cxx::new_allocator<AdFeature>::destroy<AdFeature>(AdFeature*)':
        main.cpp:(.text._ZN9__gnu_cxx13new_allocatorI9AdFeatureE7destroyIS1_EEvPT_[_ZN9__gnu_cxx13new_allocatorI9AdFeatureE7destroyIS1_EEvPT_]+0x18): undefined reference to `AdFeature::~AdFeature()'
        CMakeFiles/main.dir/main.cpp.o: In function `void std::_Destroy<AdFeature>(AdFeature*)':
        main.cpp:(.text._ZSt8_DestroyI9AdFeatureEvPT_[_ZSt8_DestroyI9AdFeatureEvPT_]+0x14): undefined reference to `AdFeature::~AdFeature()'
        collect2: error: ld returned 1 exit status
        make[2]: *** [main] Error 1
        make[1]: *** [CMakeFiles/main.dir/all] Error 2
        make: *** [all] Error 2

even though adding include_directories (dir of the code) in CMakeLists.txt did not work

        cmake_minimum_required(VERSION 2.8)
        project( main )
        find_package( OpenCV REQUIRED )
        add_executable( main main.cpp )
        target_link_libraries( main ${OpenCV_LIBS} )
        include_directories(/home/azdoud/prototype02)

So, how Can I make these .h file a definedable reference?

thank you

How resolve the problem of undefined reference in CMake on linux ?

Hi,

I've written a code and I've used classes, however when I'm trying to compile the code using CMake I got these errors

        [azdoud@video-processor prototype02]$ cmake -DCMAKE_CXX_FLAGS="-std=c++11"
        -- Configuring done
        -- Generating done
        -- Build files have been written to: /home/azdoud/prototype02
        [azdoud@video-processor prototype02]$ make
        Scanning dependencies of target main
        [100%] Building CXX object CMakeFiles/main.dir/main.cpp.o
        Linking CXX executable main
        CMakeFiles/main.dir/main.cpp.o: In function `main':
        main.cpp:(.text+0x60e): undefined reference to `AdFeature::AdFeature(int, int, bool, cv::Mat)'
        main.cpp:(.text+0x668): undefined reference to `AdFeature::~AdFeature()'
        main.cpp:(.text+0xf19): undefined reference to `AdFeature::~AdFeature()'
        CMakeFiles/main.dir/main.cpp.o: In function `ProcessingSimilarty(cv::VideoCapture, std::vector<AdFeature, std::allocator<AdFeature> >, double, seekStep, std::string)':
        main.cpp:(.text+0x13f8): undefined reference to `AdFeature::get_frame()'
        main.cpp:(.text+0x170b): undefined reference to `AdFeature::set_found(bool)'
        main.cpp:(.text+0x1731): undefined reference to `AdFeature::set_indexLocationAD(int)'
        main.cpp:(.text+0x1750): undefined reference to `AdFeature::~AdFeature()'
        CMakeFiles/main.dir/main.cpp.o: In function `cleanAdFeature(std::vector<AdFeature, std::allocator<AdFeature> >)':
        main.cpp:(.text+0x1b77): undefined reference to `AdFeature::set_found(bool)'
        main.cpp:(.text+0x1b97): undefined reference to `AdFeature::set_indexLocationAD(int)'
        CMakeFiles/main.dir/main.cpp.o: In function `findAdLocation(std::vector<AdFeature, std::allocator<AdFeature> >, int, double, double)':
        CMakeFiles/main.dir/main.cpp.o: In function `void __gnu_cxx::new_allocator<AdFeature>::destroy<AdFeature>(AdFeature*)':
        main.cpp:(.text._ZN9__gnu_cxx13new_allocatorI9AdFeatureE7destroyIS1_EEvPT_[_ZN9__gnu_cxx13new_allocatorI9AdFeatureE7destroyIS1_EEvPT_]+0x18): undefined reference to `AdFeature::~AdFeature()'
        CMakeFiles/main.dir/main.cpp.o: In function `void std::_Destroy<AdFeature>(AdFeature*)':
        main.cpp:(.text._ZSt8_DestroyI9AdFeatureEvPT_[_ZSt8_DestroyI9AdFeatureEvPT_]+0x14): undefined reference to `AdFeature::~AdFeature()'
        collect2: error: ld returned 1 exit status
        make[2]: *** [main] Error 1
        make[1]: *** [CMakeFiles/main.dir/all] Error 2
        make: *** [all] Error 2

even though adding include_directories (dir of the code) in CMakeLists.txt did not work

        cmake_minimum_required(VERSION 2.8)
        project( main )
        find_package( OpenCV REQUIRED )
        add_executable( main main.cpp )
        target_link_libraries( main ${OpenCV_LIBS} )
        include_directories(/home/azdoud/prototype02)

So, how Can I make these .h file a definedable reference?

thank you