I try to build an example from the book "hacking and securing iOS Applications" by Jonathan Zdziarski, compiling an example with a lot of object-files created. but when compiling the binary with:
export PLATFORM=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform
$PLATFORM/Developer/usr/bin/arm-apple-darwin10-llvm-gcc-4.2 -o launchd launchd.o syscalls.o -static -nostartfiles -nodefaultlibs -nostdlib -W1,-e,_main
the terminal says:
Undefined symbols for architecture armv7:
"start", referenced from:
-u command line option
ld: symbol(s) not found for architecture armv7
collect2: ld returned 1 exit status
Normally, this message shows up, when libraries are missing, but how can i find out, which one? I'm pretty sure, there's no problem with the source code.
-arch armv7 -isysroot -L$(SDK) -L$(SDK)/usr/lib/system
Related
I am trying to test Jansson on Xcode 7.3.1. I installed according to the instructions, then used cMake when that didn't work, which also didn't work. I think Xcode is having trouble finding the Jansson library. I have modified the project header and library paths in many different ways, after extensive suggestions from searching out this problem. Xcode is able to find the header. Note also that I am able to install Jansson and run it in Eclipse. Any insight would be appreciated.
Here is the error log from Xcode:
Ld /Users/corrychapman/Library/Developer/Xcode/DerivedData/JanssonDev-dispcmnteuwiedaiazlbkwtztfcu/Build/Products/Debug/JanssonDev normal x86_64
cd /Users/corrychapman/Desktop/jansson-2.11/JanssonDev
export MACOSX_DEPLOYMENT_TARGET=10.11
/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/corrychapman/Library/Developer/Xcode/DerivedData/JanssonDev-dispcmnteuwiedaiazlbkwtztfcu/Build/Products/Debug -L/usr/local/lib -L/Users/corrychapman/Desktop/jansson-2.11/JanssonDev -F/Users/corrychapman/Library/Developer/Xcode/DerivedData/JanssonDev-dispcmnteuwiedaiazlbkwtztfcu/Build/Products/Debug -filelist /Users/corrychapman/Library/Developer/Xcode/DerivedData/JanssonDev-dispcmnteuwiedaiazlbkwtztfcu/Build/Intermediates/JanssonDev.build/Debug/JanssonDev.build/Objects-normal/x86_64/JanssonDev.LinkFileList -mmacosx-version-min=10.11 -Xlinker -no_deduplicate -Xlinker -dependency_info -Xlinker /Users/corrychapman/Library/Developer/Xcode/DerivedData/JanssonDev-dispcmnteuwiedaiazlbkwtztfcu/Build/Intermediates/JanssonDev.build/Debug/JanssonDev.build/Objects-normal/x86_64/JanssonDev_dependency_info.dat -o /Users/corrychapman/Library/Developer/Xcode/DerivedData/JanssonDev-dispcmnteuwiedaiazlbkwtztfcu/Build/Products/Debug/JanssonDev
Undefined symbols for architecture x86_64:
"_json_array_get", referenced from:
_main in main.o
"_json_array_size", referenced from:
_main in main.o
"_json_delete", referenced from:
_json_decref in main.o
"_json_loads", referenced from:
_main in main.o
"_json_object_get", referenced from:
_main in main.o
"_json_string_value", referenced from:
_main 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)
Found it. Build Settings -> Linking -> Other Linker Flags: -ljansson
I am running the test tcl module from the Swig tutorial site: http://www.swig.org/tutorial.html.
However, when I enter: gcc -shared example.o example_wrap.o -o example.so into the command line, it returns:
Undefined symbols for architecture x86_64:
"_TclFreeObj", referenced from:
__wrap_My_variable_get in example_wrap.o
__wrap_My_variable_set in example_wrap.o
.
.
.
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Any suggestions on what the issue may be?
Can I use for example
gcc -o -S output.s abs.c
to generate an assembly file with name output.s? It seems like I can't. When I try to do that, I got following error message.
Undefined symbols for architecture x86_64: "_main", referenced from:
implicit entry/start for main executable ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit
code 1 (use -v to see invocation)
I do not intend to use the linker, just try to examine the assembly code.
-o must be followed by the name of the output file. So, this would work:
gcc -S abc.c -o output.s
Ld /Users/ashutoshagarwal/Library/Developer/Xcode/DerivedData/c-cnyfflmvjyaashaoduqduqqsfegd/Build/Products/Debug/c normal x86_64
cd /Users/ashutoshagarwal/Desktop/c
setenv MACOSX_DEPLOYMENT_TARGET 10.9
/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/ashutoshagarwal/Library/Developer/Xcode/DerivedData/c-cnyfflmvjyaashaoduqduqqsfegd/Build/Products/Debug -F/Users/ashutoshagarwal/Library/Developer/Xcode/DerivedData/c-cnyfflmvjyaashaoduqduqqsfegd/Build/Products/Debug -filelist /Users/ashutoshagarwal/Library/Developer/Xcode/DerivedData/c-cnyfflmvjyaashaoduqduqqsfegd/Build/Intermediates/c.build/Debug/c.build/Objects-normal/x86_64/c.LinkFileList -mmacosx-version-min=10.9 -framework Foundation -Xlinker -dependency_info -Xlinker /Users/ashutoshagarwal/Library/Developer/Xcode/DerivedData/c-cnyfflmvjyaashaoduqduqqsfegd/Build/Intermediates/c.build/Debug/c.build/Objects-normal/x86_64/c_dependency_info.dat -o /Users/ashutoshagarwal/Library/Developer/Xcode/DerivedData/c-cnyfflmvjyaashaoduqduqqsfegd/Build/Products/Debug/c
Undefined symbols for architecture x86_64:
"_add_history", referenced from:
_main in main.o
"_readline", referenced from:
_main in main.o
_source 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)
I am getting Apple-Mach-O Linker (Id) Error, have sent hours trying to fix this one, Dunno what to do.
It looks like you are using the GNU readline and GNU history libraries, which are available, by default, on the mac in libedit.dylib:
$ nm /usr/lib/libedit.dylib | fgrep readline
0000000000009899 T _readline
000000000001f444 D _readline_echoing_p
000000000001f400 D _rl_readline_name
000000000001f3f8 D _rl_readline_version
$ nm /usr/lib/libedit.dylib | fgrep add_history
000000000000acbc T _add_history
(the T indicates that the symbol is in the library's text section).
Therefore you need to add -ledit to your linker command line. If you are using Xcode then you can add libedit.dylib to the list of libraries to link against or if you are using make then you probably have to edit the LIBS variable in your Makefile.
The error message:
Undefined symbols for architecture x86_64: "_add_history", referenced from: _main in main.o
"_readline", referenced from: _main in main.o _source 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)'
Tells you that the linker cannot find the symbols readline and add_history. Without seeing your source code, and the precise linker and compiler command-lines, it's hard to speculate the exact cause. A likely cause is that you failed to link with external libraries, or other modules of your program.
I am trying to compile a mex file that I wrote in order to run a pre-existing C program in MATLAB. I am getting the following errors:
>> mex src/main.c -Iinclude -I/Users/my_name/mpfr-3.1.1/src/ -I/Users/my_name/gmp-5.0.5 -Lsrc0 -output cpdetect_c
Undefined symbols for architecture x86_64:
"_binomial_main", referenced from:
_cpdetect in main.o
"_gaussian1_main", referenced from:
_cpdetect in main.o
"_gaussianU_main", referenced from:
_cpdetect in main.o
"_mpfr_clears", referenced from:
_cpdetect in main.o
"_mpfr_exp10", referenced from:
_cpdetect in main.o
"_mpfr_inits2", referenced from:
_cpdetect in main.o
"_mpfr_set_d", referenced from:
_cpdetect in main.o
"_poisson_main", referenced from:
_cpdetect in main.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
I am confused because these functions are all part of files that I #Include in my code. How do I get the compiler to find them?
I am running MATLAB R2013a on Mac OS X 10.8 with Xcode version 4.6.3.
Thanks for any advice!
UPDATE1:
#Shai: Contents of my src0 folder:
>> ls src0
Makefile gaussian1.o test_gaussian1.c test_tools.c
Makefile.am loadtraj.c test_gaussian1_point_calc.c test_tools.o
Makefile.in loadtraj.o test_load tools.c
binomial.c main.c test_load.c tools.o
binomial.o main.o test_load.o
cpdetect poisson.c test_poisson.c
gaussian1.c poisson.o test_tools
This C program (originally meant to run on the command line) came from a friend and already had the src0 folder present. I modified the code files in the 'src' folder when writing the mex function, but I didn't touch the src0 folder.
UPDATE 2:
I realized I was pointing to the wrong location for mpfr. I am now using the following compile command:
>> mex src/main.c src/binomial.c src/gaussian1.c src/gaussianU.c src/poisson.c -Iinclude -I/usr/local/include -lmpfr -output cpdetect_c
and it is giving the following errors:
Undefined symbols for architecture x86_64:
"_mpfr_mul_d", referenced from:
_gaussian1_calc_constant_part in gaussian1.o
_gaussianU_calc_constant_part in gaussianU.o
"_mpfr_printf", referenced from:
_find_gaussian1_change_point in gaussian1.o
_gaussian1_point_calc in gaussian1.o
_gaussianU_calc_constant_part in gaussianU.o
_find_gaussianU_change_point in gaussianU.o
_find_poisson_change_point in poisson.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
mex: link of ' "cpdetect_c.mexmaci64"' failed.
This is strange. It's not like the compiler can't find any of the mpfr functions - there are lots of others that it seems to be finding without any trouble (and if I deliberately omit the -lmpfr flag, I get a much longer list of undefined symbols). I did confirm that mpfr_mul_d and mpfr_printf are part of the mpfr distribution I installed. Any ideas? Thanks.
The answer was provided by Amro - it is necessary to both point to the location of the library (using the flag -L/usr/local/lib in this case) and to tell the compiler to link to it (using the flag -lmpfr). Thanks also to Shai for help troubleshooting this.