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.
Related
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.
I have used CMake 3.3.0-rc4 to generate an Xcode project for OpenTrack. However, when I attempt to build the ALL_BUILD target in Xcode 6.4, I immediately get the error below.
Libtool build/Debug/libopentrack-version.a normal x86_64
cd /Users/david/Documents/Programming/OpenTrack
export MACOSX_DEPLOYMENT_TARGET=10.10
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool -static -arch_only x86_64 -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk -L/Users/user/Documents/Programming/OpenTrack/build/Debug -filelist /Users/user/Documents/Programming/OpenTrack/build/opentrack.build/Debug/opentrack-version.build/Objects-normal/x86_64/opentrack-version.LinkFileList -stdlib=libc++ -framework Cocoa -framework CoreFoundation -lobjc -lz -framework Carbon -o /Users/user/Documents/Programming/OpenTrack/build/Debug/libopentrack-version.a
error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: unknown option character `t' in: -stdlib=libc++
Usage: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool -static [-] file [...] [-filelist listfile[,dirname]] [-arch_only arch] [-sacLT] [-no_warning_for_no_symbols]
Usage: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool -dynamic [-] file [...] [-filelist listfile[,dirname]] [-arch_only arch] [-o output] [-install_name name] [-compatibility_version #] [-current_version #] [-seg1addr 0x#] [-segs_read_only_addr 0x#] [-segs_read_write_addr 0x#] [-seg_addr_table <filename>] [-seg_addr_table_filename <file_system_path>] [-all_load] [-noall_load]
The Build Settings for the project has the following set for Linking / Other Librarian Flags:
OTHER_LIBTOOLFLAGS = -stdlib=libc++ -framework Cocoa -framework CoreFoundation -lobjc -lz -framework Carbon
From the libtool usage statement above, it looks to me like this set of options was generated for an entirely different version of libtool. What can I do (if anything) to get this project to build with the current version of Xcode?
You cannot use the flag -stdlib=libc++ or -framework with libtool, as they are valid only in the linker, so you should make OTHER_LIBTOOLFLAGS empty as none of those options apply
I would like to know the configurations to run this Hello World program on Xcode. I have installed MacOSXFUSE.
With the command
gcc -Wall hello.c `pkg-config osxfuse --cflags --libs` -o hello
and then with
./hello outputdrive -f -s
I am able to successfully mount the drive outputdrive.
I have environmental variable declare set as -x PKG_CONFIG_PATH="/usr/local/lib/pkgconfig"
MacOSXFUSE is installed in /usr/local/include/osxfuse/
More information:
/usr/local/lib/pkgconfig/osxfuse.pc
data in this file is
prefix=/usr/local
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include
Name: fuse
Description: OSXFUSE
Version: 2.7.3
Libs: -L${libdir} -losxfuse -pthread -liconv
Cflags: -I${includedir}/osxfuse/fuse -D_FILE_OFFSET_BITS=64 -D_DARWIN_USE_64_BIT_INODE
A little progress,
I did this on terminal,
pkg-config osxfuse --cflags --libs
Pasted the below result in "other c flags" in xocde
-D_FILE_OFFSET_BITS=64 -D_DARWIN_USE_64_BIT_INODE -I/usr/local/include/osxfuse/fuse -L/usr/local/lib -losxfuse -pthread -liconv
Now I get the below error,
Undefined symbols for architecture i386:
"_fuse_main_real", referenced from:
_main in main.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Please let me know if more details is required.
You need to put the /usr/local/lib in the "Library search paths" and the library "libosxfuze" to the "Linked Frameworks and Libraries".
does it compile from command line?
g++ hello.c -I/usr/local/include/osxfuse/fuse -D_FILE_OFFSET_BITS=64 -v -L/usr/local/lib -losxfuse
/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
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.