macos - Qt5.1/Qt5.2 + Mac OS 10.9 (Mavericks) + XCode 5.0.2,架构 x86_64 的 undefined symbol

标签 macos qt opencv undefined x86-64

环境:Mac OS 10.9 + Qt5.1/Qt5.2 + OpenCV2.4.7 + XCode(5.0.2)

我可以通过终端编译下面的程序

g++ -L/usr/local/lib -lopencv_core -lopencv_highgui \
    -I/usr/local/include  main.cpp

程序a.out正常运行。

但是,当使用Qt 5.1/5.2运行这个OpenCV程序时, 我得到了“体系结构 x86_64 的 undefined symbol ”。

但是,对于简单的 HelloWorld c++ 程序,Qt5 可以正常工作。

这是怎么回事?

这是代码。

#include <iostream>
#include "opencv2/highgui/highgui.hpp"

using namespace std ;
using namespace cv ;

int main()
{
    Mat img ;

    img = imread("image.jpg") ;

    return 0;
}

这是项目设置

INCLUDEPATH += /usr/local/include

LIBS += -L/usr/local/lib

LIBS += -lopencv_core -lopencv_highgui -v

cache()

TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt

SOURCES += main.cpp

这是编译信息

/Users/XXX/Qt5.2.0/5.2.0-beta1/clang_64/bin/qmake -spec macx-clang CONFIG+=debug -o Makefile /Users/XXX/Desktop/untitled/untitled.pro

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -headerpad_max_install_names -Wl,-syslibroot

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk -mmacosx-version-min=10.6 -o untitled main.o   -L/usr/local/lib -lopencv_core -lopencv_highgui -v 

用-v显示调用

Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin13.0.0
Thread model: posix

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" -demangle -dynamic -arch x86_64 -headerpad_max_install_names -macosx_version_min 10.6.0 -o untitled -lcrt1.10.6.o -L/usr/local/lib -syslibroot

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk main.o -lopencv_core -lopencv_highgui -lstdc++ -lSystem

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/5.0/lib/darwin/libclang_rt.osx.a

这是错误信息

Undefined symbols for architecture x86_64:
"cv::imread(std::string const&, int)", referenced from:
      _main in main.o
.... and so on

我检查过这个问题与-lstdc++-std=c++11-stdlib=libstdc++无关。 通过使用命令行编译。

有什么想法或建议吗?

最佳答案

这个问题在这篇文章中得到了解答

http://qt-project.org/forums/viewthread/35646/

并由 sandy.martel 解释

我在这里引用

Qt binary distribution compile with -stdlib=libstdc++ to be compatible with 10.6, Xcode 5 on 10.9 will select -stdlib=libc++ by default (for OS X 10.7 and better only). So symbol using classes from the standard library (like std::string in this case) will not resolve correctly at link time. This is why you’re seeing this error (Undefined symbols for architecture x86_64) . Look with which standard library opencv is built: otool -L libopencv_XXX.dylib. You’ll have to rebuild it with the right one or change Qt’s mkspec to use the newer one.

我通过更改 ../Qt5.2.0/5.2.0-rc1/clang_64/mkspecs/macx-clang/qmake.conf 解决了这个问题

来自

QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.6

QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.9

并记住在重建之前清理您的项目。

关于macos - Qt5.1/Qt5.2 + Mac OS 10.9 (Mavericks) + XCode 5.0.2,架构 x86_64 的 undefined symbol ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20342896/

相关文章:

c++ - SpinBoxDelegate 显示为 DoubleSpinBoxDelegate

c++ - 在其他组件上使用 QTableView 缓慢滚动

.net - 无法从 Emgucv 中的文件创建捕获

c++ - 如何使用 Opencv C++ 在四象限(等份)中切割图像

xcode - 如何创建mac vps(虚拟专用服务器)并通过浏览器访问

c++ - Mac 的 McCabe 风格的功能复杂性测试

python - 尝试从 Mac OS X 连接到 Vertica 时连接字符串无效

node.js - Node Gui安装找不到Cmake

c++ - OpenCV C++ 在彩色图像中组合灰色图像

ios - 为mac平台移植iOS项目