I tried to compile opencv codes on raspberry pi 3.However, it gives always "undefined reference ... " error, i think there is a problem with linking.
Compile:
g++ `pkg-config --libs --cflags opencv` Face_Detection.cpp
pkg-config opencv --libs:
-L/opt/lib/ -L/opt/Deneme/opencv/a/ -opencv_calib3d -opencv_core
-opencv_features2d -opencv_flann -opencv_highgui -opencv_imgcodecs
-opencv_imgproc -opencv_ml -opencv_objdetect -opencv_photo -opencv_shape
-opencv_stitching -opencv_superres -opencv_videoio -opencv_video
-opencv_calib3d_pch_dephelp -opencv_contrib_pch_dephelp
-opencv_core_pch_dephelp -opencv_features2d_pch_dephelp
-opencv_flann_pch_dephelp -opencv_gpu_pch_dephelp
-opencv_haartraining_engine -opencv_highgui_pch_dephelp
-opencv_imgproc_pch_dephelp -opencv_legacy_pch_dephelp
-opencv_ml_pch_dephelp -opencv_objdetect_pch_dephelp
-opencv_video_pch_dephelp
pkg-config opencv --cflags:
-I/opt/Deneme/Include/opencv -I/opt/Deneme/Include/
opencv.pc file:
includedir=/opt/Deneme/Include/opencv
dir2=/opt/Deneme/Include/
libdir=/opt/lib/
libdir2=/opt/Deneme/opencv/a/
Name: opencv
Description: The opencv library
Version: 3.x.x
Cflags: -I${includedir} -I${dir2}
Libs: -L${libdir} -opencv_calib3d -opencv_core -opencv_features2d - opencv_flann -opencv_highgui -opencv_imgcodecs -opencv_imgproc -opencv_ml -opencv_objdetect -opencv_photo -opencv_shape -opencv_stitching -opencv_superres -opencv_videoio -opencv_video -L${libdir2} -opencv_calib3d_pch_dephelp -opencv_contrib_pch_dephelp -opencv_core_pch_dephelp -opencv_features2d_pch_dephelp -opencv_flann_pch_dephelp -opencv_gpu_pch_dephelp -opencv_haartraining_engine -opencv_highgui_pch_dephelp -opencv_imgproc_pch_dephelp -opencv_legacy_pch_dephelp -opencv_ml_pch_dephelp -opencv_objdetect_pch_dephelp -opencv_video_pch_dephelp
error:
Face_Detection.cpp:(.text+0x94): undefined reference to `cv::imread(std::string const&, int)'
Face_Detection.cpp:(.text+0xd8): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
Face_Detection.cpp:(.text+0xec): undefined reference to `cv::_OutputArray::_OutputArray(cv::Mat&)'
Face_Detection.cpp:(.text+0x128): undefined reference to `cv::resize(cv::_InputArray const&, cv::_OutputArray const&, cv::Size_<int>, double, double, int)'
Face_Detection.cpp:(.text+0x1e8): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
Face_Detection.cpp:(.text+0x218): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
Face_Detection.cpp:(.text+0x250): undefined reference to `cv::_OutputArray::_OutputArray(cv::Mat&)'
Face_Detection.cpp:(.text+0x26c): undefined reference to `cv::hconcat(cv::_InputArray const&, cv::_InputArray const&, cv::_OutputArray const&)'
Face_Detection.cpp:(.text+0x298): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
Face_Detection.cpp:(.text+0x2c8): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
Thanks in advance.
It was linker order error. Try to change
g++ `pkg-config --libs --cflags opencv` Face_Detection.cpp
to
g++ Face_Detection.cpp `pkg-config --libs --cflags opencv`
Related
I'm trying the following code:
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
int main(int argc, char** argv) {
namedWindow("Output",1);
Mat output = Mat::zeros( 120, 350, CV_8UC3 );
putText(output,"Hello World",cvPoint(15,70),
FONT_HERSHEY_PLAIN,3,cvScalar(0,255,0),4);
imshow("Output", output);
waitKey(0);
return 0;
}
I then tried g++ -I/usr/local/include -L/usr/local/lib -lopencv_core -lopencv_imgcodecs -lopencv_highgui opencv_hello.cpp -o opencv_hello
and g++pkg-config opencv cvblob --cflags --libsopencv_hello.cpp -o opencv_hello
But they both give the same undefined reference errors:
opencv_hello.cpp:(.text+0x132): undefined reference to `cv::namedWindow(cv::String const&, int)'
opencv_hello.cpp:(.text+0x15f): undefined reference to `cv::Mat::zeros(int, int, int)'
opencv_hello.cpp:(.text+0x26f): undefined reference to `cv::putText(cv::_InputOutputArray const&, cv::String const&, cv::Point_<int>, int, double, cv::Scalar_<double>, int, int, bool)'
opencv_hello.cpp:(.text+0x2d7): undefined reference to `cv::imshow(cv::String const&, cv::_InputArray const&)'
opencv_hello.cpp:(.text+0x2ff): undefined reference to `cv::waitKey(int)'
/tmp/cctt8VGQ.o: In function `cv::String::String(char const*)':
opencv_hello.cpp:(.text._ZN2cv6StringC2EPKc[_ZN2cv6StringC5EPKc]+0x4d): undefined reference to `cv::String::allocate(unsigned long)'
/tmp/cctt8VGQ.o: In function `cv::String::~String()':
opencv_hello.cpp:(.text._ZN2cv6StringD2Ev[_ZN2cv6StringD5Ev]+0x14): undefined reference to `cv::String::deallocate()'
/tmp/cctt8VGQ.o: In function `cv::Mat::~Mat()':
opencv_hello.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x39): undefined reference to `cv::fastFree(void*)'
/tmp/cctt8VGQ.o: In function `cv::Mat::release()':
opencv_hello.cpp:(.text._ZN2cv3Mat7releaseEv[_ZN2cv3Mat7releaseEv]+0x4b): undefined reference to `cv::Mat::deallocate()'
How can I fix this?
If pkg-config opencv --cflags --libs command finds OpenCV include files and libraries below compilation works wituout any errors.
g++ opencv_hello.cpp -o opencv_hello $(pkg-config opencv --cflags --libs)
or
g++ opencv_hello.cpp -o opencv_hello `pkg-config opencv --cflags --libs`
I am trying to compile this code in CodeBlocks
#include <boost/filesystem.hpp>
#include <iostream>
using namespace boost::filesystem;
int main()
{
if ( !boost::filesystem::exists( "myfile.txt" ) )
{
std::cout << "Can't find my file!" << std::endl;
}
}
With this compile flags:
g++.exe -Wall -fexceptions -g -O3 -pedantic-errors -Wall -std=c++0x -lboost_system -IC:\Users\moe\Desktop\boost_1_67_0 -c C:\Users\moe\Desktop\oo\main.cpp -o obj\Debug\main.o
But I always receive this error:
boost::system::generic_category()
this is the error log, that i receive when i compile the code:
Untitled4.o: In function `boost::system::error_category::std_category::equivalent(std::error_code const&, int) const':
C:/Users/moe/Desktop/boost_1_67_0/boost/system/error_code.hpp:733: undefined reference to `boost::system::generic_category()'
C:/Users/moe/Desktop/boost_1_67_0/boost/system/error_code.hpp:736: undefined reference to `boost::system::generic_category()'
C:/Users/moe/Desktop/boost_1_67_0/boost/system/error_code.hpp:748: undefined reference to `boost::system::generic_category()'
Untitled4.o: In function `boost::system::error_category::std_category::equivalent(int, std::error_condition const&) const':
C:/Users/moe/Desktop/boost_1_67_0/boost/system/error_code.hpp:703: undefined reference to `boost::system::generic_category()'
C:/Users/moe/Desktop/boost_1_67_0/boost/system/error_code.hpp:706: undefined reference to `boost::system::generic_category()'
Untitled4.o: In function `boost::filesystem::path_traits::convert(char const*, char const*, std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >&)':
C:/Users/moe/Desktop/boost_1_67_0/boost/filesystem/path.hpp:981: undefined reference to `boost::filesystem::path::codecvt()'
C:/Users/moe/Desktop/boost_1_67_0/boost/filesystem/path.hpp:981: undefined reference to `boost::filesystem::path_traits::convert(char const*, char const*, std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >&, std::codecvt<wchar_t, char, int> const&)'
Untitled4.o: In function `boost::filesystem::exists(boost::filesystem::path const&)':
C:/Users/moe/Desktop/boost_1_67_0/boost/filesystem/operations.hpp:446: undefined reference to `boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)'
collect2.exe: error: ld returned 1 exit status
Put the libraries at the end of the linker command line:
Why does the order of '-l' option in gcc matter?
Since your erro log also contained these:
C:/Users/moe/Desktop/boost_1_67_0/boost/filesystem/path.hpp:981: undefined reference to `boost::filesystem::path::codecvt()'
It is clear that you also lack -lboost_filesystem.
So there is no use to just add -lboost_system to the g++ command.
You can add -lboost_system -lboost_filesystem to your g++ command.
I need to include dlib in a c++ project. I have properly linked the library in my Makefile. Here is the Makefile:
EXE = face_frontalization
OBJ_DIR = bin
CFLAGS = -g -w
# CXXFLAGS = -w -Wall -Wextra -g -std=c++0x
# LDFLAGS = -lSDL2 -lSDL2_image -lSDL2_ttf -lSDL2_mixer -lSDL2_gfx -lm
dummy_build_folder := $(shell mkdir -p $(OBJ_DIR))
# c++ source files of the project
CXXFILES = $(shell find src -type f -name '*.cpp')
CXXOBJ = $(patsubst src/%.cpp,bin/%.o,$(CXXFILES))
INCLUDE = -I/usr/include/dlib-18.18
LIBS = `pkg-config --libs opencv`
CXXFLAGS = `pkg-config --cflags opencv` -w -Wall -Wextra -g -std=c++0x
LDFLAGS = -lcurl
CFLAGS = `pkg-config --cflags opencv` -g -w
MKDIR = mkdir -p
ifdef V
MUTE =
VTAG = -v
else
MUTE = #
endif
###################################################################
# This is a Makefile progress indicator.
# BUILD is initially undefined
ifndef BUILD
# max equals 256 x's
sixteen := x x x x x x x x x x x x x x x x
MAX := $(foreach x,$(sixteen),$(sixteen))
# T estimates how many targets we are building by replacing BUILD with
# a special string
T := $(shell $(MAKE) -nrRf $(firstword $(MAKEFILE_LIST)) $(MAKECMDGOALS) \
BUILD="COUNTTHIS" | grep -c "COUNTTHIS")
# N is the number of pending targets in base 1, well in fact, base x
# :-)
N := $(wordlist 1,$T,$(MAX))
# auto-decrementing counter that returns the number of pending targets
# in base 10
counter = $(words $N)$(eval N := $(wordlist 2,$(words $N),$N))
# BUILD is now defined to show the progress, this also avoids
# redefining T in loop
BUILD = #echo $(counter) of $(T)
endif
###################################################################
# .PHONY: directories all
#
# directories: ${OUT_DIR}
# ${OUT_DIR}:
# ${MKDIR} ${OUT_DIR}
all: $(EXE)
# build successful
$(EXE): $(CXXOBJ)
$(CXX) $(CXXOBJ) -o $(EXE) $(LIBS) $(LDFLAGS)
$(OBJ_DIR)/%.o: src/%.cpp
$(CXX) $(CXXFLAGS) $(INCLUDE) $< -c -o $#
$(BUILD)
$(OBJ_DIR)/%.o: src/%.c
$(CC) $(CFLAGS) $(INCLUDE) $< -c -o $#
run: all
./$(EXE)
clean:
# Cleaning...
-rm -f $(EXE) $(CXXOBJ)
rmdir bin/
I dont know why but its giving errors on compilation. I have compiled the dlib library itself too and the code examples are running as they should.
The error I am getting is:
bin/fatialfeaturedetect.o: In function `fatial_feature_detector()':
/home/playroom/Desktop/face-frontalization/src/fatialfeaturedetect.cpp:20: undefined reference to `dlib::base_window::wait_until_closed() const'
/home/playroom/Desktop/face-frontalization/src/fatialfeaturedetect.cpp:18: undefined reference to `dlib::image_window::~image_window()'
/home/playroom/Desktop/face-frontalization/src/fatialfeaturedetect.cpp:18: undefined reference to `dlib::image_window::~image_window()'
bin/fatialfeaturedetect.o: In function `dlib::get_serialized_frontal_faces()':
/usr/include/dlib-18.18/dlib/image_processing/frontal_face_detector.h:115: undefined reference to `dlib::base64::base64()'
/usr/include/dlib-18.18/dlib/image_processing/frontal_face_detector.h:2358: undefined reference to `dlib::base64::decode(std::istream&, std::ostream&) const'
/usr/include/dlib-18.18/dlib/image_processing/frontal_face_detector.h:2367: undefined reference to `dlib::base64::~base64()'
/usr/include/dlib-18.18/dlib/image_processing/frontal_face_detector.h:2367: undefined reference to `dlib::base64::~base64()'
bin/fatialfeaturedetect.o: In function `dlib_check_consistent_assert_usage':
/usr/include/dlib-18.18/dlib/gui_widgets/../gui_core/../threads/threads_kernel_shared.h:44: undefined reference to `USER_ERROR__missing_dlib_all_source_cpp_file__OR__inconsistent_use_of_DEBUG_or_ENABLE_ASSERTS_preprocessor_directives_'
bin/fatialfeaturedetect.o: In function `dlib::drawable_window::drawable_window(bool, bool)':
/usr/include/dlib-18.18/dlib/gui_widgets/drawable.h:79: undefined reference to `dlib::base_window::base_window(bool, bool)'
/usr/include/dlib-18.18/dlib/gui_widgets/drawable.h:79: undefined reference to `vtable for dlib::drawable_window'
/usr/include/dlib-18.18/dlib/gui_widgets/drawable.h:79: undefined reference to `dlib::base_window::~base_window()'
bin/fatialfeaturedetect.o: In function `dlib::drawable_window::~drawable_window()':
/usr/include/dlib-18.18/dlib/gui_widgets/drawable.h:195: undefined reference to `vtable for dlib::drawable_window'
/usr/include/dlib-18.18/dlib/gui_widgets/drawable.h:195: undefined reference to `dlib::base_window::close_window()'
/usr/include/dlib-18.18/dlib/gui_widgets/drawable.h:195: undefined reference to `dlib::base_window::~base_window()'
bin/fatialfeaturedetect.o: In function `dlib::scrollable_region_style_default::draw_scrollable_region_border(dlib::canvas const&, dlib::rectangle const&, bool) const':
/usr/include/dlib-18.18/dlib/gui_widgets/style.h:527: undefined reference to `dlib::draw_sunken_rectangle(dlib::canvas const&, dlib::rectangle const&, unsigned char)'
bin/fatialfeaturedetect.o: In function `dlib::image_display::disable_overlay_editing()':
/usr/include/dlib-18.18/dlib/gui_widgets/widgets.h:3485: undefined reference to `dlib::base_window::invalidate_rectangle(dlib::rectangle const&)'
bin/fatialfeaturedetect.o: In function `dlib::compress_stream_kernel_1<dlib::entropy_encoder_model_kernel_5<257ul, dlib::entropy_encoder_kernel_2, 200000ul, 4ul>, dlib::entropy_decoder_model_kernel_5<257ul, dlib::entropy_decoder_kernel_2, 200000ul, 4ul>, dlib::crc32>::decompress(std::istream&, std::ostream&) const':
/usr/include/dlib-18.18/dlib/image_processing/../compress_stream/compress_stream_kernel_1.h:180: undefined reference to `dlib::entropy_decoder_kernel_2::entropy_decoder_kernel_2()'
/usr/include/dlib-18.18/dlib/image_processing/../compress_stream/compress_stream_kernel_1.h:181: undefined reference to `dlib::entropy_decoder_kernel_2::set_stream(std::istream&)'
/usr/include/dlib-18.18/dlib/image_processing/../compress_stream/compress_stream_kernel_1.h:196: undefined reference to `dlib::entropy_decoder_kernel_2::get_target(unsigned int)'
/usr/include/dlib-18.18/dlib/image_processing/../compress_stream/compress_stream_kernel_1.h:201: undefined reference to `dlib::entropy_decoder_kernel_2::decode(unsigned int, unsigned int)'
/usr/include/dlib-18.18/dlib/image_processing/../compress_stream/compress_stream_kernel_1.h:243: undefined reference to `dlib::entropy_decoder_kernel_2::~entropy_decoder_kernel_2()'
/usr/include/dlib-18.18/dlib/image_processing/../compress_stream/compress_stream_kernel_1.h:243: undefined reference to `dlib::entropy_decoder_kernel_2::~entropy_decoder_kernel_2()'
bin/fatialfeaturedetect.o: In function `void dlib::image_window::add_overlay<dlib::rgb_pixel>(std::vector<dlib::rectangle, std::allocator<dlib::rectangle> > const&, dlib::rgb_pixel)':
/usr/include/dlib-18.18/dlib/gui_widgets/widgets.h:3968: undefined reference to `dlib::image_window::add_overlay(std::vector<dlib::image_display::overlay_rect, std::allocator<dlib::image_display::overlay_rect> > const&)'
bin/fatialfeaturedetect.o: In function `dlib::image_window::image_window<dlib::array2d<dlib::rgb_pixel, dlib::memory_manager_stateless_kernel_1<char> > >(dlib::array2d<dlib::rgb_pixel, dlib::memory_manager_stateless_kernel_1<char> > const&)':
/usr/include/dlib-18.18/dlib/gui_widgets/widgets.h:3883: undefined reference to `vtable for dlib::image_window'
/usr/include/dlib-18.18/dlib/gui_widgets/widgets.h:3883: undefined reference to `dlib::image_display::image_display(dlib::drawable_window&)'
/usr/include/dlib-18.18/dlib/gui_widgets/widgets.h:3885: undefined reference to `dlib::image_window::on_image_clicked(dlib::vector<long, 2l> const&, bool, unsigned long)'
/usr/include/dlib-18.18/dlib/gui_widgets/widgets.h:3888: undefined reference to `dlib::base_window::show()'
/usr/include/dlib-18.18/dlib/gui_widgets/widgets.h:3883: undefined reference to `dlib::image_display::~image_display()'
bin/fatialfeaturedetect.o: In function `dlib::entropy_decoder_model_kernel_5<257ul, dlib::entropy_decoder_kernel_2, 200000ul, 4ul>::decode(unsigned long&)':
/usr/include/dlib-18.18/dlib/image_processing/../entropy_decoder_model/entropy_decoder_model_kernel_5.h:422: undefined reference to `dlib::entropy_decoder_kernel_2::get_target(unsigned int)'
/usr/include/dlib-18.18/dlib/image_processing/../entropy_decoder_model/entropy_decoder_model_kernel_5.h:456: undefined reference to `dlib::entropy_decoder_kernel_2::decode(unsigned int, unsigned int)'
/usr/include/dlib-18.18/dlib/image_processing/../entropy_decoder_model/entropy_decoder_model_kernel_5.h:503: undefined reference to `dlib::entropy_decoder_kernel_2::decode(unsigned int, unsigned int)'
/usr/include/dlib-18.18/dlib/image_processing/../entropy_decoder_model/entropy_decoder_model_kernel_5.h:551: undefined reference to `dlib::entropy_decoder_kernel_2::get_target(unsigned int)'
/usr/include/dlib-18.18/dlib/image_processing/../entropy_decoder_model/entropy_decoder_model_kernel_5.h:553: undefined reference to `dlib::entropy_decoder_kernel_2::decode(unsigned int, unsigned int)'
bin/fatialfeaturedetect.o: In function `void dlib::image_window::set_image<dlib::array2d<dlib::rgb_pixel, dlib::memory_manager_stateless_kernel_1<char> > >(dlib::array2d<dlib::rgb_pixel, dlib::memory_manager_stateless_kernel_1<char> > const&)':
/usr/include/dlib-18.18/dlib/gui_widgets/widgets.h:3930: undefined reference to `dlib::image_display::get_image_display_rect() const'
/usr/include/dlib-18.18/dlib/gui_widgets/widgets.h:3934: undefined reference to `dlib::base_window::set_size(int, int)'
bin/fatialfeaturedetect.o: In function `void dlib::load_dng<dlib::array2d<dlib::rgb_pixel, dlib::memory_manager_stateless_kernel_1<char> > >(dlib::array2d<dlib::rgb_pixel, dlib::memory_manager_stateless_kernel_1<char> >&, std::istream&)':
/usr/include/dlib-18.18/dlib/image_loader/image_loader.h:585: undefined reference to `dlib::entropy_decoder_kernel_2::entropy_decoder_kernel_2()'
/usr/include/dlib-18.18/dlib/image_loader/image_loader.h:586: undefined reference to `dlib::entropy_decoder_kernel_2::set_stream(std::istream&)'
/usr/include/dlib-18.18/dlib/image_loader/image_loader.h:757: undefined reference to `dlib::entropy_decoder_kernel_2::~entropy_decoder_kernel_2()'
/usr/include/dlib-18.18/dlib/image_loader/image_loader.h:771: undefined reference to `dlib::entropy_decoder_kernel_2::entropy_decoder_kernel_2()'
/usr/include/dlib-18.18/dlib/image_loader/image_loader.h:772: undefined reference to `dlib::entropy_decoder_kernel_2::set_stream(std::istream&)'
/usr/include/dlib-18.18/dlib/image_loader/image_loader.h:771: undefined reference to `dlib::entropy_decoder_kernel_2::~entropy_decoder_kernel_2()'
/usr/include/dlib-18.18/dlib/image_loader/image_loader.h:757: undefined reference to `dlib::entropy_decoder_kernel_2::~entropy_decoder_kernel_2()'
/usr/include/dlib-18.18/dlib/image_loader/image_loader.h:771: undefined reference to `dlib::entropy_decoder_kernel_2::~entropy_decoder_kernel_2()'
bin/fatialfeaturedetect.o: In function `void dlib::image_display::set_image<dlib::array2d<dlib::rgb_pixel, dlib::memory_manager_stateless_kernel_1<char> > >(dlib::array2d<dlib::rgb_pixel, dlib::memory_manager_stateless_kernel_1<char> > const&)':
/usr/include/dlib-18.18/dlib/gui_widgets/widgets.h:3272: undefined reference to `dlib::scrollable_region::set_total_rect_size(unsigned long, unsigned long)'
/usr/include/dlib-18.18/dlib/gui_widgets/widgets.h:3274: undefined reference to `dlib::scrollable_region::set_total_rect_size(unsigned long, unsigned long)'
/usr/include/dlib-18.18/dlib/gui_widgets/widgets.h:3278: undefined reference to `dlib::base_window::invalidate_rectangle(dlib::rectangle const&)'
/usr/include/dlib-18.18/dlib/gui_widgets/widgets.h:3283: undefined reference to `dlib::popup_menu_region::disable()'
bin/fatialfeaturedetect.o: In function `dlib::entropy_decoder_model_kernel_5<256ul, dlib::entropy_decoder_kernel_2, 200000ul, 4ul>::decode(unsigned long&)':
/usr/include/dlib-18.18/dlib/image_processing/../entropy_decoder_model/entropy_decoder_model_kernel_5.h:422: undefined reference to `dlib::entropy_decoder_kernel_2::get_target(unsigned int)'
/usr/include/dlib-18.18/dlib/image_processing/../entropy_decoder_model/entropy_decoder_model_kernel_5.h:456: undefined reference to `dlib::entropy_decoder_kernel_2::decode(unsigned int, unsigned int)'
/usr/include/dlib-18.18/dlib/image_processing/../entropy_decoder_model/entropy_decoder_model_kernel_5.h:503: undefined reference to `dlib::entropy_decoder_kernel_2::decode(unsigned int, unsigned int)'
/usr/include/dlib-18.18/dlib/image_processing/../entropy_decoder_model/entropy_decoder_model_kernel_5.h:551: undefined reference to `dlib::entropy_decoder_kernel_2::get_target(unsigned int)'
/usr/include/dlib-18.18/dlib/image_processing/../entropy_decoder_model/entropy_decoder_model_kernel_5.h:553: undefined reference to `dlib::entropy_decoder_kernel_2::decode(unsigned int, unsigned int)'
bin/fatialfeaturedetect.o: In function `dlib::entropy_decoder_model_kernel_4<256ul, dlib::entropy_decoder_kernel_2, 200000ul, 4ul>::decode(unsigned long&)':
/usr/include/dlib-18.18/dlib/image_processing/../entropy_decoder_model/entropy_decoder_model_kernel_4.h:348: undefined reference to `dlib::entropy_decoder_kernel_2::get_target(unsigned int)'
/usr/include/dlib-18.18/dlib/image_processing/../entropy_decoder_model/entropy_decoder_model_kernel_4.h:376: undefined reference to `dlib::entropy_decoder_kernel_2::decode(unsigned int, unsigned int)'
/usr/include/dlib-18.18/dlib/image_processing/../entropy_decoder_model/entropy_decoder_model_kernel_4.h:422: undefined reference to `dlib::entropy_decoder_kernel_2::decode(unsigned int, unsigned int)'
/usr/include/dlib-18.18/dlib/image_processing/../entropy_decoder_model/entropy_decoder_model_kernel_4.h:469: undefined reference to `dlib::entropy_decoder_kernel_2::get_target(unsigned int)'
/usr/include/dlib-18.18/dlib/image_processing/../entropy_decoder_model/entropy_decoder_model_kernel_4.h:471: undefined reference to `dlib::entropy_decoder_kernel_2::decode(unsigned int, unsigned int)'
collect2: error: ld returned 1 exit status
make: *** [face_frontalization] Error 1
I cant figure out what I have done in linking the library to the project. Please help.
Dlib is partially header-based and some functions need to have libdlib.a linked to a project
You have two ways how to solve your problem:
link to dlib: LDFLAGS = -ldlib (dlib should be installed or its path provided to linker)
add dlib/all/source.cpp to your project sources list(CXXFILES)
If this error is present during compilation with dLib:
/usr/bin/ld: /tmp/ccps6CPH.o: undefined reference to symbol 'pthread_create##GLIBC_2.2.5'
//lib/x86_64-linux-gnu/libpthread.so.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status make: *** [face_frontalization] Error 1
There is a good probability that X11 is missing. I dont know what it is so if somebody does, please tell me. Solution is to just add -lX11 to the LDFLAGS in order to link with it. If you dont want it, you can also specify compiler option -DDLIB_NO_GUI_SUPPORT.
(NOTE: I haven't tested it and dont know what X11 does so better include it than exclude it.)
When I start compiling the code with clang, it seems like libmongoclient doesn't exist. However, I compile the legacy version of mongo-cxx-client on this ubuntu machine. This code is working correctly on my Mac.
clang -lstdc++ -stdlib=libc++ -lcurl -lpthread -ljsoncpp -lboost_system -lboost_regex -lmongoclient -L/usr/lib main.o qqlogin.o fetcher.o -o qq_crawler
this is the code for linking. It didn't make any difference with or without the parameter -lmongoclient. I have already make sure it is under the correct path and the compile are able to search it.
main.o: In function `main':
main.cpp:(.text+0x3b): undefined reference to `mongo::client::Options::Options()'
main.cpp:(.text+0x4b): undefined reference to `mongo::client::GlobalInstance::GlobalInstance(mongo::client::Options const&)'
main.cpp:(.text+0x2d4): undefined reference to `mongo::client::GlobalInstance::~GlobalInstance()'
main.cpp:(.text+0x310): undefined reference to `mongo::client::GlobalInstance::~GlobalInstance()'
main.o: In function `thread_main(threadtool::Threadsafe_queue<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >*)':
main.cpp:(.text+0x343): undefined reference to `mongo::DBClientConnection::DBClientConnection(bool, mongo::DBClientReplicaSet*, double)'
main.o: In function `GCC_except_table14':
main.cpp:(.gcc_except_table+0x258): undefined reference to `typeinfo for mongo::DBException'
main.o: In function `mongo::DBClientConnection::connect(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)':
main.cpp:(.text._ZN5mongo18DBClientConnection7connectERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE[_ZN5mongo18DBClientConnection7connectERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE]+0x116): undefined reference to `mongo::HostAndPort::HostAndPort(mongo::StringData const&)'
main.o: In function `mongo::DBClientConnection::~DBClientConnection()':
main.cpp:(.text._ZN5mongo18DBClientConnectionD2Ev[_ZN5mongo18DBClientConnectionD2Ev]+0x12): undefined reference to `vtable for mongo::DBClientConnection'
main.cpp:(.text._ZN5mongo18DBClientConnectionD2Ev[_ZN5mongo18DBClientConnectionD2Ev]+0x1d): undefined reference to `vtable for mongo::DBClientConnection'
main.cpp:(.text._ZN5mongo18DBClientConnectionD2Ev[_ZN5mongo18DBClientConnectionD2Ev]+0x22): undefined reference to `mongo::DBClientConnection::_numConnections'
main.cpp:(.text._ZN5mongo18DBClientConnectionD2Ev[_ZN5mongo18DBClientConnectionD2Ev]+0xc4): undefined reference to `mongo::DBClientBase::~DBClientBase()'
main.cpp:(.text._ZN5mongo18DBClientConnectionD2Ev[_ZN5mongo18DBClientConnectionD2Ev]+0x15d): undefined reference to `mongo::DBClientBase::~DBClientBase()'
main.o: In function `mongo::DBException::~DBException()':
main.cpp:(.text._ZN5mongo11DBExceptionD2Ev[_ZN5mongo11DBExceptionD2Ev]+0xc): undefined reference to `vtable for mongo::DBException'
main.o: In function `mongo::UserException::UserException(int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)':
main.cpp:(.text._ZN5mongo13UserExceptionC2EiRKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE[_ZN5mongo13UserExceptionC2EiRKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE]+0x30): undefined reference to `vtable for mongo::UserException'
main.o: In function `mongo::DBException::addContext(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)':
main.cpp:(.text._ZN5mongo11DBException10addContextERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE[_ZN5mongo11DBException10addContextERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE]+0x51): undefined reference to `mongo::causedBy(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)'
main.o: In function `mongo::DBException::DBException(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int)':
main.cpp:(.text._ZN5mongo11DBExceptionC2ERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEEi[_ZN5mongo11DBExceptionC2ERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEEi]+0xf): undefined reference to `vtable for mongo::DBException'
main.o:(.rodata._ZTIN5mongo16ConnectExceptionE[_ZTIN5mongo16ConnectExceptionE]+0x10): undefined reference to `typeinfo for mongo::UserException'
main.o:(.rodata._ZTVN5mongo16ConnectExceptionE[_ZTVN5mongo16ConnectExceptionE]+0x30): undefined reference to `mongo::UserException::appendPrefix(std::__1::basic_stringstream<char, std::__1::char_traits<char>, std::__1::allocator<char> >&) const'
main.o:(.rodata._ZTVN5mongo16ConnectExceptionE[_ZTVN5mongo16ConnectExceptionE]+0x40): undefined reference to `mongo::DBException::toString() const'
main.o:(.rodata._ZTVN5mongo18AssertionExceptionE[_ZTVN5mongo18AssertionExceptionE]+0x40): undefined reference to `mongo::DBException::toString() const'
main.o:(.rodata._ZTIN5mongo18AssertionExceptionE[_ZTIN5mongo18AssertionExceptionE]+0x10): undefined reference to `typeinfo for mongo::DBException'
fetcher.o: In function `fetch::Fetcher::parsed_json(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&)':
fetcher.cpp:(.text+0x1e8c): undefined reference to `Json::Reader::parse(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, Json::Value&, bool)'
fetcher.o: In function `mongo::BSONObjBuilder::BSONObjBuilder(int)':
fetcher.cpp:(.text._ZN5mongo14BSONObjBuilderC2Ei[_ZN5mongo14BSONObjBuilderC2Ei]+0x4e): undefined reference to `mongo::BSONObjBuilderValueStream::BSONObjBuilderValueStream(mongo::BSONObjBuilder*)'
fetcher.o: In function `mongo::BSONObjBuilder::append(mongo::StringData const&, mongo::Date_t)':
fetcher.cpp:(.text._ZN5mongo14BSONObjBuilder6appendERKNS_10StringDataENS_6Date_tE[_ZN5mongo14BSONObjBuilder6appendERKNS_10StringDataENS_6Date_tE]+0x29): undefined reference to `mongo::BSONObjBuilder::appendDate(mongo::StringData const&, mongo::Date_t)'
fetcher.o: In function `mongo::BSONObjBuilder::obj()':
fetcher.cpp:(.text._ZN5mongo14BSONObjBuilder3objEv[_ZN5mongo14BSONObjBuilder3objEv]+0x4c): undefined reference to `mongo::msgasserted(int, char const*)'
fetcher.o: In function `mongo::BSONObjBuilder::_done()':
fetcher.cpp:(.text._ZN5mongo14BSONObjBuilder5_doneEv[_ZN5mongo14BSONObjBuilder5_doneEv]+0x62): undefined reference to `mongo::BSONObjBuilderValueStream::endField(mongo::StringData const&)'
fetcher.o: In function `mongo::_BufBuilder<mongo::TrivialAllocator>::claimReservedBytes(int)':
fetcher.cpp:(.text._ZN5mongo11_BufBuilderINS_16TrivialAllocatorEE18claimReservedBytesEi[_ZN5mongo11_BufBuilderINS_16TrivialAllocatorEE18claimReservedBytesEi]+0x52): undefined reference to `mongo::invariantFailed(char const*, char const*, unsigned int)'
fetcher.o: In function `mongo::_BufBuilder<mongo::TrivialAllocator>::grow_reallocate(int)':
fetcher.cpp:(.text._ZN5mongo11_BufBuilderINS_16TrivialAllocatorEE15grow_reallocateEi[_ZN5mongo11_BufBuilderINS_16TrivialAllocatorEE15grow_reallocateEi]+0x663): undefined reference to `mongo::msgasserted(int, char const*)'
fetcher.cpp:(.text._ZN5mongo11_BufBuilderINS_16TrivialAllocatorEE15grow_reallocateEi[_ZN5mongo11_BufBuilderINS_16TrivialAllocatorEE15grow_reallocateEi]+0x6ed): undefined reference to `mongo::msgasserted(int, char const*)'
fetcher.o: In function `mongo::checkFieldName(mongo::StringData)':
fetcher.cpp:(.text._ZN5mongo14checkFieldNameENS_10StringDataE[_ZN5mongo14checkFieldNameENS_10StringDataE]+0x56): undefined reference to `mongo::uasserted(int, char const*)'
fetcher.o: In function `mongo::_BufBuilder<mongo::TrivialAllocator>::_BufBuilder(int)':
fetcher.cpp:(.text._ZN5mongo11_BufBuilderINS_16TrivialAllocatorEEC2Ei[_ZN5mongo11_BufBuilderINS_16TrivialAllocatorEEC2Ei]+0x5e): undefined reference to `mongo::msgasserted(int, char const*)'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [qq_crawler] Error 1
Put your object files before the libraries:
clang -stdlib=libc++ main.o qqlogin.o fetcher.o -L/usr/lib -lcurl -lpthread
-ljsoncpp -lboost_system -lboost_regex -lmongoclient -o qq_crawler
I've used the already compiled version of openCV for Raspberry Pi. link for anyone who is interested
After trying to compile using this command line
g++ test3.cpp -o test3 -I/usr/local/include/ -lraspicam -lraspicam_cv -L/opt/vc/lib -lmmal -lmmal_core -lmmal_util -I/usr/include -lopencv_core -lopencv_highgui -lopencv_imgproc -lwiringPi -lpthread
I get the following error lines.
//usr/local/lib/libopencv_stitching.so.2.4: undefined reference to `cv::gpu::ensureSizeIsEnough(int, int, int, cv::gpu::GpuMat&)'
//usr/local/lib/libopencv_calib3d.so.2.4: undefined reference to `cv::parallel_for_(cv::Range const&, cv::ParallelLoopBody const&, double)'
//usr/local/lib/libopencv_calib3d.so.2.4: undefined reference to `typeinfo for cv::ParallelLoopBody'
//usr/local/lib/libopencv_calib3d.so.2.4: undefined reference to `cv::Mutex::unlock()'
//usr/local/lib/libopencv_calib3d.so.2.4: undefined reference to `cv::Mutex::lock()'
//usr/local/lib/libopencv_ocl.so.2.4: undefined reference to cv::TLSDataContainer::getData() const
//usr/local/lib/libopencv_features2d.so.2.4: undefined reference to cv::AlgorithmInfo::addParam(cv::Algorithm&, char const*, unsigned char&, bool, unsigned char (cv::Algorithm::)(), void (cv::Algorithm::)(unsigned char), std::basic_string, std::allocator > const&)
//usr/local/lib/libopencv_features2d.so.2.4: undefined reference to `cv::AlgorithmInfo::addParam(cv::Algorithm&, char const*, float&, bool, float (cv::Algorithm::)(), void (cv::Algorithm::)(float), std::basic_string, std::allocator > const&)'
//usr/local/lib/libopencv_features2d.so.2.4: undefined reference to `cv::AlgorithmInfo::addParam(cv::Algorithm&, char const*, short&, bool, int (cv::Algorithm::)(), void (cv::Algorithm::)(int), std::basic_string, std::allocator > const&)'
//usr/local/lib/libopencv_calib3d.so.2.4: undefined reference to `cv::Mutex::Mutex()'
//usr/local/lib/libopencv_ocl.so.2.4: undefined reference to `cv::TLSDataContainer::TLSDataContainer()'
//usr/local/lib/libopencv_calib3d.so.2.4: undefined reference to `cv::ParallelLoopBody::~ParallelLoopBody()'
//usr/local/lib/libopencv_calib3d.so.2.4: undefined reference to `cv::Mutex::~Mutex()'
//usr/local/lib/libopencv_ocl.so.2.4: undefined reference to `cv::TLSDataContainer::~TLSDataContainer()'
collect2: ld returned 1 exit status
You have not linked the executable against several libraries that are required by the program
Try using this:
g++ -lpthread `pkg-config opencv --libs` -I/usr/local/include/ -lraspicam -lraspicam_cv -L/opt/vc/lib -lmmal -lmmal_core -lmmal_util -I/usr/include -lwiringPi test3.cpp -o test3