I'm having this issue where the linker fails due to an undefined symbol while it works great in command line. Hope you guys can help me to figure this out.
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
Output of command tree :
$ 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
...
Compiler output :
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"
My main.cpp file consists of a basic YAML::LoadFile("foo.bar") and trying to display it.
I have tried to create a test.cpp calling YAML::LoadFile()
, then compile it with the two following commands (Qt produces the same + all its including stuff, I can paste it as well) :
$ 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
... and it works.
I don't know what I am missing. Thank you a lot !
EDIT : if you have any suggestions to clean this tree, I would be thrilled. Don't know the standard way to organise all this.
Okay so the solution was easy but really tricky to spot (crazy hunt).
Since there is two C++ standard libraries in OSX (see here), I had to specifically tell the compiler to use libc++.
Therefore I added
QMAKE_CXXFLAGS = -stdlib=libc++
LIBS += -stdlib=libc++
to my .pro file and everything works correctly now !
Still don't know why on command line I don't have to do this but... If someone has a clue ?
Have a good day everyone.