Qt Creator 3.2.2./Mac OSX 10.9.3 Qt Creaator中未定义的符号,在命令行中确定

Qt Creator 3.2.2 / Mac OSX 10.9.3 Undefined symbol in Qt Creator, OK in command line

本文关键字:Qt 符号 命令行 Creaator Creator Mac OSX 未定义      更新时间:2023-10-16

我遇到了这个问题,链接器由于未定义的符号而失败,而它在命令行中工作得很好。希望你们能帮我解决这个问题。

costesmanager_gui.pro

#-------------------------------------------------
#
# Project created by QtCreator 2014-10-22T14:45:23
#
#-------------------------------------------------
QT       += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = costesmanager_gui
TEMPLATE = app
SOURCES += main.cpp
        mainwindow.cpp
HEADERS  += mainwindow.h
FORMS    += mainwindow.ui
INCLUDEPATH += /Users/noe/boost_1_56_0
LIBS += -L/Users/noe/costesmanager/gui/costesmanager_gui/lib -lyaml-cpp
INCLUDEPATH += /Users/noe/costesmanager/gui/costesmanager_gui/yaml-cpp/include

命令树输出:

$ tree
.
├── costesmanager_gui.pro
├── costesmanager_gui.pro.user
├── lib
│   └── libyaml-cpp.a
├── main.cpp
├── mainwindow.cpp
├── mainwindow.h
├── mainwindow.ui
├── test.cpp
└── yaml-cpp
 ...
    ├── include
    │   └── yaml-cpp
...
    │       └── yaml.h
...

编译器输出:

Undefined symbols for architecture x86_64:
  "YAML::LoadFile(std::string const&)", referenced from:
      _main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [costesmanager_gui.app/Contents/MacOS/costesmanager_gui] Error 1
15:50:30: Le processus "/usr/bin/make" s'est terminé avec le code 2.
Erreur lors de la compilation/déploiement du projet costesmanager_gui (kit : Desktop Qt 5.3 clang 64bit)
When executing step "Make"

我的main.cpp文件由一个基本的YAML::LoadFile("foo.bar")组成,并试图显示它。

我尝试创建一个名为YAML::LoadFile()的test.cpp,然后用以下两个命令编译它(Qt生成相同的+所有包含的东西,我也可以粘贴它):

$ clang++ -c -I/Users/noe/costesmanager/gui/costesmanager_gui/yaml-cpp/include -I /Users/noe/boost_1_56_0 -o test.o test.cpp
$ clang++ test.o -o test -L/Users/noe/costesmanager/gui/costesmanager_gui/lib/ -lyaml-cpp

它是有效的。

我不知道我错过了什么。非常感谢!

编辑:如果你有任何清洁这棵树的建议,我会很高兴。不知道组织这一切的标准方法。

好的,所以解决方案很简单,但很难发现(疯狂的狩猎)。

由于OSX中有两个C++标准库(请参阅此处),我不得不特别告诉编译器使用libc++。

因此我添加了

QMAKE_CXXFLAGS = -stdlib=libc++
LIBS += -stdlib=libc++

到我的.pro文件,现在一切正常!

仍然不知道为什么在命令行上我不必这么做,但是。。。如果有人有线索?

祝大家今天愉快。