I'm working on my project which uses mongoDB. I've installed mongocxx according to the official guide and it works when I'm compiling the code from command line. Now I'd like to use it in my Qt project, I've added all necessary libraries in .pro file but I can't compile my code because of linker error. The code is the simplest:
#include <mongocxx/client.hpp>
#include <mongocxx/instance.hpp>
void connectToMongo() {
mongocxx::instance abc{};
}
.pro:
CONFIG += c++11
QMAKE_CXXFLAGS += -I/usr/local/include/mongocxx/v_noabi -I/usr/local/include/libmongoc-1.0 \
-I/usr/local/include/bsoncxx/v_noabi -I/usr/local/include/libbson-1.0 \
-L/usr/local/lib -lmongocxx -lbsoncxx
SOURCES += main.cpp
...
But, unfortunately, there is a linker's error:
Undefined symbols for architecture x86_64:
"mongocxx::v_noabi::instance::instance()", referenced from:
connectToMongo() in main.o
"mongocxx::v_noabi::instance::~instance()", referenced from:
connectToMongo() 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: *** [hw.app/Contents/MacOS/hw] Error 1
18:38:01: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project hw (kit: Desktop Qt 5.8.0 clang 64bit)
When executing step "Make"
the make's string:
Starting: "/usr/bin/make"
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -c -pipe -stdlib=libc++ -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk -mmacosx-version-min=10.12 -I/usr/local/include/mongocxx/v_noabi -I/usr/local/include/libmongoc-1.0 -I/usr/local/include/bsoncxx/v_noabi -I/usr/local/include/libbson-1.0 -L/usr/local/lib -lmongocxx -lbsoncxx -g -std=gnu++1z -Wall -W -fPIC -DQT_QML_DEBUG -DQT_WEBENGINEWIDGETS_LIB -DQT_WEBENGINECORE_LIB -DQT_QUICKCONTROLS2_LIB -DQT_QUICK_LIB -DQT_PRINTSUPPORT_LIB -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_WEBCHANNEL_LIB -DQT_QML_LIB -DQT_NETWORK_LIB -DQT_POSITIONING_LIB -DQT_CORE_LIB -I../hw -I. -I../Qt/5.8/clang_64/lib/QtWebEngineWidgets.framework/Headers -I../Qt/5.8/clang_64/lib/QtWebEngineCore.framework/Headers -I../Qt/5.8/clang_64/lib/QtQuickControls2.framework/Headers -I../Qt/5.8/clang_64/lib/QtQuick.framework/Headers -I../Qt/5.8/clang_64/lib/QtPrintSupport.framework/Headers -I../Qt/5.8/clang_64/lib/QtWidgets.framework/Headers -I../Qt/5.8/clang_64/lib/QtGui.framework/Headers -I../Qt/5.8/clang_64/lib/QtWebChannel.framework/Headers -I../Qt/5.8/clang_64/lib/QtQml.framework/Headers -I../Qt/5.8/clang_64/lib/QtNetwork.framework/Headers -I../Qt/5.8/clang_64/lib/QtPositioning.framework/Headers -I../Qt/5.8/clang_64/lib/QtCore.framework/Headers -I. -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/OpenGL.framework/Headers -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/AGL.framework/Headers -I../Qt/5.8/clang_64/mkspecs/macx-clang -F/Users/alexey/Qt/5.8/clang_64/lib -o main.o ../hw/main.cpp
clang: warning: -lmongocxx: 'linker' input unused
clang: warning: -lbsoncxx: 'linker' input unused
clang: warning: argument unused during compilation: '-L/usr/local/lib'
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -headerpad_max_install_names -stdlib=libc++ -Wl,-syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk -mmacosx-version-min=10.12 -Wl,-rpath,/Users/alexey/Qt/5.8/clang_64/lib -o hw.app/Contents/MacOS/hw main.o qrc_qml.o moc_filldatacollections.o -F/Users/alexey/Qt/5.8/clang_64/lib -framework QtWebEngineWidgets -framework QtWebEngineCore -framework QtQuick -framework QtQml -framework QtNetwork -framework QtCore -framework DiskArbitration -framework IOKit -framework QtGui -framework QtWebChannel -framework QtPositioning -framework QtPrintSupport -framework QtWidgets -framework QtQuickControls2 -framework OpenGL -framework AGL
I've already found a decision for such problem in different topics, e.g. http://widequestion.com/question/msgasserted-linker-errors-on-mongo-c-drivers-on-macosx-10-10-3-yosemite/
but it'n't working in my case. My OS X is 10.11.
Help me, please, to resolve this problem.
clang: warning: -lmongocxx: 'linker' input unused
clang: warning: -lbsoncxx: 'linker' input unused
clang: warning: argument unused during compilation: '-L/usr/local/lib'
You seem to have set your linker flags as cxxflags so they were applied building main.o (when they were unused) and not applied during linking to build the executable.
I haven't worked with Qt, but a quick search suggests maybe those should have been set on LIBS. See docs for declaring other libraries.
Related
For educational purposes, I'm learning to create a QT makefile from scratch - without qmake.
Here is my Makefile:
SOURCES = calculator.cpp
INCPATH = -I. -I/usr/local/qt/5.9.1/clang_64/lib/QtWidgets.framework/Headers -I/usr/local/qt/5.9.1/clang_64/lib/QtGui.framework/Headers -I/usr/local/qt/5.9.1/clang_64/lib/QtCore.framework/Headers -I. -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/OpenGL.framework/Headers -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/AGL.framework/Headers -I/usr/local/qt/5.9.1/clang_64/mkspecs/macx-clang -F/usr/local/qt/5.9.1/clang_64/lib
DEFINES = -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB
FRAMEWORK = -framework QtCore -framework QtGui -framework QtWidgets -framework OpenGL -framework DiskArbitration -framework IOKit -framework OpenGL -framework AGL
all:
g++ -std=c++11 $(SOURCES) $(INCPATH) $(FRAMEWORK)
When I run make, there are no errors and an a.out file is generated successfully.
When I try to run that a.out file by typing ./a.out, I get this error:
dyld: Library not loaded: #rpath/QtCore.framework/Versions/5/QtCore
Referenced from: /Users/dougbeney/Desktop/Coding/Projects/cpp/Test/./a.out
Reason: image not found
Abort trap: 6
Any idea of what I'm missing? I tried checking out the generated qmake Makefile as a reference, but couldn't pinpoint what I needed.
Figured it out!
It was all in the LFLAGS.
Here is how I changed my Makefile to work:
SOURCES = calculator.cpp
INCPATH = -I. -I/usr/local/qt/5.9.1/clang_64/lib/QtWidgets.framework/Headers -I/usr/local/qt/5.9.1/clang_64/lib/QtGui.framework/Headers -I/usr/local/qt/5.9.1/clang_64/lib/QtCore.framework/Headers -I. -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/OpenGL.framework/Headers -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/AGL.framework/Headers -I/usr/local/qt/5.9.1/clang_64/mkspecs/macx-clang -F/usr/local/qt/5.9.1/clang_64/lib
DEFINES = -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB
LFLAGS = -stdlib=libc++ -headerpad_max_install_names -arch x86_64 -Wl,-syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk -mmacosx-version-min=10.10 -Wl,-rpath,#executable_path/Frameworks -Wl,-rpath,/usr/local/qt/5.9.1/clang_64/lib
FRAMEWORK = -framework QtCore -framework QtGui -framework QtWidgets -framework OpenGL -framework DiskArbitration -framework IOKit -framework OpenGL -framework AGL
all:
g++ -std=c++11 $(LFLAGS) $(SOURCES) $(INCPATH) $(FRAMEWORK)
I'm trying to start a project in XCode 8 using wxWidgets 3.1.0 on OS X 10.11
After downloading wxWidgets-3.1.0 I've built and make everything according to the /docs/osx/install.txt
Now I tried to create a new project and followed their guide: https://wiki.wxwidgets.org/Creating_Xcode_projects_for_wxWidgets_applications
I followed almost every step exactly as instructed. (Static and Debug)
I didn't find the Summary Tab and a Choose Info.plist File Button, I chose it over General under Identity (which may be the same)
Then I tried to compile and run.
I'm getting Warnings and 1 Error.
Warning: Telling me to check dependencies
wxcocoa.xcconfig line 3: Unable to find included file "wx.xcconfig"
Warning: The Copy Bundle Resources build phase contains this target's Info.plist file '/Users/me/Desktop/git/xcode/wx_mac_xcode/Info_cocoa.plist'.
Error:
Ld /Users/me/Library/Developer/Xcode/DerivedData/wx_mac_xcode-bhbnjqgpmqtgwxhfxmjhvrtjnraz/Build/Products/Debug/Static.app/Contents/MacOS/Static normal x86_64
cd /Users/me/Desktop/git/xcode/wx_mac_xcode
export MACOSX_DEPLOYMENT_TARGET=10.5
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -L/Users/me/Library/Developer/Xcode/DerivedData/wx_mac_xcode-bhbnjqgpmqtgwxhfxmjhvrtjnraz/Build/Products/Debug -F/Users/me/Library/Developer/Xcode/DerivedData/wx_mac_xcode-bhbnjqgpmqtgwxhfxmjhvrtjnraz/Build/Products/Debug -filelist /Users/me/Library/Developer/Xcode/DerivedData/wx_mac_xcode-bhbnjqgpmqtgwxhfxmjhvrtjnraz/Build/Intermediates/wx_mac_xcode.build/Debug/Static.build/Objects-normal/x86_64/Static.LinkFileList -Xlinker -rpath -Xlinker #executable_path/../Frameworks -mmacosx-version-min=10.5 -Xlinker -no_deduplicate -framework WebKit -framework IOKit -framework Carbon -framework Cocoa -framework AudioToolbox -framework OpenGL -framework QTKit -framework WebKit -framework IOKit -framework Carbon -framework Cocoa -framework AudioToolbox -framework OpenGL -framework QTKit -lz -stdlib=libstdc++ -lwx_osx_cocoa_static -Xlinker -dependency_info -Xlinker /Users/me/Library/Developer/Xcode/DerivedData/wx_mac_xcode-bhbnjqgpmqtgwxhfxmjhvrtjnraz/Build/Intermediates/wx_mac_xcode.build/Debug/Static.build/Objects-normal/x86_64/Static_dependency_info.dat -o /Users/me/Library/Developer/Xcode/DerivedData/wx_mac_xcode-bhbnjqgpmqtgwxhfxmjhvrtjnraz/Build/Products/Debug/Static.app/Contents/MacOS/Static
ld: library not found for -lwx_osx_cocoa_static
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Double checked every step, but don't know how to fix those dependencies.
Project and library are debug mode
Cheers
Alright, I know that there are other posts on this error, but I can't seem to find one that fixes my problem. The issue is that when I try to build my C++ project in Qt Creator I get two errors: 1) symbol(s) not found for architecture x86_64 and 2) linker command failed with exit code 1 (use -v to see invocation). The code builds and runs fine until I try to implement the FFT using the FFTW-3.3.4 library. The complete compiler output is:
14:55:10: Running steps for project RFdata...
14:55:10: Configuration unchanged, skipping qmake step.
14:55:10: Starting: "/usr/bin/make"
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr /bin/clang++ -c -pipe -g -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDK s/MacOSX10.9.sdk -mmacosx-version-min=10.7 -Wall -W -fPIE -DQT_CORE_LIB - I../Qt/5.4/clang_64/mkspecs/macx-clang -I../RFdata -I../RFdata/fftw- 3.3.4/libbench2 -I../Qt/5.4/clang_64/lib/QtCore.framework/Versions/5/Headers -I. - I. -F/Users/Mike/Desktop/Qt/5.4/clang_64/lib -o main.o ../RFdata/main.cpp
../RFdata/main.cpp:93:22: warning: comparison of integers of different signs: 'long' and 'size_type' (aka 'unsigned long') [-Wsign-compare]
for (long i = 0; i < str.length(); ++i) //M:for loop that iterates through the length of the string and //replaces each occurance of a ch1 with ch2
~ ^ ~~~~~~~~~~~~
1 warning generated.
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr /bin/clang++ -c -pipe -g -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDK s/MacOSX10.9.sdk -mmacosx-version-min=10.7 -Wall -W -fPIE -DQT_CORE_LIB - I../Qt/5.4/clang_64/mkspecs/macx-clang -I../RFdata -I../RFdata/fftw- 3.3.4/libbench2 -I../Qt/5.4/clang_64/lib/QtCore.framework/Versions/5/Headers -I. - I. -F/Users/Mike/Desktop/Qt/5.4/clang_64/lib -o display_vector.o ../RFdata/display_vector.cpp
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr /bin/clang++ -c -pipe -g -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDK s/MacOSX10.9.sdk -mmacosx-version-min=10.7 -Wall -W -fPIE -DQT_CORE_LIB - I../Qt/5.4/clang_64/mkspecs/macx-clang -I../RFdata -I../RFdata/fftw- 3.3.4/libbench2 -I../Qt/5.4/clang_64/lib/QtCore.framework/Versions/5/Headers -I. - I. -F/Users/Mike/Desktop/Qt/5.4/clang_64/lib -o convert_string.o ../RFdata/convert_string.cpp
/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/De veloper/SDKs/MacOSX10.9.sdk -mmacosx-version-min=10.7 -Wl,- rpath,/Users/Mike/Desktop/Qt/5.4/clang_64/lib -o RFdata main.o display_vector.o convert_string.o -F/Users/Mike/Desktop/Qt/5.4/clang_64/lib - L/Users/Mike/Desktop/RFdata/fftw-3.3.4/libbench2/ -lbench2 -framework QtCore - framework DiskArbitration -framework IOKit
Undefined symbols for architecture x86_64:
"_fftw_cleanup", referenced from:
hilbert() in main.o
"_fftw_destroy_plan", referenced from:
hilbert() in main.o
"_fftw_execute", referenced from:
hilbert() in main.o
"_fftw_plan_dft_1d", referenced from:
hilbert() 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: *** [RFdata] Error 1
14:55:11: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project RFdata (kit: Desktop Qt 5.4.0 clang 64bit)
When executing step "Make"
14:55:11: Elapsed time: 00:01.
I have absolutely no experience with linking libraries so any help would be absolutely amazing! I should probably show what my .pro file says since from what I can understand, adding the correct lines in the .pro file can be the difference between successfully linking to a library and not being as successful!
.pro:
QT += core
QT -= gui
TARGET = RFdata
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp \
display_vector.cpp \
convert_string.cpp
HEADERS += \
display_vector.h \
convert_string.h
macx: LIBS += -L$$PWD/fftw-3.3.4/libbench2/ -lbench2
INCLUDEPATH += $$PWD/fftw-3.3.4/libbench2
DEPENDPATH += $$PWD/fftw-3.3.4/libbench2
macx: PRE_TARGETDEPS += $$PWD/fftw-3.3.4/libbench2/libbench2.a
So, I guess the overarching question, though I realize it is a very general and possibly simple one, is how do I go about successfully linking the fftw-3.3.4 library to my c++ project in Qt creator 3.3 on my mac (OSX 10.9.5)????? This has been driving me insane!
It looks like you are trying to link a 32bit library into a 64bit executable. Either look for a 64bit library or compile it as a 32bit program.
I used the method described in the answer of: https://stackoverflow.com/a/18922738/2197292
to build Assimp 3.0 on my Mac OS X 10.9. I use Xcode 5.0.2. Then I added libassimp.a to frameworks and added /usr/local/include/assimp to header search paths. Am I missing something? When I build my project I get this error:
Ld DerivedData/OpenGLGLSL5Assimp/Build/Products/Debug/OpenGLGLSL5Assimp.app/Contents/MacOS/OpenGLGLSL5Assimp normal x86_64
cd /Users/MATH/Documents/XCODE/OpenGLGLSL5Assimp
setenv MACOSX_DEPLOYMENT_TARGET 10.8
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk -L/Users/MATH/Documents/XCODE/OpenGLGLSL5Assimp/DerivedData/OpenGLGLSL5Assimp/Build/Products/Debug -F/Users/MATH/Documents/XCODE/OpenGLGLSL5Assimp/DerivedData/OpenGLGLSL5Assimp/Build/Products/Debug -filelist /Users/MATH/Documents/XCODE/OpenGLGLSL5Assimp/DerivedData/OpenGLGLSL5Assimp/Build/Intermediates/OpenGLGLSL5Assimp.build/Debug/OpenGLGLSL5Assimp.build/Objects-normal/x86_64/OpenGLGLSL5Assimp.LinkFileList -mmacosx-version-min=10.8 -stdlib=libc++ -fobjc-arc -fobjc-link-runtime -lassimp -framework GLUT -framework OpenGL -framework Cocoa -Xlinker -dependency_info -Xlinker /Users/MATH/Documents/XCODE/OpenGLGLSL5Assimp/DerivedData/OpenGLGLSL5Assimp/Build/Intermediates/OpenGLGLSL5Assimp.build/Debug/OpenGLGLSL5Assimp.build/Objects-normal/x86_64/OpenGLGLSL5Assimp_dependency_info.dat -o /Users/MATH/Documents/XCODE/OpenGLGLSL5Assimp/DerivedData/OpenGLGLSL5Assimp/Build/Products/Debug/OpenGLGLSL5Assimp.app/Contents/MacOS/OpenGLGLSL5Assimp
ld: library not found for -lassimp
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I'm looking at opencv highgui samples (like connectedcomponents.cpp) and trying to get used to adding GUI elements. Currently I'm trying to add a button:
void on_button(int, void*){
cout << "click" << end;
}
//in main()
createButton("test",on_button);
but I get a link error:
g++ -c -pipe -g -gdwarf-2 -arch x86_64 -Xarch_x86_64 -mmacosx-version-min=10.5 -Wall -W -DQT_CORE_LIB -I../../../QtSDK/Desktop/Qt/474/gcc/mkspecs/macx-g++ -I. -I../../../QtSDK/Desktop/Qt/474/gcc/lib/QtCore.framework/Versions/4/Headers -I../../../QtSDK/Desktop/Qt/474/gcc/include/QtCore -I../../../QtSDK/Desktop/Qt/474/gcc/include -I/opt/local/include -I../../../QtSDK/Desktop/Qt/474/gcc/include -I. -F/Users/george/QtSDK/Desktop/Qt/474/gcc/lib -o main.o main.cpp
g++ -headerpad_max_install_names -arch x86_64 -Xarch_x86_64 -mmacosx-version-min=10.5 -o CVConnectedComponent main.o -F/Users/george/QtSDK/Desktop/Qt/474/gcc/lib -L/Users/george/QtSDK/Desktop/Qt/474/gcc/lib /opt/local/lib/libopencv_core.dylib /opt/local/lib/libopencv_contrib.dylib /opt/local/lib/libopencv_highgui.dylib /opt/local/lib/libopencv_objdetect.dylib /opt/local/lib/libopencv_imgproc.dylib /opt/local/lib/libopencv_features2d.dylib /opt/local/lib/libopencv_video.dylib -framework QtCore -F/Users/george/Documents/Qt/CVConnectedComponent/../../../QtSDK/Desktop/Qt/474/gcc/lib/
Undefined symbols:
"cv::createButton(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, void (*)(int, void*), void*, int, bool)", referenced from:
_main in main.o
make: Leaving directory `/Users/george/Documents/Qt/CVConnectedComponent'
ld: symbol(s) not found
As far as I can understand I'm not linking against the QtCore library properly.
I've this:
mac: LIBS += -framework QtCore
and this:
mac: LIBS += -F$$PWD/../../../QtSDK/Desktop/Qt/474/gcc/lib/ -framework QtCore
INCLUDEPATH += $$PWD/../../../QtSDK/Desktop/Qt/474/gcc/include
DEPENDPATH += $$PWD/../../../QtSDK/Desktop/Qt/474/gcc/include
In the .pro file of the Qt project, but with no luck.
I'm using OpenCV 2.4.1 with Qt 4.7.4 on osx 10.6.8.
What's the correct way to link to QtCore in Qt Creator to use createButton in OpenCV ?
I've reinstalled OpenCV, this time with Qt support and the code worked.
Still it's worth remembering that buttons will go into the Control Panel by default, as I found out by reading some documentation: