gpt4 book ai didi

c++ - MakeFile 中的 "undefined reference to"

转载 作者:太空宇宙 更新时间:2023-11-04 05:28:05 24 4
gpt4 key购买 nike

我是 MakeFile 的菜鸟。我已经阅读了 stackoverflow 上所有类似的帖子。但仍然不知道该怎么做(我确信这是一个 MakeFile 问题,因为我可以用 XCode 运行它)。这是我的 MakeFile 和错误消息:

####### Detect system architecture

SYSARCH = i386
ifeq ($(shell uname -m),x86_64)
SYSARCH = x86_64
endif

####### Compiler, tools and options

CXX = g++
LINK = g++
MAKE = make
DELETEFILE = rm -f
DELETEDIR = rm -Rf
DEFINES = -DQT_WEBKIT -DGL_GLEXT_PROTOTYPES
COMMONFLAGS = -Wall -Wextra -pipe -msse2 -Wno-reorder
#-Werror
####### Detect debug or release

DEBUG ?= 0
CXXFLAGS ?=
ifeq ($(DEBUG), 1)
CXXFLAGS += $(COMMONFLAGS) -DDEBUG -DOVR_BUILD_DEBUG -g $(DEFINES)
RELEASETYPE ?= Debug
LFLAGS =
else
CXXFLAGS += $(COMMONFLAGS) -O2 $(DEFINES)
RELEASETYPE ?= Release
LFLAGS = -O1 # Why O1?
endif

####### Paths

OCULUSWORLDPATH = .
LIBOVRPATH = ../../LibOVR
COMMONSRCPATH = ../CommonSrc
3RDPARTYPATH = ../../3rdParty
INCPATH = -I. -I.. -I$(COMMONSRCPATH) -I$(LIBOVRPATH)/Include -I$(LIBOVRPATH)/Src
OBJPATH = ./Obj/Linux/$(RELEASETYPE)/$(SYSARCH)
CXX_BUILD = $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $(OBJPATH)/

####### Files

LIBS = -L$(LIBOVRPATH)/Lib/Linux/$(RELEASETYPE)/$(SYSARCH) \
-lovr \
-ludev \
-lpthread \
-lGL \
-lX11 \
-lXrandr \
-lrt

TARGET = ./Release/OculusWorldDemo_$(SYSARCH)_$(RELEASETYPE)

####### Rules

all: $(TARGET)

OCULUSWORLD_SOURCE = $(OCULUSWORLDPATH)/OculusWorldDemo.cpp \
$(OCULUSWORLDPATH)/OculusWorldDemo_Scene.cpp \
$(OCULUSWORLDPATH)/Player.cpp \
$(OCULUSWORLDPATH)/../CommonSrc/Util/RenderProfiler.cpp \
$(OCULUSWORLDPATH)/../CommonSrc/Util/OptionMenu.cpp \
$(OCULUSWORLDPATH)/../CommonSrc/Platform/Linux_Gamepad.cpp \
$(OCULUSWORLDPATH)/../CommonSrc/Platform/Linux_Platform.cpp \
$(OCULUSWORLDPATH)/../CommonSrc/Platform/Platform.cpp \
$(OCULUSWORLDPATH)/../CommonSrc/Render/Render_Device.cpp \
$(OCULUSWORLDPATH)/../CommonSrc/Render/Render_GL_Device.cpp \
$(OCULUSWORLDPATH)/../CommonSrc/Render/Render_LoadTextureDDS.cpp \
$(OCULUSWORLDPATH)/../CommonSrc/Render/Render_LoadTextureTGA.cpp \
$(OCULUSWORLDPATH)/../CommonSrc/Render/Render_XmlSceneLoader.cpp \
$(OCULUSWORLDPATH)/../../3rdParty/TinyXml/tinyxml2.cpp

OCULUSWORLD_OBJECTS = $(patsubst $(OCULUSWORLDPATH)%.cpp,$(OBJPATH)%.o,$(OCULUSWORLD_SOURCE))

OBJECTS = $(OTHER_OBJECTS) $(OCULUSWORLD_OBJECTS)

$(OBJPATH)/%.o: %.cpp
-mkdir -p $(dir $@)
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<

$(LIBOVRPATH)/Lib/Linux/$(RELEASETYPE)/$(SYSARCH)/libovr.a:
$(MAKE) -C $(LIBOVRPATH) DEBUG=$(DEBUG)

lib: $(LIBOVRPATH)/Lib/Linux/$(RELEASETYPE)/$(SYSARCH)/libovr.a

run: $(TARGET)
$(TARGET)

$(TARGET): $(OBJECTS) lib
-mkdir -p $(dir $@)
$(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(LIBS)

clean:
-$(DELETEFILE) $(OBJECTS)
-$(DELETEFILE) $(TARGET)

cleanall:
-$(DELETEFILE) $(OBJECTS)
-$(DELETEDIR) ./Release/*
<小时/>
xxx:~/Desktop/ing$ make
true
make -C ./LibOVR
make[1]: Entering directory `/home/bosch3d/Desktop/ing/LibOVR'
make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `/home/bosch3d/Desktop/ing/LibOVR'
make -C ./Samples/OculusWorldDemo
make[1]: Entering directory `/home/bosch3d/Desktop/ing/Samples/OculusWorldDemo'
mkdir -p Release/
g++ -O1 -o ./Release/OculusWorldDemo_x86_64_Release ./Obj/Linux/Release/x86_64/OculusWorldDemo.o ./Obj/Linux/Release/x86_64/OculusWorldDemo_Scene.o ./Obj/Linux/Release/x86_64/Player.o ./Obj/Linux/Release/x86_64/../CommonSrc/Util/RenderProfiler.o ./Obj/Linux/Release/x86_64/../CommonSrc/Util/OptionMenu.o ./Obj/Linux/Release/x86_64/../CommonSrc/Platform/Linux_Gamepad.o ./Obj/Linux/Release/x86_64/../CommonSrc/Platform/Linux_Platform.o ./Obj/Linux/Release/x86_64/../CommonSrc/Platform/Platform.o ./Obj/Linux/Release/x86_64/../CommonSrc/Render/Render_Device.o ./Obj/Linux/Release/x86_64/../CommonSrc/Render/Render_GL_Device.o ./Obj/Linux/Release/x86_64/../CommonSrc/Render/Render_LoadTextureDDS.o ./Obj/Linux/Release/x86_64/../CommonSrc/Render/Render_LoadTextureTGA.o ./Obj/Linux/Release/x86_64/../CommonSrc/Render/Render_XmlSceneLoader.o ./Obj/Linux/Release/x86_64/../../3rdParty/TinyXml/tinyxml2.o -L../../LibOVR/Lib/Linux/Release/x86_64 -lovr -ludev -lpthread -lGL -lX11 -lXrandr -lrt
./Obj/Linux/Release/x86_64/OculusWorldDemo.o: In function `OculusWorldDemoApp::~OculusWorldDemoApp()':
OculusWorldDemo.cpp:(.text+0x756): undefined reference to `cv::fastFree(void*)'
OculusWorldDemo.cpp:(.text+0x7d6): undefined reference to `cv::fastFree(void*)'
OculusWorldDemo.cpp:(.text+0x836): undefined reference to `cv::Mat::deallocate()'
OculusWorldDemo.cpp:(.text+0x843): undefined reference to `cv::Mat::deallocate()'
./Obj/Linux/Release/x86_64/OculusWorldDemo.o: In function `OculusWorldDemoApp::RenderEyeView(ovrEyeType)':
OculusWorldDemo.cpp:(.text+0x9064): undefined reference to `ReadDataRunML::run(bool)'
./Obj/Linux/Release/x86_64/OculusWorldDemo.o: In function `cv::Mat::~Mat()':
OculusWorldDemo.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x89): undefined reference to `cv::Mat::deallocate()'
OculusWorldDemo.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x79): undefined reference to `cv::fastFree(void*)'
./Obj/Linux/Release/x86_64/OculusWorldDemo.o: In function `ReadDataRunML::~ReadDataRunML()':
OculusWorldDemo.cpp:(.text._ZN13ReadDataRunMLD2Ev[_ZN13ReadDataRunMLD5Ev]+0xa6): undefined reference to `cv::fastFree(void*)'
OculusWorldDemo.cpp:(.text._ZN13ReadDataRunMLD2Ev[_ZN13ReadDataRunMLD5Ev]+0x120): undefined reference to `cv::fastFree(void*)'
OculusWorldDemo.cpp:(.text._ZN13ReadDataRunMLD2Ev[_ZN13ReadDataRunMLD5Ev]+0x144): undefined reference to `cv::Mat::deallocate()'
OculusWorldDemo.cpp:(.text._ZN13ReadDataRunMLD2Ev[_ZN13ReadDataRunMLD5Ev]+0x154): undefined reference to `cv::Mat::deallocate()'
./Obj/Linux/Release/x86_64/OculusWorldDemo.o: In function `ReadDataRunML::ReadDataRunML(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int, double, int, int)':
OculusWorldDemo.cpp:(.text._ZN13ReadDataRunMLC2ESsidii[_ZN13ReadDataRunMLC5ESsidii]+0x1a3): undefined reference to `cv::String::allocate(unsigned long)'
OculusWorldDemo.cpp:(.text._ZN13ReadDataRunMLC2ESsidii[_ZN13ReadDataRunMLC5ESsidii]+0x1eb): undefined reference to `cv::ml::TrainData::loadFromCSV(cv::String const&, int, int, int, cv::String const&, char, char)'
OculusWorldDemo.cpp:(.text._ZN13ReadDataRunMLC2ESsidii[_ZN13ReadDataRunMLC5ESsidii]+0x1f8): undefined reference to `cv::String::deallocate()'
OculusWorldDemo.cpp:(.text._ZN13ReadDataRunMLC2ESsidii[_ZN13ReadDataRunMLC5ESsidii]+0x20b): undefined reference to `cv::String::deallocate()'
OculusWorldDemo.cpp:(.text._ZN13ReadDataRunMLC2ESsidii[_ZN13ReadDataRunMLC5ESsidii]+0x2ec): undefined reference to `cv::fastFree(void*)'
OculusWorldDemo.cpp:(.text._ZN13ReadDataRunMLC2ESsidii[_ZN13ReadDataRunMLC5ESsidii]+0x3db): undefined reference to `cv::Mat::copySize(cv::Mat const&)'
OculusWorldDemo.cpp:(.text._ZN13ReadDataRunMLC2ESsidii[_ZN13ReadDataRunMLC5ESsidii]+0x4c7): undefined reference to `cv::fastFree(void*)'
OculusWorldDemo.cpp:(.text._ZN13ReadDataRunMLC2ESsidii[_ZN13ReadDataRunMLC5ESsidii]+0x5bf): undefined reference to `cv::Mat::copySize(cv::Mat const&)'
OculusWorldDemo.cpp:(.text._ZN13ReadDataRunMLC2ESsidii[_ZN13ReadDataRunMLC5ESsidii]+0x6b8): undefined reference to `cv::fastFree(void*)'
OculusWorldDemo.cpp:(.text._ZN13ReadDataRunMLC2ESsidii[_ZN13ReadDataRunMLC5ESsidii]+0x6c7): undefined reference to `cv::Formatter::get(int)'
OculusWorldDemo.cpp:(.text._ZN13ReadDataRunMLC2ESsidii[_ZN13ReadDataRunMLC5ESsidii]+0x7c1): undefined reference to `cv::Mat::deallocate()'
OculusWorldDemo.cpp:(.text._ZN13ReadDataRunMLC2ESsidii[_ZN13ReadDataRunMLC5ESsidii]+0x861): undefined reference to `cv::Mat::deallocate()'
OculusWorldDemo.cpp:(.text._ZN13ReadDataRunMLC2ESsidii[_ZN13ReadDataRunMLC5ESsidii]+0x86e): undefined reference to `cv::Mat::deallocate()'
OculusWorldDemo.cpp:(.text._ZN13ReadDataRunMLC2ESsidii[_ZN13ReadDataRunMLC5ESsidii]+0x882): undefined reference to `cv::Mat::deallocate()'
OculusWorldDemo.cpp:(.text._ZN13ReadDataRunMLC2ESsidii[_ZN13ReadDataRunMLC5ESsidii]+0x88f): undefined reference to `cv::Mat::deallocate()'
OculusWorldDemo.cpp:(.text._ZN13ReadDataRunMLC2ESsidii[_ZN13ReadDataRunMLC5ESsidii]+0x929): undefined reference to `cv::String::deallocate()'
OculusWorldDemo.cpp:(.text._ZN13ReadDataRunMLC2ESsidii[_ZN13ReadDataRunMLC5ESsidii]+0x975): undefined reference to `cv::String::deallocate()'
collect2: ld returned 1 exit status
make[1]: *** [Release/OculusWorldDemo_x86_64_Release] Error 1
make[1]: Leaving directory `/home/bosch3d/Desktop/ing/Samples/OculusWorldDemo'
make: *** [Samples/OculusWorldDemo/Release/OculusWorldDemo_x86_64_Release] Error 2
xxx:~/Desktop/ing$

我添加了:

-lopencv_core \
-lopencv_highgui \
-lopencv_imgproc \
-lopencv_video \
-lopencv_objdetect \

现在的错误是:

./Obj/Linux/Release/x86_64/OculusWorldDemo.o: In function `OculusWorldDemoApp::RenderEyeView(ovrEyeType)':
OculusWorldDemo.cpp:(.text+0x9064): undefined reference to `ReadDataRunML::run(bool)'
./Obj/Linux/Release/x86_64/OculusWorldDemo.o: In function `ReadDataRunML::ReadDataRunML(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int, double, int, int)':
OculusWorldDemo.cpp:(.text._ZN13ReadDataRunMLC2ESsidii[_ZN13ReadDataRunMLC5ESsidii]+0x1eb): undefined reference to `cv::ml::TrainData::loadFromCSV(cv::String const&, int, int, int, cv::String const&, char, char)'
collect2: ld returned 1 exit status
make[1]: *** [Release/OculusWorldDemo_x86_64_Release] Error 1
make[1]: Leaving directory `/home/bosch3d/Desktop/ing/Samples/OculusWorldDemo'
make: *** [Samples/OculusWorldDemo/Release/OculusWorldDemo_x86_64_Release] Error 2

ReadDataRunML是我自己添加的一个类。我应该如何将它添加到MakeFile?

最佳答案

您需要将 opencv 库添加到您链接的库列表中:

添加到 MakeFile 的 LIBS 部分:

-lopencv_core \

并且,根据您使用的 opencv 功能,您可能需要以下一项或多项:

-lopencv_highgui \
-lopencv_imgproc \
-lopencv_video \
-lopencv_objdetect \

未解析的外部只是因为链接器不知道在哪里寻找它们。另外,请确保您的 opencv 库路径位于您的 lib 路径中或将其添加到链接器使用的 libpath 中。您可以使用 -L 选项添加到库路径,例如-LMyLocalPathToOpenCV (您可能需要定义它并使用宏来引用它,而不是在将其添加到链接器选项的位置进行硬编码,以保持 makefile 更清晰,例如 $(OPENCV_LIB_PATH))。

关于c++ - MakeFile 中的 "undefined reference to",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28140318/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com