如何解决在Webots中使用OpenCV时如何解决链接器错误
我必须在项目中使用opencv,然后编辑opencv的makefile。但是它给出了“未定义的引用”错误。如果我不使用任何opencv函数,则代码正在编译和链接。我正在使用opencv版本4.4。我提取了机械手代码以简化问题。这是我的源代码和makefile。
#include <math.h>
#include <iostream>
#include <webots/motor.hpp>
#include <webots/robot.hpp>
#include <opencv2/opencv.hpp>
#define TIME_STEP 64
#define NUM_PISTONS 6
using namespace webots;
using namespace cv;
// main program
int main(int argc,char **argv) {
// Testing if opencv works.
Mat img = imread("lena.png");
namedWindow("image",WINDOW_NORMAL);
imshow("image",img);
waitKey(0);
return 0;
}
这是makefile。
null :=
space := $(null) $(null)
WEBOTS_HOME_PATH=$(subst $(space),\,$(strip $(subst \,/,$(WEBOTS_HOME))))
include $(WEBOTS_HOME_PATH)/resources/Makefile.os.include
### USE_C_API = true
# define the opencv installation directory if not set in an environment variable
OPENCV_DIR = C:/opencv/build
ifneq ($(OPENCV_DIR),)
INCLUDE = -I$(OPENCV_DIR)/include
ifeq ($(OSTYPE),windows)
OPENCV_VERSION := $(subst .,$(shell $(OPENCV_DIR)/x64/vc15/bin/opencv_version.exe))
LIBRARIES = -L$(OPENCV_DIR)/x64/vc15/lib -lopencv_world440 -lopencv_world440d
else
LIBRARIES = -L"$(OPENCV_DIR)/x64/vc15/lib" -lopencv_world440 -lopencv_world440d
endif
# Do not modify the following: this includes Webots global Makefile.include
include $(WEBOTS_HOME_PATH)/resources/Makefile.include
else
release debug profile clean:
@+echo "# opencv not installed,skipping vision controller."
endif
编辑:我正在使用Windows 10,并且已安装opencv已构建版本。 Visual Studio可以运行opencv,但即使我设置了库并正确包含文件,我们的机器人自己的环境也无法运行。
错误消息:
C:/Program Files/Webots/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: build/release/bouncer2.o:bouncer2.cpp:(.text$_ZN2cv3MatD1Ev[_ZN2cv3MatD1Ev]+0x5e): undefined reference to `cv::fastFree(void*)'
C:/Program Files/Webots/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: build/release/bouncer2.o:bouncer2.cpp:(.text$_ZN2cv3MatD1Ev[_ZN2cv3MatD1Ev]+0x71): undefined reference to `cv::Mat::deallocate()'
C:/Program Files/Webots/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: build/release/bouncer2.o:bouncer2.cpp:(.text.startup+0x6b): undefined reference to `cv::imread(std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char> > const&,int)'
C:/Program Files/Webots/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: build/release/bouncer2.o:bouncer2.cpp:(.text.startup+0x9e): undefined reference to `cv::namedWindow(std::__cxx11::basic_string<char,int)'
C:/Program Files/Webots/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: build/release/bouncer2.o:bouncer2.cpp:(.text.startup+0xe7): undefined reference to `cv::imshow(std::__cxx11::basic_string<char,cv::_InputArray const&)'
C:/Program Files/Webots/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: build/release/bouncer2.o:bouncer2.cpp:(.text.startup+0x100): undefined reference to `cv::waitKey(int
)'
collect2.exe: error: ld returned 1 exit status
make: *** [C:/Program Files/Webots/resources/Makefile.include:484: build/release/bouncer2.exe] Error 1
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。