symbol picked up from wrong dylib on linking - macos

I am linking a binary which imports a symbol defined in two dependent dylibs, and I can't make ld to pick the correct one.
The symbol is _init_process and it's defined both in libSystem.dylib (added by ld implicitly) and libida.dylib (our library). I want ld to pick libida but I can't make it work.
Here's the final linker command line:
/usr/libexec/gcc/i686-apple-darwin10/4.2.1/ld -dynamic -dylib
-dylib_compatibility_version 1.0 -dylib_current_version 1.0 -arch
i386 -macosx_version_min 10.5 -macosx_version_min 10.5
-single_module -weak_reference_mismatches non-weak -w -o
../../bin/x86_mac_gcc/plugins/python.pmc -ldylib1.10.5.o
-L../../bin/x86_mac_gcc/
-L/Developer/SDKs/MacOSX10.5.sdk/usr/lib/i686-apple-darwin10/4.2.1
-L/Developer/SDKs/MacOSX10.5.sdk/usr/lib
-L/usr/lib/gcc/i686-apple-darwin10/4.2.1
-L/usr/lib/gcc/i686-apple-darwin10/4.2.1
-L/Developer/SDKs/MacOSX10.5.sdk/usr/lib/gcc/i686-apple-darwin10/4.2.1/../../../i686-apple-darwin10/4.2.1
-L/Developer/SDKs/MacOSX10.5.sdk/usr/lib/gcc/i686-apple-darwin10/4.2.1/../../..
-v -lpthread ../../lib/x86_mac_gcc_32/libiconv.2.2.0.dylib
obj/x86_mac_gcc_32/python.o32 obj/x86_mac_gcc_32/idaapi.o32 -lida
-install_name python.pmc -lpython2.6 -ldl -why_load
-search_paths_first -t -lstdc++ -lgcc_s.10.5 -lgcc -lSystem
As you can see, -lida comes before -lSystem, so I would expect ld to pick libida.dylib first, but it's not happening:
dlopen(/home/test/build/bin/x86_mac_gcc/plugins/python.pmc): dlopen(/home/test/build/bin/x86_mac_gcc/plugins/python.pmc, 2): Symbol not found: _init_process
Referenced from: /home/test/build/bin/x86_mac_gcc/plugins/python.pmc
Expected in: /usr/lib/libSystem.B.dylib
in /home/test/build/bin/x86_mac_gcc/plugins/python.pmc
/home/test/build/bin/x86_mac_gcc/plugins/python.pmc: can't load file
Debug output from the linker:
Library search paths:
../../bin/x86_mac_gcc/
/Developer/SDKs/MacOSX10.5.sdk/usr/lib/i686-apple-darwin10/4.2.1
/Developer/SDKs/MacOSX10.5.sdk/usr/lib
/usr/lib/gcc/i686-apple-darwin10/4.2.1
/usr/lib/gcc/i686-apple-darwin10/4.2.1
/Developer/SDKs/MacOSX10.5.sdk/usr/lib/i686-apple-darwin10/4.2.1
/Developer/SDKs/MacOSX10.5.sdk/usr/lib
/usr/lib
/usr/local/lib
Framework search paths:
/Library/Frameworks/
/System/Library/Frameworks/
/Developer/SDKs/MacOSX10.5.sdk/usr/lib/dylib1.10.5.o
/Developer/SDKs/MacOSX10.5.sdk/usr/lib/libpthread.dylib
../../lib/x86_mac_gcc_32/libiconv.2.2.0.dylib
obj/x86_mac_gcc_32/python.o32
obj/x86_mac_gcc_32/idaapi.o32
../../bin/x86_mac_gcc//libida.dylib
/usr/lib/libpython2.6.dylib
/Developer/SDKs/MacOSX10.5.sdk/usr/lib/libdl.dylib
/Developer/SDKs/MacOSX10.5.sdk/usr/lib/i686-apple-darwin10/4.2.1/libstdc++.dylib
/Developer/SDKs/MacOSX10.5.sdk/usr/lib/libgcc_s.10.5.dylib
/usr/lib/gcc/i686-apple-darwin10/4.2.1/libgcc.a
/Developer/SDKs/MacOSX10.5.sdk/usr/lib/libSystem.dylib
/usr/lib/system/libmathCommon.A.dylib

Solved it. The culprit was -lpthread - libpthread is a symlink to libSystem:
$ ls -la /Developer/SDKs/MacOSX10.5.sdk/usr/lib/libpthread.dylib
lrwxr-xr-x 1 root wheel 15 Nov 9 2011 /Developer/SDKs/MacOSX10.5.sdk/usr/lib/libpthread.dylib -> libSystem.dylib
After moving it after -lida, everything works as expected.

Related

math library and POSIX realtime extensions for Mac

Although more a novice I try to explain my problem.
I am on a Mac and use command line to build the executable. The compiling command works successfully on Ubuntu.
cc program.o file1.o file2.o file3.o file4.o -lm -lrt -o program
ld: library not found for -lrt
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [program] Error 1
If I run with -v command I get the following:
Apple LLVM version 7.0.2 (clang-700.1.81)
Target: x86_64-apple-darwin14.5.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 program program.o file1.o file2.o file3.o file4.o -lm -lrt -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 -lrt
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Any hint?
I found in this post what -lm -lrt mean but still could not figure out a solution.
Update 1: According to this link -lrt is not available for Mac.
Update 2: I have found two possible solutions: (a) either to remove completely the flag or (b) use the -lSystem.B instead. The real-time extensions seems to be in libSystem.B.dylib as explained here.

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.

Building GCC-4.9.2 on OS X Yosemite

Ok, I'm having trouble building gcc-4.9.2 on Apple's new OS X Yosemite. I'm not sure if I need to be building a gnu-gcc compiler on OS X, as most other software has compiled fine, apart from tesseract-3.0.1 and some of my own wxWidgets applications. Are there certain programs/code features that clang can't compile?
My build steps are as follows:
cd build-gcc
../gcc-4.9.1/configure --program-prefix="gnu-" --prefix="/usr/local/gcc-4.9.1" --with-gmp="/usr/local" --with-mpfr="/usr/local" --with-mpc="/usr/local" CC=clang CXX=clang++
make
My build path and gcc source paths do not contain any whitespace, and I have installed GMP, MPFR and MPC in /usr/local.
My build outputs are:
clang++ -g -DIN_GCC -fno-exceptions -fno-rtti -fasynchronous-unwind-tables -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual -Wno-format -Wmissing-format-attribute -pedantic -Wno-long-long -Wno-variadic-macros -Wno-overlength-strings -fno-common -DHAVE_CONFIG_H -Wl,-no_pie -o cc1 c/c-lang.o c-family/stub-objc.o attribs.o c/c-errors.o c/c-decl.o c/c-typeck.o c/c-convert.o c/c-aux-info.o c/c-objc-common.o c/c-parser.o c/c-array-notation.o c-family/c-common.o c-family/c-cppbuiltin.o c-family/c-dump.o c-family/c-format.o c-family/c-gimplify.o c-family/c-lex.o c-family/c-omp.o c-family/c-opts.o c-family/c-pch.o c-family/c-ppoutput.o c-family/c-pragma.o c-family/c-pretty-print.o c-family/c-semantics.o c-family/c-ada-spec.o c-family/c-cilkplus.o c-family/array-notation-common.o c-family/cilk.o c-family/c-ubsan.o i386-c.o darwin-c.o \
cc1-checksum.o libbackend.a main.o tree-browser.o libcommon-target.a libcommon.a ../libcpp/libcpp.a ../libdecnumber/libdecnumber.a libcommon.a ../libcpp/libcpp.a ./../intl/libintl.a -liconv ../libbacktrace/.libs/libbacktrace.a ../libiberty/libiberty.a ../libdecnumber/libdecnumber.a -L/usr/local/lib -L/usr/local/lib -L/usr/local/lib -lmpc -lmpfr -lgmp -L../zlib -lz
ld: warning: ld: warning: ld: warning: ignoring file libbackend.a, file was built for archive which is not the architecture being linked (x86_64): libbackend.aignoring file libcommon-target.a, file was built for archive which is not the architecture being linked (x86_64): libcommon-target.aignoring file ../libdecnumber/libdecnumber.a, file was built for archive which is not the architecture being linked (x86_64): ../libdecnumber/libdecnumber.a
ld: warning: ignoring file ../zlib/libz.a, file was built for archive which is not the architecture being linked (x86_64): ../zlib/libz.a
Undefined symbols for architecture x86_64:
... (Lots of symbols)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[3]: *** [cc1] Error 1
make[2]: *** [all-stage1-gcc] Error 2
make[1]: *** [stage1-bubble] Error 2
make: *** [all] Error 2
Configure outputs the build type as: x86_64-apple-darwin14.0.0, so I don't understand why this is happening.
Thank You in advance for any help.
Turns out that I had a broken ranlib in /usr/local/bin - maybe GNU Binutils don't work on OS X? All I needed to do to fix the problem was to:
sudo mv /usr/local/bin/ranlib /usr/local/ranlib_old
and then make, and now I have a working GCC!

Undefined symbols "_TLSv1_1_client_method" for x86_64 when compiling httpd on Mac os 10.8

The detail error message is below.
$ ./configure
$ make
then ...
/usr/share/apr-1/build-1/libtool --silent --mode=link /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.8.xctoolchain/usr/bin/cc -lssl -lcrypto -lpthread \
-o ab ab.lo -L/usr/lib -R/usr/lib -laprutil-1 -lexpat -liconv -lsqlite3 -lldap -llber -llber -L/usr/lib -R/usr/lib -lapr-1 -lpthread
Undefined symbols for architecture x86_64:
"_TLSv1_1_client_method", referenced from:
_main in ab.o
"_TLSv1_2_client_method", referenced from:
_main in ab.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
APR and apr-util are required dependencies.
So - before building httpd on Mac,
port install APR
port install apr-util
Solved this.
Additionally, you might have to set the 'OPENSSL_ROOT_DIR' variable to '/opt/local'.
You can do that by giving '-DOPENSSL_ROOT_DIR=/opt/local' as command line argument when executing cmake.

Compiling VLCKit framework

I'm following the directions on this page: http://wiki.videolan.org/Mac_OS_X_Framework
I can build the core components, but when I try to build framework I have an error
How can I fix it?
Build VLCKit of project VLCKit with configuration Debug
PhaseScriptExecution "Run Script" build/VLCKit.build/Debug/VLCKit.build/Script-EF78BD2E0CAEEF9500354E6E.sh
cd /Users/ragopor/vlc/projects/macosx/framework
/bin/sh -c /Users/ragopor/vlc/projects/macosx/framework/build/VLCKit.build/Debug/VLCKit.build/Script-EF78BD2E0CAEEF9500354E6E.sh
Building modules folder...
find: /Users/ragopor/vlc/projects/macosx/framework/build/vlc_build_dir/modules: No such file or directory
Removing module libmacosx_plugin.dylib
rm: /Users/ragopor/vlc/projects/macosx/framework/build/Debug/VLCKit.framework/Versions/A/modules/libmacosx_plugin.dylib: No such file or directory
Building library folder...
Building share folder...
Headers not needed for this product
Ld build/Debug/VLCKit.framework/Versions/A/VLCKit normal i386
cd /Users/ragopor/vlc/projects/macosx/framework
setenv MACOSX_DEPLOYMENT_TARGET 10.6
/Developer/usr/bin/llvm-gcc-4.2 -arch i386 -dynamiclib -isysroot /Developer/SDKs/MacOSX10.6.sdk -L/Users/ragopor/vlc/projects/macosx/framework/build/Debug -L/Users/ragopor/vlc/projects/macosx/framework/build/Debug/VLCKit.framework/lib -F/Users/ragopor/vlc/projects/macosx/framework/build/Debug -filelist /Users/ragopor/vlc/projects/macosx/framework/build/VLCKit.build/Debug/VLCKit.build/Objects-normal/i386/VLCKit.LinkFileList -install_name #loader_path/../Frameworks/VLCKit.framework/Versions/A/VLCKit -mmacosx-version-min=10.6 -single_module -read_only_relocs suppress -lvlc -framework Cocoa -framework QuartzCore -single_module -compatibility_version 1 -current_version 1 -o /Users/ragopor/vlc/projects/macosx/framework/build/Debug/VLCKit.framework/Versions/A/VLCKit
ld: library not found for -lvlc
collect2: ld returned 1 exit status
Command /Developer/usr/bin/llvm-gcc-4.2 failed with exit code 1
Maybe too late, but check this out

Resources