[英]OpenCV 2.3 doesn't compile, undefined reference error
I'm using OpenCV in Windows 7 64bits and Netbeans 7.0.我在 Windows 7 64 位和 Netbeans 7.0 中使用 OpenCV。 I tried to compile the next code using MinGW and cygwin but both fails with undefined references.
我尝试使用 MinGW 和 cygwin 编译下一个代码,但都因未定义的引用而失败。
When I use MAT or FLANN and others I can't compile, but I'm adding all libraries (I tried only adding Debug ones, Release ones, only needed ones... but fails).当我使用 MAT 或 FLANN 等时,我无法编译,但我正在添加所有库(我尝试仅添加调试库、发布库、仅需要的库……但失败了)。
The same code in ubuntu works, but I need to compile it in windows too. ubuntu 中的相同代码可以工作,但我也需要在 windows 中编译它。 I'm using the 2.3 compiled version (using CMake) and the installable one.
我正在使用 2.3 编译版本(使用 CMake)和可安装版本。
#include "opencv2\opencv.hpp"
#include <iostream>
using namespace std;
int main(void)
{
cv::Mat::eye(1, 1, 0);
return 0;
}
"/usr/bin/make" -f nbproject/Makefile-Release.mk QMAKE= SUBPROJECTS= .clean-conf
make[1]: Entering directory `/cygdrive/f/Proyectos/C++/OpenCV23Sandbox'
rm -f -r build/Release
rm -f dist/Release/Cygwin-Windows/opencv23sandbox.exe
make[1]: Leaving directory `/cygdrive/f/Proyectos/C++/OpenCV23Sandbox'
CLEAN SUCCESSFUL (total time: 1s)
"/usr/bin/make" -f nbproject/Makefile-Release.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory `/cygdrive/f/Proyectos/C++/OpenCV23Sandbox'
"/usr/bin/make" -f nbproject/Makefile-Release.mk dist/Release/Cygwin-Windows/opencv23sandbox.exe
make[2]: Entering directory `/cygdrive/f/Proyectos/C++/OpenCV23Sandbox'
mkdir -p build/Release/Cygwin-Windows
rm -f build/Release/Cygwin-Windows/main.o.d
g++.exe -c -O2 -I/cygdrive/C/OpenCV2.3/build/include -MMD -MP -MF build/Release/Cygwin-Windows/main.o.d -o build/Release/Cygwin-Windows/main.o main.cpp
mkdir -p dist/Release/Cygwin-Windows
g++.exe -o dist/Release/Cygwin-Windows/opencv23sandbox build/Release/Cygwin-Windows/main.o -L/cygdrive/C/OpenCV2.3/build/x86/vc10/lib -lopencv_calib3d230 -lopencv_calib3d230d -lopencv_contrib230 -lopencv_contrib230d -lopencv_core230 -lopencv_core230d -lopencv_features2d230 -lopencv_features2d230d -lopencv_flann230 -lopencv_flann230d -lopencv_gpu230 -lopencv_gpu230d -lopencv_haartraining_engine -lopencv_haartraining_engined -lopencv_highgui230 -lopencv_highgui230d -lopencv_imgproc230 -lopencv_imgproc230d -lopencv_legacy230 -lopencv_legacy230d -lopencv_ml230 -lopencv_ml230d -lopencv_objdetect230 -lopencv_objdetect230d -lopencv_video230 -lopencv_video230d
build/Release/Cygwin-Windows/main.o:main.cpp:(.text+0xac): undefined reference to `cv::Mat::eye(int, int, int)'
build/Release/Cygwin-Windows/main.o:main.cpp:(.text+0x106): undefined reference to `cv::fastFree(void*)'
build/Release/Cygwin-Windows/main.o:main.cpp:(.text+0x16f): undefined reference to `cv::fastFree(void*)'
build/Release/Cygwin-Windows/main.o:main.cpp:(.text+0x1dd): undefined reference to `cv::fastFree(void*)'
build/Release/Cygwin-Windows/main.o:main.cpp:(.text+0x1fa): undefined reference to `cv::Mat::deallocate()'
build/Release/Cygwin-Windows/main.o:main.cpp:(.text+0x20a): undefined reference to `cv::Mat::deallocate()'
build/Release/Cygwin-Windows/main.o:main.cpp:(.text+0x21a): undefined reference to `cv::Mat::deallocate()'
build/Release/Cygwin-Windows/main.o:main.cpp:(.text$_ZN2cv3MatD1Ev[cv::Mat::~Mat()]+0x66): undefined reference to `cv::Mat::deallocate()'
build/Release/Cygwin-Windows/main.o:main.cpp:(.text$_ZN2cv3MatD1Ev[cv::Mat::~Mat()]+0x5e): undefined reference to `cv::fastFree(void*)'
collect2: ld returned 1make[2]: Leaving directory `/cygdrive/f/Proyectos/C++/OpenCV23Sandbox'
make[1]: Leaving directory `/cygdrive/f/Proyectos/C++/OpenCV23Sandbox'
exit status
make[2]: *** [dist/Release/Cygwin-Windows/opencv23sandbox.exe] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 2s)
Trying with MinGW libs:尝试使用 MinGW 库:
"/bin/make" -f nbproject/Makefile-Release.mk QMAKE= SUBPROJECTS= .clean-conf
make[1]: Entering directory `/f/Proyectos/C++/OpenCV23Sandbox'
rm -f -r build/Release
rm -f dist/Release/MinGW-Windows/opencv23sandbox.exe
make[1]: Leaving directory `/f/Proyectos/C++/OpenCV23Sandbox'
CLEAN SUCCESSFUL (total time: 350ms)
"/bin/make" -f nbproject/Makefile-Release.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory `/f/Proyectos/C++/OpenCV23Sandbox'
"/bin/make" -f nbproject/Makefile-Release.mk dist/Release/MinGW-Windows/opencv23sandbox.exe
make[2]: Entering directory `/f/Proyectos/C++/OpenCV23Sandbox'
mkdir -p build/Release/MinGW-Windows
rm -f build/Release/MinGW-Windows/main.o.d
g++.exe -c -O2 -I/C/OpenCV2.3/build/include -MMD -MP -MF build/Release/MinGW-Windows/main.o.d -o build/Release/MinGW-Windows/main.o main.cpp
mkdir -p dist/Release/MinGW-Windows
g++.exe -o dist/Release/MinGW-Windows/opencv23sandbox build/Release/MinGW-Windows/main.o -L../OpenCV/OpenCV2.3/build/x86/mingw/lib ../OpenCV/OpenCV2.3/build/x86/mingw/lib/libopencv_calib3d230.dll.a ../OpenCV/OpenCV2.3/build/x86/mingw/lib/libopencv_contrib230.dll.a ../OpenCV/OpenCV2.3/build/x86/mingw/lib/libopencv_core230.dll.a ../OpenCV/OpenCV2.3/build/x86/mingw/lib/libopencv_features2d230.dll.a ../OpenCV/OpenCV2.3/build/x86/mingw/lib/libopencv_flann230.dll.a ../OpenCV/OpenCV2.3/build/x86/mingw/lib/libopencv_gpu230.dll.a ../OpenCV/OpenCV2.3/build/x86/mingw/lib/libopencv_highgui230.dll.a ../OpenCV/OpenCV2.3/build/x86/mingw/lib/libopencv_imgproc230.dll.a ../OpenCV/OpenCV2.3/build/x86/mingw/lib/libopencv_legacy230.dll.a ../OpenCV/OpenCV2.3/build/x86/mingw/lib/libopencv_ml230.dll.a ../OpenCV/OpenCV2.3/build/x86/mingw/lib/libopencv_objdetect230.dll.a ../OpenCV/OpenCV2.3/build/x86/mingw/lib/libopencv_video230.dll.a
build/Release/MinGW-Windows/main.o:main.cpp:(.text+0x4f): undefined reference to `cv::Mat::eye(int, int, int)'
build/Release/MinGW-Windows/main.o:main.cpp:(.text+0xac): undefined reference to `cv::fastFree(void*)'
build/Release/MinGW-Windows/main.o:main.cpp:(.text+0x11a): undefined reference to `cv::fastFree(void*)'
build/Release/MinGW-Windows/main.o:main.cpp:(.text+0x191): undefined reference to `cv::fastFree(void*)'
build/Release/MinGW-Windows/main.o:main.cpp:(.text+0x1a7): undefined reference to `cv::Mat::deallocate()'
build/Release/MinGW-Windows/main.o:main.cpp:(.text+0x1ba): undefined reference to `cv::Mat::deallocate()'
build/Release/MinGW-Windows/main.o:main.cpp:(.text+0x1ce): undefined reference to `cv::Mat::deallocate()'
build/Release/MinGW-Windows/main.o:main.cpp:(.text$_ZN2cv3MatD1Ev[cv::Mat::~Mat()]+0x74): undefined reference to `cv::Mat::deallocate()'
build/Release/MinGW-Windows/main.o:main.cpp:(.text$_ZN2cv3MatD1Ev[cv::Mat::~Mat()]+0x63): undefined reference to `cv::fastFree(void*)'
collect2: ld returned 1 exit status
make[2]: Leaving directory `/f/Proyectos/C++/OpenCV23Sandbox'
make[1]: Leaving directory `/f/Proyectos/C++/OpenCV23Sandbox'
make[2]: *** [dist/Release/MinGW-Windows/opencv23sandbox.exe] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 1s)
or或者
g++.exe -o dist/Release/MinGW-Windows/opencv23sandbox build/Release/MinGW-Windows/main.o -L../OpenCV/OpenCV2.3/build/x86/mingw/lib -lopencv_calib3d230.dll -lopencv_contrib230.dll -lopencv_core230.dll -lopencv_features2d230.dll -lopencv_flann230.dll -lopencv_gpu230.dll -lopencv_highgui230.dll -lopencv_imgproc230.dll -lopencv_legacy230.dll -lopencv_ml230.dll -lopencv_objdetect230.dll -lopencv_video230.dll
same result.同样的结果。
I guess the Problem is that the library path points to the vc10 directory ( -L/cygdrive/C/OpenCV2.3/build/x86/vc10/lib
) instead of the mingw directory ( -L/cygdrive/C/OpenCV2.3/build/x86/mingw/lib
).我猜问题是库路径指向 vc10 目录(
-L/cygdrive/C/OpenCV2.3/build/x86/vc10/lib
)而不是 mingw 目录( -L/cygdrive/C/OpenCV2.3/build/x86/mingw/lib
)。 The ld-linker can't find the methods because they are mangled for the vc++ "link.exe". ld-linker 找不到这些方法,因为它们被 vc++“link.exe”破坏了。
If you use 64 bit, then you have also link against 64-bit libs: -L/cygdrive/C/OpenCV2.3/build/x64/mingw/lib
.如果您使用 64 位,那么您还链接到 64 位库:
-L/cygdrive/C/OpenCV2.3/build/x64/mingw/lib
。
Are you using the precompiled MinGW libraries?你在使用预编译的 MinGW 库吗? (it appears so).
(看起来是这样)。 I tried for a couple of days to get my project to link successfully under Code::Blocks.
我尝试了几天让我的项目在 Code::Blocks 下成功链接。 I was seeing the same sort of errors you describe (bad references, etc).
我看到了与您描述的相同类型的错误(错误的引用等)。
I finally recompiled OpenCV using the steps shown here , and all became well.我终于使用这里显示的步骤重新编译了 OpenCV,一切都变得很好。
I have exactly the same issue.我有完全相同的问题。 I am trying to compile my program under a 64-bit Windows 7 machine with MinGW.
我正在尝试在带有 MinGW 的 64 位 Windows 7 机器下编译我的程序。 Here is several possibilities that may result in the problem:
以下是可能导致问题的几种可能性:
1) You need to make sure OpenCV2.3/build/x64/mingw/lib
is link. 1)您需要确保
OpenCV2.3/build/x64/mingw/lib
是链接。 Be careful, don't link the project to the libs for visual studio or libs for x86.请注意,不要将项目链接到 Visual Studio 的库或 x86 的库。
2) Make sure the proper dll
s are copied to the project directory, or have been added to PATH
. 2)确保将正确的
dll
复制到项目目录,或已添加到PATH
。 For example, if you use this lib libopencv_core243.dll.a
, you should make sure libopencv_core243.dll
can be loaded by the project.例如,如果您使用此
libopencv_core243.dll.a
,则应确保项目可以加载libopencv_core243.dll
。 This is not the cause of the problem.这不是问题的原因。 But I think it is also important to know.
但我认为知道也很重要。
3) Make sure the MinGW can compile x64 programs. 3)确保MinGW可以编译x64程序。 This is what I use: mingw-w64 (But since mingw-w64 project is moving to mingw-w64.org it's better to use the new website).
这是我使用的: mingw-w64 (但由于 mingw-w64 项目正在迁移到mingw-w64.org ,所以最好使用新网站)。 Unfortunately, the one that download from MinGW32 won't work.
不幸的是,从MinGW32下载的那个不起作用。 And the link from the official site of MinGW will bring you to a second one (MinGW32).
MinGW官方网站的链接将带您进入第二个(MinGW32)。
4) By default, MinGw may compile your project to a 32 bit program. 4) 默认情况下,MinGw 可能会将您的项目编译为 32 位程序。 In order to make sure it compiles for 64 bit, add this compile flag
-m64
.为了确保它可以编译为 64 位,请添加此编译标志
-m64
。 Otherwise, if you only link the project with all the 64-bit libs, it will result in the problem as well.否则,如果您只将项目与所有 64 位库链接,也会导致问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.