问题描述
我在从opencv(2.3.1)链接库时遇到问题,找不到解决方法.我正在将qtCreator与mingw和预构建的vc10动态lib文件一起使用.所以,这是我到目前为止所做的:
I'm having a problem linking a library from opencv(2.3.1) and can't find a way to resolve it..I'm using qtCreator with mingw and the pre-built vc10 dynamic lib files.So, here is what I have done till now:
.pro文件:
TEMPLATE = app
INCLUDEPATH += "E:/opencv/build/include/"
INCLUDEPATH += "E:/opencv/build/include/opencv/"
INCLUDEPATH += "E:/opencv/build/include/opencv2/"
INCLUDEPATH += $$PWD/../opencv/build/x86/vc10
DEPENDPATH += $$PWD/../opencv/build/x86/vc10
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../opencv/build/x86/vc10/lib/ -lopencv_core231
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../opencv/build/x86/vc10/lib/ -lopencv_core231d
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../opencv/build/x86/vc10/lib/ -lopencv_highgui231
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../opencv/build/x86/vc10/lib/ -lopencv_highgui231d
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../opencv/build/x86/vc10/lib/ -lopencv_imgproc231
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../opencv/build/x86/vc10/lib/ -lopencv_imgproc231d
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../opencv/build/x86/vc10/lib/ -lopencv_calib3d231
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../opencv/build/x86/vc10/lib/ -lopencv_calib3d231d
...
我已经测试了一个使用来自opencv的highgui库的应用程序,它的编译和运行良好,但是当我尝试使用cvPyrDown(来自imgproc_c.h)时,它可以编译但无法正确加载该库,它意外退出",并且代码-1073741515.我不明白为什么会这样..正如您从.pro文件中看到的那样,我像highgui一样链接了imgproc库,但是它仍然无法正常工作!
有什么建议吗?
I have tested an application that used highgui libs from opencv and it compiled and worked nicely, but when I try to use cvPyrDown(from imgproc_c.h) it compiles but can't load the library correctly it "exits unexpectedly" with code -1073741515.I don't understand why that is.. as you can see from the .pro file I linked the imgproc libs just like the highgui, but it still won't work!
Any suggestions ?
修改
好吧,问题在于Visual Studio创建的库使用的命名约定与g ++不同,这就是为什么它不起作用的原因.如果是这样,我仍然无法解释为什么它可以与highgui库一起工作.想法?
Ok, the problem is that visual studio creates libraries with different naming conventions than g++ and that's why it won't work.. If this is true, I still can't explain why it works with the highgui libs.. Any ideas ?
推荐答案
这是哪个版本的Opencv?我建议尝试使用最新版本2.3,并使用CMake代替.pro文件,这是整个项目的构建系统.
Which version of Opencv is this? I suggest trying latest 2.3, and using CMake instead of .pro files, which is the build system for the overall project.
然后,您只需在CMakeLists.txt上归档-> open-project,就可以看看如何使用CMake设置示例.
Then you just file->open-project on the CMakeLists.txt, and you can just look at how examples are set up with CMake.
如果此是最新的,则1)highgui使用QT,因此可以在qt creator上更好地使用它; 2)在Windows上使用.pro进行构建可能未经过测试;对CMake的不可避免的需求不足为奇.
If this is latest, then 1) highgui uses QT so it makes sense that it might play nicer with qt creator and 2) building with .pro on windows might be untested; a unavoidable need for CMake would not be surprising.
编辑:查看库的CMakeLists.txt文件....
Edit: Look at the CMakeLists.txt files for the libraries ....
# CMakeLists.txt for /modules/highgui
#YV
if (HAVE_QT)
if (HAVE_QT_OPENGL)
set(QT_USE_QTOPENGL TRUE)
endif()
INCLUDE(${QT_USE_FILE})
SET(_RCCS_FILES src/window_QT.qrc)
QT4_ADD_RESOURCES(_RCC_OUTFILES ${_RCCS_FILES})
SET(_MOC_HEADERS src/window_QT.h )
QT4_WRAP_CPP(_MOC_OUTFILES ${_MOC_HEADERS})
set(HIGHGUI_LIBRARIES ${HIGHGUI_LIBRARIES} ${QT_LIBRARIES} ${QT_QTTEST_LIBRARY})
set(highgui_srcs ${highgui_srcs} src/window_QT.cpp ${_MOC_OUTFILES} ${_RCC_OUTFILES} )
endif()
if(WIN32)
if(NOT HAVE_QT)
set(highgui_srcs ${highgui_srcs} src/window_w32.cpp)
endif()
set(highgui_srcs ${highgui_srcs} src/cap_vfw.cpp src/cap_cmu.cpp src/cap_dshow.cpp)
if(HAVE_MIL)
set(highgui_srcs ${highgui_srcs} src/cap_mil.cpp)
endif()
endif()
if(UNIX)
if(NOT HAVE_QT)
if(HAVE_GTK)
set(highgui_srcs ${highgui_srcs} src/window_gtk.cpp)
endif()
endif()
....
endif()
但是"imgproc"的CMakeLists.txt不做任何特定的检查...只是将buck传递给了主要的opencv lib:
But "imgproc"'s CMakeLists.txt doesn't do any specific checks ... just passes the buck to main opencv lib:
define_opencv_module(imgproc opencv_core)
这篇关于链接QtCreator&& OpenCv的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!