Qt5.1/Qt5.2 + Mac OS 10.9(Mavericks)+ XCode 5.0.2,体系结构x86_64的未定义符号 [英] Qt5.1/Qt5.2 + Mac OS 10.9 (Mavericks) + XCode 5.0.2, Undefined symbols for architecture x86_64

查看:80
本文介绍了Qt5.1/Qt5.2 + Mac OS 10.9(Mavericks)+ XCode 5.0.2,体系结构x86_64的未定义符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

I can compile the following program via terminal

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

程序a.out正常运行.

The program a.out runs normally.

但是,当使用Qt 5.1/5.2运行此OpenCV程序时, 我得到体系结构x86_64的未定义符号".

However, when using Qt 5.1/5.2 to run this OpenCV program, I got "Undefined symbols for architecture x86_64".

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

However, Qt5 works normally for a simple HelloWorld c++ program.

发生了什么事?

这是代码.

#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++无关. 通过使用命令行编译.

I checked the problem has nothing to do with -lstdc++ or -std=c++11 or -stdlib=libstdc++. by using command line compile.

有什么想法或建议吗?

推荐答案

此问题已得到解决

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

,并由 sandy.martel

我在这里引用了

使用-stdlib = libstdc ++编译的Qt二进制发行版可与10.6兼容,默认情况下,在10.9上的Xcode 5将选择-stdlib = libc ++(仅适用于OS X 10.7和更高版本). 因此,使用标准库中的类的符号(在这种情况下,如std :: string)在链接时无法正确解析. 这就是为什么您看到此错误(架构x86_64的未定义符号)的原因.看一下用哪个标准库opencv构建的: otool -L libopencv_XXX.dylib. 您必须使用正确的版本重建它,或者更改Qt的mkspec才能使用更新的版本.

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

在重建之前,请记住清理您的项目.

And remember clean your project before rebuild.

这篇关于Qt5.1/Qt5.2 + Mac OS 10.9(Mavericks)+ XCode 5.0.2,体系结构x86_64的未定义符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆