Makefile错误导致对符号的未定义引用' GOMP_parallel @@ GOMP_4.0'

时间:2016-11-04 16:59:39

标签: c++ makefile g++ ld opencv3.1

警告:新手Ubuntu / g ++ / makefile用户

我正在尝试构建一个C ++应用程序(C ++ 11,OpenMP,OpenCV3,实验性文件系统),如果我直接构建,它可以工作,但如果我使用带有链接器错误的makefile则会失败。

这有效:

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

但是我的makefile产生了这个,并且失败了:

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

这是我的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

1 个答案:

答案 0 :(得分:2)

您需要与-fopenmp相关联。您的makefile不在链接器步骤上提供该标志。只需将-fopenmp添加到LDFLAGS

即可

所有未构建文件的规则都应标明为.PHONY