Jansson on Xcode - c

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

Related

Tcl module: symbol(s) not found for architecture x86_64

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?

Symbol not found - linking to hdf library

I am trying to use the hdf5-format to store data. Problem is, that I fail to link against the library. I have the following code
#include <H5Cpp.h>
int main(void){
H5::H5File file("test_MatrixRoundTrip_Double.h5", H5F_ACC_TRUNC);
}
and compile it using
gcc -std=c++11 -o main main.cpp -I /usr/local/include/ -L /usr/local/lib/ -lhdf5 -lhdf5_hl
This always returns the error
Undefined symbols for architecture x86_64:
"H5::FileAccPropList::DEFAULT", referenced from:
_main in main-c207d1.o
"H5::FileCreatPropList::DEFAULT", referenced from:
_main in main-c207d1.o
"H5::H5File::H5File(char const*, unsigned int, H5::FileCreatPropList const&, H5::FileAccPropList const&)", referenced from:
_main in main-c207d1.o
"H5::H5File::~H5File()", referenced from:
_main in main-c207d1.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 installed the hdf5 library on OSX using
brew install homebrew/science/hdf5
What am I doing wrong here?
You are including the HDF5 C++ header file, but only linking the HDF5 C library. Add the line: -lhdf5_cpp to link the C++ shared object and use locate libhdf5_cpp to find it's libpath.

Getting Apple Mach-O Linker error C99. How do i fix it?

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.

Trouble Linking when compiling a MEX file

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.

Undefine symbols for architecture x86_64 using FFTW

Ceeloss-MacBook-Pro:desktop ceelos$ gcc -o prog -I/usr/local/include test.c
Undefined symbols for architecture x86_64:
"_fftw_destroy_plan", referenced from:
_main in test-IBqBdS.o
"_fftw_execute", referenced from:
_main in test-IBqBdS.o
"_fftw_plan_dft_1d", referenced from:
_main in test-IBqBdS.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Ceeloss-MacBook-Pro:desktop ceelos$
What's this telling me?
It's telling you that you forgot to use -L and -l to tell gcc where the FFTW libraries are and what they're called.

Resources