Qengineering / Face-detection-Landmark-Raspberry-Pi-32-64-bits

Super fast face detection with landmarks on Raspberry Pi 4
https://qengineering.eu/deep-learning-examples-on-raspberry-32-64-os.html
BSD 3-Clause "New" or "Revised" License
6 stars 1 forks source link

undefined reference error compiling main.cpp #1

Open EvanBrownVTM opened 2 years ago

EvanBrownVTM commented 2 years ago

Command: g++ main.cpp

Error: /usr/bin/ld: /tmp/ccfhTjVl.o: in function main': main.cpp:(.text+0xc0): undefined reference toDetector::Detector(std::cxx11::basic_string<char, std::char_traits, std::allocator > const&, std::cxx11::basic_string<char, std::char_traits, std::allocator > const&)' /usr/bin/ld: main.cpp:(.text+0x114): undefined reference to cv::VideoCapture::VideoCapture(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)' /usr/bin/ld: main.cpp:(.text+0x12c): undefined reference tocv::VideoCapture::isOpened() const' /usr/bin/ld: main.cpp:(.text+0x1a4): undefined reference to cv::VideoCapture::operator>>(cv::Mat&)' /usr/bin/ld: main.cpp:(.text+0x284): undefined reference tocv::resize(cv::_InputArray const&, cv::OutputArray const&, cv::Size, double, double, int)' /usr/bin/ld: main.cpp:(.text+0x2b4): undefined reference to Detector::Detect(cv::Mat&, std::vector<bbox, std::allocator<bbox> >&)' /usr/bin/ld: main.cpp:(.text+0x3f8): undefined reference tocv::rectangle(cv::InputOutputArray const&, cv::Rect, cv::Scalar_ const&, int, int, int)' /usr/bin/ld: main.cpp:(.text+0x498): undefined reference to cv::circle(cv::_InputOutputArray const&, cv::Point_<int>, int, cv::Scalar_<double> const&, int, int, int)' /usr/bin/ld: main.cpp:(.text+0x540): undefined reference tocv::circle(cv::InputOutputArray const&, cv::Point, int, cv::Scalar_ const&, int, int, int)' /usr/bin/ld: main.cpp:(.text+0x5e8): undefined reference to cv::circle(cv::_InputOutputArray const&, cv::Point_<int>, int, cv::Scalar_<double> const&, int, int, int)' /usr/bin/ld: main.cpp:(.text+0x688): undefined reference tocv::circle(cv::InputOutputArray const&, cv::Point, int, cv::Scalar_ const&, int, int, int)' /usr/bin/ld: main.cpp:(.text+0x728): undefined reference to cv::circle(cv::_InputOutputArray const&, cv::Point_<int>, int, cv::Scalar_<double> const&, int, int, int)' /usr/bin/ld: main.cpp:(.text+0x81c): undefined reference tocv::format[abi:cxx11](char const, ...)' /usr/bin/ld: main.cpp:(.text+0x880): undefined reference to cv::putText(cv::_InputOutputArray const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::Point_<int>, int, double, cv::Scalar_<double>, int, int, bool)' /usr/bin/ld: main.cpp:(.text+0x8cc): undefined reference tocv::imshow(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&, cv::_InputArray const&)' /usr/bin/ld: main.cpp:(.text+0x8ec): undefined reference to cv::waitKey(int)' /usr/bin/ld: main.cpp:(.text+0x93c): undefined reference tocv::destroyAllWindows()' /usr/bin/ld: main.cpp:(.text+0x948): undefined reference to cv::VideoCapture::~VideoCapture()' /usr/bin/ld: main.cpp:(.text+0x950): undefined reference toDetector::~Detector()' /usr/bin/ld: main.cpp:(.text+0xa9c): undefined reference to cv::VideoCapture::~VideoCapture()' /usr/bin/ld: main.cpp:(.text+0xaa4): undefined reference toDetector::~Detector()' /usr/bin/ld: /tmp/ccfhTjVl.o: in function cv::Mat::~Mat()': main.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x34): undefined reference tocv::fastFree(void)' /usr/bin/ld: /tmp/ccfhTjVl.o: in function cv::Mat::release()': main.cpp:(.text._ZN2cv3Mat7releaseEv[_ZN2cv3Mat7releaseEv]+0x54): undefined reference tocv::Mat::deallocate()' collect2: error: ld returned 1 exit status

Qengineering commented 2 years ago

You have to tell g++ where it can find all the headers, libraries and other dependencies. Perhaps only a 'Hello World' could run without any other information. Second, once g++ has compiled the individual cpp files, you get object files. All these need to be linked together with the linker.

The commands you should have used are:

g++ -Wall -fexceptions -pthread -O3 -I/usr/local/include/opencv4 -I/usr/local/include/ncnn -c FaceDetector.cpp -o FaceDetector.o
g++ -Wall -fexceptions -pthread -O3 -I/usr/local/include/opencv4 -I/usr/local/include/ncnn -c main.cpp -o main.o
g++ -L/usr/local/lib/ -o FaceLandmark FaceDetector.o main.o  -I/usr/local/include/opencv4 -L/usr/local/lib -lopencv_gapi -lopencv_stitching -lopencv_aruco -lopencv_bgsegm -lopencv_bioinspired -lopencv_ccalib -lopencv_dnn_objdetect -lopencv_dnn_superres -lopencv_dpm -lopencv_face -lopencv_freetype -lopencv_fuzzy -lopencv_hdf -lopencv_hfs -lopencv_img_hash -lopencv_intensity_transform -lopencv_line_descriptor -lopencv_mcc -lopencv_quality -lopencv_rapid -lopencv_reg -lopencv_rgbd -lopencv_saliency -lopencv_stereo -lopencv_structured_light -lopencv_phase_unwrapping -lopencv_superres -lopencv_optflow -lopencv_surface_matching -lopencv_tracking -lopencv_highgui -lopencv_datasets -lopencv_text -lopencv_plot -lopencv_videostab -lopencv_videoio -lopencv_xfeatures2d -lopencv_shape -lopencv_ml -lopencv_ximgproc -lopencv_video -lopencv_dnn -lopencv_xobjdetect -lopencv_objdetect -lopencv_calib3d -lopencv_imgcodecs -lopencv_features2d -lopencv_flann -lopencv_xphoto -lopencv_photo -lopencv_imgproc -lopencv_core -pthread -fopenmp -s  /usr/local/lib/ncnn/libncnn.a

You get the following output: image FaceLandmark is your exe.

Even with a relatively simple program like this, working with the command prompt is a source of typos and other errors. You need a kind of compile manager. That is why we advise you to use the free Code::Blocks. See our site for more details on how to work with Code::Blocks.