2016-11-04 106 views
2

警告:新手的Ubuntu /克++ /生成文件的用戶生成文件錯誤導致未定義的參考符號 'GOMP_parallel @@ GOMP_4.0'

我試圖建立一個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 '[email protected]@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 
+0

您應該注意,排列庫的順序對於鏈接 –

回答

1

您需要-fopenmp鏈接。您的makefile不會在鏈接器步驟中提供該標誌。只需在您的LDFLAGS上添加-fopenmp即可。


所有不是建築文件的規則都應該顯示爲.PHONY

+0

很重要,這會導致未解析的'__gcov_indirect_call_profiler_v2','_'__gcov_indirect_call_callee'和'__gcov_time_profiler'等等。有沒有辦法診斷這些依賴關係? – cdmh

+0

@cdmh同樣的想法 - 你的gcov相關標誌需要傳遞給鏈接器。 – Barry

+0

僅供參考,'-fprofile-generate'正在導致gcov錯誤。另外,'-lstdC++ fs'應該是一個鏈接器標誌,而不是編譯器標誌。 – cdmh

相關問題