I try to compile program using boost with Clang++ on Mac OS X in Qt Creator. Everything goes fine: I have compiled boost and all program modules, but on the linkage stage clang cannot find any symbols:
Undefined symbols for architecture x86_64:
"_BIO_ctrl", referenced from:
boost::asio::ssl::detail::engine::map_error_code(boost::system::error_code&) const in session.o
.....
"boost::log::v2s_mt_posix::core::get()", referenced from:
INIT_LOG() in log.o
.....
qmake config:
CONFIG -= qt
CONFIG += console debug
TARGET = server
QMAKE_CXXFLAGS -= -mmacosx-version-min=10.6
QMAKE_CXXFLAGS += -std=c++11 -stdlib=libc++ -mmacosx-version-min=10.7
QMAKE_LFLAGS -= -mmacosx-version-min=10.6
QMAKE_LFLAGS += -stdlib=libc++ -mmacosx-version-min=10.7
Linking command is:
clang++ -headerpad_max_install_names -stdlib=libc++ -mmacosx-version-min=10.7 -o server main.o session.o log.o -L/Users/apple/Lib/boost_1_53_0/usr/lib -L/opt/local/lib -L/usr/lib -lssl -lboost_system -lboost_filesystem -lboost_date_time -lboost_thread -lboost_log_setup -lboost_log -lboost_chrono -lboost_program_options
If I rename *.dylib, it says that cannot find -lboost_*, so it really SEES library files.
With nm I can find, that symbols exist:
0000000000018ad0 T __ZN5boost3log11v2_mt_posix4core3getEv
Related
I am trying to compile Qscintilla 2.9.3 (obtained here) on mac (OS X 10.11.6), but the make step fails with the following error :
/Applications/Xcode.app/Contents/Developer/usr/bin/g++ -c -pipe -O2 -std=gnu++11 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -mmacosx-version-min=10.8 -fvisibility=hidden -fvisibility-inlines-hidden -w -fPIC -DQSCINTILLA_MAKE_DLL -DSCINTILLA_QT -DSCI_LEXER -DQT_NO_DEBUG -DQT_PRINTSUPPORT_LIB -DQT_WIDGETS_LIB -DQT_MACEXTRAS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I. -I. -I../include -I../lexlib -I../src -I/Applications/Utilities/Qt/5.7/clang_64/lib/QtPrintSupport.framework/Headers -I/Applications/Utilities/Qt/5.7/clang_64/lib/QtWidgets.framework/Headers -I/Applications/Utilities/Qt/5.7/clang_64/lib/QtMacExtras.framework/Headers -I/Applications/Utilities/Qt/5.7/clang_64/lib/QtGui.framework/Headers -I/Applications/Utilities/Qt/5.7/clang_64/lib/QtCore.framework/Headers -I. -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks/OpenGL.framework/Headers -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks/AGL.framework/Headers -I/Applications/Utilities/Qt/5.7/clang_64/mkspecs/macx-g++ -F/Applications/Utilities/Qt/5.7/clang_64/lib -o qsciscintilla.o qsciscintilla.cpp
In file included from qsciscintilla.cpp:23:
In file included from ./Qsci/qsciscintilla.h:29:
In file included from /Applications/Utilities/Qt/5.7/clang_64/lib/QtCore.framework/Headers/QByteArray:1:
In file included from /Applications/Utilities/Qt/5.7/clang_64/lib/QtCore.framework/Headers/qbytearray.h:44:
In file included from /Applications/Utilities/Qt/5.7/clang_64/lib/QtCore.framework/Headers/qrefcount.h:43:
In file included from /Applications/Utilities/Qt/5.7/clang_64/lib/QtCore.framework/Headers/qatomic.h:41:
In file included from /Applications/Utilities/Qt/5.7/clang_64/lib/QtCore.framework/Headers/qglobal.h:1145:
In file included from /Applications/Utilities/Qt/5.7/clang_64/lib/QtCore.framework/Headers/qatomic.h:46:
/Applications/Utilities/Qt/5.7/clang_64/lib/QtCore.framework/Headers/qbasicatomic.h:61:4: error:
"Qt requires C++11 support"
# error "Qt requires C++11 support"
^
/Applications/Utilities/Qt/5.7/clang_64/lib/QtCore.framework/Headers/qbasicatomic.h:90:13: error:
unknown type name 'QAtomicOps'
typedef QAtomicOps Ops;
Following other questions on the subject, I have added
\# With C++11 support
greaterThan(QT_MAJOR_VERSION, 4){
CONFIG += c++11
} else {
QMAKE_CXXFLAGS += -std=c++0x
}
in the qscintilla.pro file, to no avail.
This thread seems to show a similar problem. It was solved by suppressing an -ansi flag in a dependency, which prevented the use of c++11. However I do not see such a flag in the log above.
Do you have an idea as to what could cause that problem ?
I have QMake version 3.0 and Qt 5.7.
Thanks to the remarks above regarding the compiler used, I found on this thread that in order to use c++11 with clang/llvm on Mac, it is necessary to also use the library -stdlib=libc++ instead of the old libstdc++.
The problem was thus solved by adding
QMAKE_LFLAGS += -stdlib=libc++
QMAKE_CXXFLAGS += -stdlib=libc++
to the .pro file.
I have a problem with linking a compiled program (see github repo for details).
The osx specific makefile section is here:
CFLAGS = -v -arch x86_64 -Wall -fPIC -O2 -I./include $(OPTS)
LDFLAGS = -v -arch x86_64 -lpthread /usr/local/lib/libportaudio.a -framework CoreAudio -framework AudioToolbox -framework AudioUnit -framework Carbon
EXECUTABLE ?= squeezelite-osx
include Makefile
The compilation works fine, but during the linking it fails with:
Apple LLVM version 7.0.2 (clang-700.1.81)
Target: x86_64-apple-darwin15.2.0
Thread model: posix
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" -demangle -dynamic -arch x86_64 -macosx_version_min 10.11.0 -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -o squeezelite-osx main.o slimproto.o buffer.o stream.o utils.o output.o output_alsa.o output_pa.o output_stdout.o output_pack.o decode.o flac.o pcm.o mad.o vorbis.o faad.o mpg.o dsd.o dop.o dsd2pcm/dsd2pcm.o process.o resample.o -lpthread /usr/local/lib/libportaudio.a -framework CoreAudio -framework AudioToolbox -framework AudioUnit -framework Carbon -lFLAC -lmad -lvorbisfile -lfaad -lmpg123 -lsoxr -lSystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/7.0.2/lib/darwin/libclang_rt.osx.a
ld: library not found for -lFLAC
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [squeezelite-osx] Error 1
The library which is not found is in the folder /usr/local/include and I think I have to add this path to the include path of the linker.
How can I add the path /usr/local/include to the include path of the linker?
The linker doesn't use include files; that's the compiler (actually the pre-processor, but let's keep it simple).
Instead you need to tell the linker that it should look in /usr/local/lib using the -L option:
-L/usr/local/lib
Note: you can provide more than one -L option to the linker.
Helllo, I have some code, that I'm trying to compile. The code runs well on Linux but I can't compile it on OSX.
In the makefile I use for Linux:
LD_FLAGS = -lcudart -L$(CUDA_HOME)/lib64
For Mac I try to use these flags:
LD_FLAGS = -lcudart -L$(CUDA_HOME)/lib
LD_FLAGS = -lm -F/Library/Frameworks -framework CUDA
CXXFLAGS = -O3 -g -m32 -I$(CUDA_HOME)/include
NVCC_FLAGS = -O3 -g -G -I$(CUDA_HOME)/include -arch=sm_11
This is the make output file:
mpic++ -c -o main.o main.cpp -O3 -m32 -I/Developer/NVIDIA/CUDA-5.0/include
/Developer/NVIDIA/CUDA-5.0/bin/nvcc -c -o kernel.o kernel.cu -O3 -I/Developer/NVIDIA/CUDA-5.0/include -arch=sm_11
ptxas /tmp/tmpxft_000026f4_00000000-5_kernel.ptx, line 146; warning : Double is not supported. Demoting to float
/Developer/NVIDIA/CUDA-5.0/bin/nvcc -c -o support.o support.cu -O3 -I/Developer/NVIDIA/CUDA-5.0/include -arch=sm_11
mpic++ main.o kernel.o support.o -o stencil-mpi -lcudart -L/Developer/NVIDIA/CUDA-5.0/lib
ld: warning: ld: warning: ignoring file kernel.o, file was built for i386 which is not the architecture being linked (x86_64): kernel.o
ignoring file main.o, file was built for i386 which is not the architecture being linked (x86_64): main.o
ld: warning: ignoring file support.o, file was built for i386 which is not the architecture being linked (x86_64): support.o
Undefined symbols for architecture x86_64:
"_main", referenced from:
start in crt1.10.6.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
make: *** [stencil-mpi] Error 1
This problem was caused by trying to mix 32 and 64 bit compilation between the CUDA and MPI toolchains. It was noted in comments that adding -m64 instead of -m32 for LD_FLAGS, CXXFLAGS, and NVCC_FLAGS produced a working 64 bit build.
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
The program a.out runs normally.
However, when using Qt 5.1/5.2 to run this OpenCV program,
I got "Undefined symbols for architecture x86_64".
However, Qt5 works normally for a simple HelloWorld c++ program.
What is going on ?
Here is the code.
#include <iostream>
#include "opencv2/highgui/highgui.hpp"
using namespace std ;
using namespace cv ;
int main()
{
Mat img ;
img = imread("image.jpg") ;
return 0;
}
And this is the project setting
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
Here is the compile message
/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
with -v to show invocation
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
And here is the error message
Undefined symbols for architecture x86_64:
"cv::imread(std::string const&, int)", referenced from:
_main in main.o
.... and so on
I checked the problem has nothing to do with -lstdc++ or -std=c++11 or -stdlib=libstdc++.
by using command line compile.
Any ideas or suggestion?
This issue is answered in this post
http://qt-project.org/forums/viewthread/35646/
and explained by sandy.martel
I quoted here
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.
I solve this by changing ../Qt5.2.0/5.2.0-rc1/clang_64/mkspecs/macx-clang/qmake.conf
from
QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.6
to
QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.9
And remember clean your project before rebuild.
In case you came here, because you changed config+=11 and nothing happend, try to clean your project before rebuild.
The problem is not with the system. On Mac you just have to include imgcodecs header and include the respective lib files also. This will solve all the trouble you had.
-lopencv_imgcodecs
i am getting the following linker error when compiling our Qt project.
We do not use qmake. We use autoconf & automake..
Now porting to Mac brings the follwoing error:
I have tried using Qt-SDK and by compiling Qt by myself... Neither worked :(
Maybe somebody has an idea?
/bin/sh ../../libtool --tag=CXX --mode=link clang++ -g -O2 -Wl,-rpath -
Wl,/space/dev-libs/instantclient_10_2 -Wl,-rpath -Wl,/space/dev-libs/boost_1_53/lib -v -o showtime showtime-application_resources.o showtime-main.o cmdline.o ../../atcaf/atcafgui/libatcafgui.la
libtool: link: clang++ -g -O2 -Wl,-rpath -Wl,/space/dev-libs/instantclient_10_2 -Wl,-rpath -Wl,/space/dev-libs/boost_1_53/lib -v -o showtime showtime-application_resources.o showtime-main.o cmdline.o -Wl,-bind_at_load ../../atcaf/atcafgui/.libs/libatcafgui.a -L/usr/local/Qt-5.0.1/lib /usr/local/Qt-5.0.1/lib/libQt5Widgets.dylib /usr/local/Qt-5.0.1/lib/libQt5Gui.dylib /usr/local/Qt-5.0.1/lib/libQt5Sql.dylib /usr/local/Qt-5.0.1/lib/libQt5Xml.dylib /usr/local/Qt-5.0.1/lib/libQt5XmlPatterns.dylib /usr/local/Qt-5.0.1/lib/libQt5Network.dylib /usr/local/Qt-5.0.1/lib/libQt5Core.dylib -L/space/dev-libs/log4cxx-dfs/lib /space/dev-libs/log4cxx-dfs/lib/liblog4cxx.dylib -L/usr/lib -laprutil-1 -lexpat -liconv -lpq -lsqlite3 -lldap -llber -lapr-1 -lpthread -L/space/dev-libs/boost_1_53/lib -lboost_python -lpython2.6 -L/space/dev-libs/instantclient_10_2 -lclntsh -lz
Apple clang version 3.1 (tags/Apple/clang-318.0.58) (based on LLVM 3.1svn)
Target: x86_64-apple-darwin11.4.2
Thread model: posix
"/usr/bin/ld" -demangle -dynamic -arch x86_64 -macosx_version_min 10.7.4 -o showtime -lcrt1.10.6.o -L/usr/local/Qt-5.0.1/lib -L/space/dev-libs/log4cxx-dfs/lib -L/usr/lib -L/space/dev-libs/boost_1_53/lib -L/space/dev-libs/instantclient_10_2 -rpath /space/dev-libs/instantclient_10_2 -rpath /space/dev-libs/boost_1_53/lib showtime-application_resources.o showtime-main.o cmdline.o -bind_at_load ../../atcaf/atcafgui/.libs/libatcafgui.a /usr/local/Qt-5.0.1/lib/libQt5Widgets.dylib /usr/local/Qt-5.0.1/lib/libQt5Gui.dylib /usr/local/Qt-5.0.1/lib/libQt5Sql.dylib /usr/local/Qt-5.0.1/lib/libQt5Xml.dylib /usr/local/Qt-5.0.1/lib/libQt5XmlPatterns.dylib /usr/local/Qt-5.0.1/lib/libQt5Network.dylib /usr/local/Qt-5.0.1/lib/libQt5Core.dylib /space/dev-libs/log4cxx-dfs/lib/liblog4cxx.dylib -laprutil-1 -lexpat -liconv -lpq -lsqlite3 -lldap -llber -lapr-1 -lpthread -lboost_python -lpython2.6 -lclntsh -lz -lstdc++ -lSystem /usr/bin/../lib/clang/3.1/lib/darwin/libclang_rt.osx.a
Undefined symbols for architecture x86_64:
"QApplication::palette()", referenced from:
_main in showtime-main.o
"QApplication::commitData(QSessionManager&)", referenced from:
vtable for Application in libatcafgui.a(libatcafgui_la-Application.o)
"QApplication::saveState(QSessionManager&)", referenced from:
vtable for Application in libatcafgui.a(libatcafgui_la-Application.o)
"QAbstractItemView::dataChanged(QModelIndex const&, QModelIndex const&)", referenced from:
vtable for LogTableWWU in libatcafgui.a(libatcafgui_la-moc_LogTableWWU.o)
"QWidget::styleChange(QStyle&)", referenced from:
I had a similar problem when porting from Qt 4 to Qt 5. There were missing functions for QApplication::commitData() and QApplication::saveState().
I had derived a class from QApplication, in the header file I changed
#include <QtGui/QApplication>
to
#include <QApplication>
and this solved the problem.
I had the same problem, although mine was related to QWidget functions (e.g. QWidget::styleChange(QStyle&) or QWidget::fontChange(QFont const&)) rather than QApplication.
As suggested by koan, I looked for all the occurrences of
#include <QtGui/
in my project and replaced them with
#include <
which solved the problem. I tested this with both clang and g++ versions (5.0.1 and 5.0.2) and they both seem to work.
Note:
A number of solutions found on the web proposed to add
QT += widgets
to the qmake project (.pro) file, as this might be related to an existing bug. While I don't think that adding this is a problem, it did not solve this specific issue.