Mac proj.4 compile error - c

I installed proj.4 library with homebrew on my Mac 10.7 (using gcc-4.2). When trying to compile the following code:
#include <proj_api.h>
int main(void) {
projPJ pj_merc;
pj_merc = pj_init_plus("+proj=merc");
pj_free(pj_merc);
return 0;
}
I'm getting this error:
$ gcc-4.2 test.c
Undefined symbols for architecture x86_64:
"_pj_init_plus", referenced from:
_main in cccf4vey.o
"_pj_free", referenced from:
_main in cccf4vey.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
EDIT:
The library file is 64bit (gcc-4.2 -m32 test.c lead to the same error):
$ file /usr/local/lib/libproj.dylib
/usr/local/lib/libproj.dylib: Mach-O 64-bit dynamically linked shared library x86_64
Any ideas what's wrong?
Thank you!

You should link against the library.
gcc-4.2 test.c -L/usr/local/lib -lproj
This is what the error is complaining about

Related

linker error when running a simple hello world on Mac Mojave

I am getting the following linker error:
Source (hello_world.c):
#include <stdio.h>
int main(){
printf("hello world\n");
return 0;
}
Compilation:
$ gcc hello_world.c
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)
$

testu01 installation problems on mac OS X

I installed testu01 on my mac (OS El Capitan). I want to compile one of the examples using gcc, code below. But I get the following error, below. Did anybody run TestU01 on x86_64 successfully? Any other suggestions?
MacBook-Pro-2:examples Joan$ gcc -std=c99 -Wall -O3 -o birth1 birth1.c -I/Users/TestU01/TestU01-1.2.3/include -I/Users/TestU01/TestU01-1.2.3/mylib
Undefined symbols for architecture x86_64:
"_smarsa_BirthdaySpacings", referenced from:
_main in birth1-c99705.o
"_ulcg_CreateLCG", referenced from:
_main in birth1-c99705.o
"_ulcg_DeleteGen", referenced from:
_main in birth1-c99705.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

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.

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.

How do I compile simple gearman worker with C?

I am trying to compile a simple gearman worker on C. I use mac. Here is the code:
#include <libgearman/gearman.h>
int main(void) {
gearman_worker_st worker;
gearman_worker_create(&worker);
gearman_worker_add_server(&worker, "localhost", 4730);
return 0;
}
When I try to compile it with:
#gcc test.c
Undefined symbols for architecture x86_64:
"_gearman_worker_add_server", referenced from:
_main in ccLUuf8y.o
"_gearman_worker_create", referenced from:
_main in ccLUuf8y.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
I know I have to link gcc with gearman but when try:
#gcc test.c -lgearman
ld: library not found for -lgearman
collect2: ld returned 1 exit status
Any ideas?
maybe your need to define the lib path, like
-L/usr/lib/, use your libgearman.a stored path to substitute -L/usr/lib/
maybe your need to define the "include path" and the "lib path",
for example,
the head file "libgearman/gearman.h" in the /usr/local,
the library libgearman.so in the /usr/local/libgearman/lib
the compile command like,
gcc -I/usr/local -L/usr/local/libgearman/lib test.c -lgearman
As stated here, you have to link it with -lgearman
gcc test.c -lgearman

Resources