Creating lib with g++ 4.0.1 - macos

I'm trying to create a lib with g++ 4.0.1, but it looks for _main (which deliberately isn't in the code). Must I put a _main in there or can I circumvent with some nifty switch? My current command line looks like:
g++ -shared -o mylib.so myobj1.o myobj2.o ...
On a sidenote I'm using g++ powerpc-apple-darwin9, but I'm guessing/hoping that this should be irrelevant. A more complete printout:
$g++ -O0 -ggdb -fPIC -D_DARWIN_C_SOURCE -D_STLP_THREADS -D_POSIX_PTHREAD_SEMANTICS -Istlport/stlport -Iutf8cpp -Ifreealut-1.1.0/include -Iode-0.11.1/include -Iode-0.11.1/ode/src -Iode-0.11.1/ode/src/joints -Iode-0.11.1/OPCODE -Iode-0.11.1/GIMPACT/include -Iode-0.11.1/ou/include -DPOSIX -D_XOPEN_SOURCE=600 -D_DEBUG -D_CONSOLE -DPNG_NO_ASSEMBLER_CODE -DdSingle -DdTLS_ENABLED=1 -DHAVE_CONFIG_H=1 -DLEPRA_WITHOUT_FMOD -framework OpenGL -framework CoreServices -framework OpenAL -DMAC_OS_X_VERSION=1050 -Wno-unknown-pragmas -o myfile.o -c myfile.cpp
$g++ -shared -framework OpenGL -framework AppKit -framework Cocoa -lobjc -lstlport -framework CoreServices -Lstlport/build/lib/obj/gcc/so -L. -Lopenal-soft-1.10.622 -Lfreealut-1.1.0/admin/VisualStudioDotNET/alut -L../Lepra -L../TBC -L../Cure -L../UiLepra -L../UiTBC -L../UiCure -L../Life -framework OpenAL -o libThirdParty.so myfile.o
Undefined symbols:
"_main", referenced from:
start in crt1.10.5.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
make: *** [libThirdParty.so] Error 1

The solution is to upgrade the compiler. As stated by Adil, 4.1.2 seems to work. Myself, I upgraded to 4.3.4 and that worked great too.

Related

Since Xcode 13.3, I'm seeing an error when compiling in Terminal with -flto

On macOS 12.3 I am working on a patch to build HandBrake with -flto. It then can be build in Terminal with ./configure --lto. This worked nicely with Xcode 13.2 and 13.2.1 installed. But since I have updated to Xcode 13.3 (compiler updated to Apple clang version 13.1.6 (clang-1316.0.21.2)) it fails with the following error:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -target x86_64-apple-macos10.13 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk -L/Users/Nomis101/Documents/GitHub/HandBrakeKopie/build/xroot -L/Users/Nomis101/Documents/GitHub/HandBrakeKopie/build/libhb -L/Users/Nomis101/Documents/GitHub/HandBrakeKopie/build/contrib/lib -F/Users/Nomis101/Documents/GitHub/HandBrakeKopie/build/xroot -filelist /Users/Nomis101/Documents/GitHub/HandBrakeKopie/build/xroot/HandBrakeCLI.build/Objects-normal/x86_64/HandBrakeCLI.LinkFileList -Xlinker -object_path_lto -Xlinker /Users/Nomis101/Documents/GitHub/HandBrakeKopie/build/xroot/HandBrakeCLI.build/Objects-normal/x86_64/HandBrakeCLI_lto.o -filelist /Users/Nomis101/Documents/GitHub/HandBrakeKopie/build/macosx/osl.filelist.txt -lc++ -w -framework Foundation -liconv -lbz2 -lz -framework CoreMedia -framework CoreVideo -framework VideoToolbox -framework CoreGraphics -framework CoreText -lavfilter -framework AudioToolbox -framework CoreServices -framework IOKit -lopus -lhandbrake -lass -lavcodec -lavformat -lavutil -lbluray -ldav1d -ldvdnav -ldvdread -lspeex -lturbojpeg -lfreetype -lfribidi -lmp3lame -llzma -lpostproc -logg -lswscale -ltheora -lvorbis -lswresample -lvorbisenc -lvpx -lx264 -lxml2 -ljansson -lharfbuzz -lzimg -Xlinker -dependency_info -Xlinker /Users/Nomis101/Documents/GitHub/HandBrakeKopie/build/xroot/HandBrakeCLI.build/Objects-normal/x86_64/HandBrakeCLI_dependency_info.dat -o /Users/Nomis101/Documents/GitHub/HandBrakeKopie/build/xroot/HandBrakeCLI
ld: linking module flags 'override-stack-alignment': IDs have conflicting values in '/Users/Nomis101/Documents/GitHub/HandBrakeKopie/build/contrib/lib/libx264.a(base.o)' and 'ld-temp.o' for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
** BUILD FAILED **
The following build commands failed:
Ld /Users/Nomis101/Documents/GitHub/HandBrakeKopie/build/xroot/HandBrakeCLI normal (in target 'HandBrakeCLI' from project 'HandBrake')
(1 failure)
make: *** [macosx.build] Error 65
I've tried already to remove and compile the necessary toolchain (nasm, cmake...) with the same version of Xcode. I've reinstalled the CommandLineTools, I removed them completely. I've added flags -fno-stack-check and similar. Nothing helped. I have no idea what the reason of this is, I'm really lost right now. I also could not find anything in the Release Notes of Xcode 13.3.

Set include directory for linker (ld) on OSX

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.

Mac: Undefined symbols for architecture x86_64: "QApplication::palette()", referenced from:

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.

scan-build linker error in xcode target build fails, but links correctly within xcodebuild

so im having a linker error while building an xcode project when using scan-build
for my normal xcodebuild command i use the following
xcodebuild -target LibCoreMobileGHUnit -configuration Debug -sdk iphonesimulator5.0 clean build
and it uses the following options for the linker phase
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld"
-demangle
-dynamic
-arch i386
-all_load
-ios_simulator_version_min 5.0.0
-syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk
-ObjC
-o /Users/ops/workspace/MobileFramework_Test_IOS_Client/LibCoreMobile/build/Debug-iphonesimulator/LibCoreMobileGHUnit.app/LibCoreMobileGHUnit
-lcrt1.o
-L/Users/ops/workspace/MobileFramework_Test_IOS_Client/LibCoreMobile/build/Debug-iphonesimulator
-filelist /Users/ops/workspace/MobileFramework_Test_IOS_Client/LibCoreMobile/build/LibCoreMobile.build/Debug-iphonesimulator/LibCoreMobileGHUnit.build/Objects-normal/i386/LibCoreMobileGHUnit.LinkFileList
-objc_abi_version 2
-no_implicit_dylibs
-lz
-framework QuartzCore
-framework UIKit
-framework Foundation
-framework CoreGraphics
-framework GHUnitIOS
-force_load /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/arc/libarclite_iphonesimulator.a
-framework Foundation
-lobjc
-lc++ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/4.1/lib/darwin/libclang_rt.profile_ios.a
-lSystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/4.1/lib/darwin/libclang_rt.ios.a
-F/Users/ops/workspace/MobileFramework_Test_IOS_Client/LibCoreMobile/build/Debug-iphonesimulator
-F/Applications/Xcode.app/Contents/Developer/Library/Frameworks
-F/Users/ops/workspace/MobileFramework_Test_IOS_Client/LibCoreMobile/LibCoreMobileGHUnit
-F/Users/ops/workspace/MobileFramework_Test_IOS_Client/LibCoreMobile/ExternalFrameworks
and this is sucessfull
however when I run the following
scan-build -k -v -v -o ../clangScanBuildReports xcodebuild -target LibCoreMobileGHUnit -configuration Debug -sdk iphonesimulator5.0 clean build
it links with the following options:
"/usr/llvm-gcc-4.2/libexec/gcc/i686-apple-darwin11/4.2.1/ld"
-dynamic
-arch i386
-all_load
-ios_simulator_version_min 5.0.0
-syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk
-ObjC
-o /Users/ops/workspace/MobileFramework_Test_IOS_Client/LibCoreMobile/build/Debug-iphonesimulator/LibCoreMobileGHUnit.app/LibCoreMobileGHUnit
-lcrt1.o
-L/Users/ops/workspace/MobileFramework_Test_IOS_Client/LibCoreMobile/build/Debug-iphonesimulator
-filelist /Users/ops/workspace/MobileFramework_Test_IOS_Client/LibCoreMobile/build/LibCoreMobile.build/Debug-iphonesimulator/LibCoreMobileGHUnit.build/Objects-normal/i386/LibCoreMobileGHUnit.LinkFileList
-objc_abi_version 2
-no_implicit_dylibs
-lz
-framework QuartzCore
-framework UIKit
-framework Foundation
-framework CoreGraphics
-framework GHUnitIOS
-force_load /Users/ops/tools/checker-269/lib/arc/libarclite_iphonesimulator.a
-framework Foundation
-lobjc
-lc++
-lSystem
-F/Users/ops/workspace/MobileFramework_Test_IOS_Client/LibCoreMobile/build/Debug-iphonesimulator
-F/Applications/Xcode.app/Contents/Developer/Library/Frameworks
-F/Users/ops/workspace/MobileFramework_Test_IOS_Client/LibCoreMobile/LibCoreMobileGHUnit
-F/Users/ops/workspace/MobileFramework_Test_IOS_Client/LibCoreMobile/ExternalFrameworks
so theres a few things here that are different
when running scan-build it seems to be using a different linker
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld vs
/usr/llvm-gcc-4.2/libexec/gcc/i686-apple-darwin11/4.2.1/ld
in the normal xcodebuild it has an extra option -demangle
and in the scan-build it is missing the two libclang libs
-lc++ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/4.1/lib/darwin/libclang_rt.profile_ios.a
-lSystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/4.1/lib/darwin/libclang_rt.ios.a
Does anyone know how i could force the libaries to be included in the linker flags on the "scan-build" execution.

Make Error while Installing Ruby 1.9.2-180

/usr/bin/gcc-4.2 -dynamic -bundle -o ../../.ext/x86_64-darwin11.3.0/tcltklib.bundle
stubs.o tcltklib.o -L. -L../.. -L/Users/jasonvdm/.rvm/usr/lib - L/System/Library/Frameworks/Tcl.framework -L/System/Library/Frameworks/Tk.framework -L. -L/usr/local/lib -lpthread -framework CoreFoundation -F/System/Library/Frameworks -framework Tcl -lpthread -framework CoreFoundation -framework Cocoa -framework Carbon -framework IOKit -lpthread -framework CoreFoundation -F/System/Library/Frameworks -framework Tk -Wl,-undefined,dynamic_lookup -Wl,-multiply_defined,suppress -Wl,-flat_namespace -lruby.1.9.1 -lm -ldl -lpthread -ldl -lobjc
ld: in /usr/local/lib/libxml2.2.dylib, file was built for unsupported file format which is not the architecture being linked (x86_64) for architecture x86_64
collect2: ld returned 1 exit status
make[1]: *** [../../.ext/x86_64-darwin11.3.0/tcltklib.bundle] Error 1
make: *** [mkmain.sh] Error 1
I'm getting a make error:
Error running 'make', please read /Users/jasonvdm/.rvm/log/ruby-1.9.2-p320/make.log
There has been an error while running make. Halting the installation.
This is the same for p180. I have installed readline and everything already. I'm trying to install 1.9.3, with similar errors. I've tried installing with clang and readline flags, nothing works.
It appears that this is my main error:
ld: in /usr/local/lib/libxslt.1.dylib, file was built for unsupported file format which
is not the architecture being linked (x86_64) for architecture x86_64
Are you using OSX??
You can try use:
rvm install ruby-1.9.2-p320 --with-gcc=clang
Or:
CC=/usr/local/bin/gcc-4.2 rvm install ruby-1.9.2-p320

Resources