Warning: Newbie Ubuntu/g++/makefile user
I'm trying to build a C++ app (C++11, OpenMP, OpenCV3, experimental filesystem) that works if I build directly, but fails if I use a makefile
with a linker error.
This works:
g++ \
-std=c++11 -std=c++1y -fopenmp -DNDEBUG \
-O3 -fprofile-generate -march=native -fomit-frame-pointer \
docproc.cpp \
-flto -L/usr/local/lib -lstdc++fs \
-lpthread -lboost_thread -lboost_system \
-lopencv_aruco -lopencv_bgsegm -lopencv_bioinspired -lopencv_calib3d -lopencv_ccalib -lopencv_core -lopencv_datasets -lopencv_dnn -lopencv_dpm -lopencv_face -lopencv_features2d -lopencv_flann -lopencv_fuzzy -lopencv_highgui -lopencv_imgcodecs -lopencv_imgproc -lopencv_line_descriptor -lopencv_ml -lopencv_objdetect -lopencv_optflow -lopencv_photo -lopencv_plot -lopencv_reg -lopencv_rgbd -lopencv_saliency -lopencv_shape -lopencv_stereo -lopencv_stitching -lopencv_structured_light -lopencv_superres -lopencv_surface_matching -lopencv_text -lopencv_tracking -lopencv_xfeatures2d -lopencv_ximgproc -lopencv_xobjdetect -lopencv_xphoto
But my makefile
produces this, and fails:
g++ -g -L/usr/local/lib -o docproc docproc.o taina.o logging.o \
-lpthread -lboost_thread -lboost_system \
-lopencv_aruco -lopencv_bgsegm -lopencv_bioinspired -lopencv_calib3d -lopencv_ccalib -lopencv_core -lopencv_datasets -lopencv_dnn -lopencv_dpm -lopencv_face -lopencv_features2d -lopencv_flann -lopencv_fuzzy -lopencv_highgui -lopencv_imgcodecs -lopencv_imgproc -lopencv_line_descriptor -lopencv_ml -lopencv_objdetect -lopencv_optflow -lopencv_photo -lopencv_plot -lopencv_reg -lopencv_rgbd -lopencv_saliency -lopencv_shape -lopencv_stereo -lopencv_stitching -lopencv_structured_light -lopencv_superres -lopencv_surface_matching -lopencv_text -lopencv_tracking -lopencv_xfeatures2d -lopencv_ximgproc -lopencv_xobjdetect -lopencv_xphoto
/usr/bin/ld: /tmp/ccNDMpfK.ltrans2.ltrans.o: undefined reference to symbol 'GOMP_parallel@@GOMP_4.0'
//usr/lib/x86_64-linux-gnu/libgomp.so.1: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
Here's my makefile
CC=gcc
CXX=g++
RM=rm -f
CPPCONFIG=-std=c++11 -std=c++1y -fopenmp -flto -lstdc++fs -DNDEBUG
CPP_OPT=-O3 -fprofile-generate -march=native -fomit-frame-pointer
CPPFLAGS=-g $(CPPCONFIG) $(CPP_OPT)
THREAD_LIBS=-lpthread -lboost_thread -lboost_system
OPENCV_LIBS=-lopencv_aruco -lopencv_bgsegm -lopencv_bioinspired -lopencv_calib3d -lopencv_ccalib -lopencv_core -lopencv_datasets -lopencv_dnn -lopencv_dpm -lopencv_face -lopencv_features2d -lopencv_flann -lopencv_fuzzy -lopencv_highgui -lopencv_imgcodecs -lopencv_imgproc -lopencv_line_descriptor -lopencv_ml -lopencv_objdetect -lopencv_optflow -lopencv_photo -lopencv_plot -lopencv_reg -lopencv_rgbd -lopencv_saliency -lopencv_shape -lopencv_stereo -lopencv_stitching -lopencv_structured_light -lopencv_superres -lopencv_surface_matching -lopencv_text -lopencv_tracking -lopencv_xfeatures2d -lopencv_ximgproc -lopencv_xobjdetect -lopencv_xphoto
LDFLAGS=-g -L/usr/local/lib
LDLIBS=$(THREAD_LIBS) $(OPENCV_LIBS)
SRCS=docproc.cpp taina.cpp logging.cpp
OBJS=$(subst .cpp,.o,$(SRCS))
all: docproc
docproc: $(OBJS)
$(CXX) $(LDFLAGS) -o docproc $(OBJS) $(LDLIBS)
depend: .depend
.depend: $(SRCS)
rm -f ./.depend
$(CXX) $(CPPFLAGS) -MM $^>>./.depend;
clean:
$(RM) $(OBJS)
dist-clean: clean
$(RM) *~ .depend
include .depend