Makefile 错误导致对符号 'GOMP_parallel@@GOMP_4.0' 的未定义引用
Makefile error causes undefined reference to symbol 'GOMP_parallel@@GOMP_4.0'
警告:新手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
您需要 link 和 -fopenmp
。您的 makefile 没有在 linker 步骤中提供该标志。只需将 -fopenmp
添加到您的 LDFLAGS
.
所有不构建文件的规则都应表示为 .PHONY
。
警告:新手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
您需要 link 和 -fopenmp
。您的 makefile 没有在 linker 步骤中提供该标志。只需将 -fopenmp
添加到您的 LDFLAGS
.
所有不构建文件的规则都应表示为 .PHONY
。