Compile simple hello world ZeroMQ C example, compile flags? - c

Trying to compile the example hello_world.c from the zeromq tutorial:
http://zguide.zeromq.org/page:all#Ask-and-Ye-Shall-Receive
Pretty sure I have everything installed in OSX Mountain Lion.
clang -Wall hwserver.c -o hwserver
gives me an error:
Undefined symbols for architecture x86_64:
"_zmq_bind", referenced from:
_main in hwserver-OgrEe6.o
"_zmq_ctx_new", referenced from:
_main in hwserver-OgrEe6.o
"_zmq_msg_close", referenced from:
_main in hwserver-OgrEe6.o
"_zmq_msg_data", referenced from:
_main in hwserver-OgrEe6.o
"_zmq_msg_init", referenced from:
_main in hwserver-OgrEe6.o
"_zmq_msg_init_size", referenced from:
_main in hwserver-OgrEe6.o
"_zmq_msg_recv", referenced from:
_main in hwserver-OgrEe6.o
"_zmq_msg_send", referenced from:
_main in hwserver-OgrEe6.o
"_zmq_socket", referenced from:
_main in hwserver-OgrEe6.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'm not the most experienced in C. Not sure if I sure be adding a compiler flag for the zmq dylib or headers or my $PATH being off.
in /usr/local/lib:
libzmq.3.dylib
libzmq.a
libzmq.dylib
libzmq.la
and in /usr/local/include:
zmq.h
zmq_utils.h
and echo $PATH:
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/lib/:/usr/local/include/

You list the ZeroMQ libraries in your question, but you do not actually link with them. Change the command line to this:
clang -Wall hwserver.c -o hwserver -L/usr/local/lib -lzmq
Explanation of the extra arguments:
-L/usr/local/lib tells the linker to add a path (/usr/local/lib) to the library search path.
-lzmq tells the library to link with the zmq library.
The $PATH environment variable have nothing to do with this, it just tells the shell where to look for commands.

Related

Mac OS X Sierra : Undefined symbols for architecture x86_64

I am trying to build a C source file based on Linphone in Mac OS X Sierra but getting the following error.
This is the link for the C source file.
http://www.linphone.org/docs/liblinphone/group__basic__call__tutorials.html
Edited:
I am trying to compile the source code with this command
clang -o tt tt.c -I/Users/softdev/Downloads/linphone-sdk-3.11.1-mac/include/
Error:
Undefined symbols for architecture x86_64
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I have tried to change the target cpu but didn't work.
My system has XCode 8. Any help regarding this will be appreciated.
Edited: Complete Output
Undefined symbols for architecture x86_64:
"_linphone_call_get_state", referenced from:
_main in tt-ca2045.o
"_linphone_call_ref", referenced from:
_main in tt-ca2045.o
"_linphone_call_unref", referenced from:
_main in tt-ca2045.o
"_linphone_core_destroy", referenced from:
_main in tt-ca2045.o
"_linphone_core_invite", referenced from:
_main in tt-ca2045.o
"_linphone_core_iterate", referenced from:
_main in tt-ca2045.o
"_linphone_core_new", referenced from:
_main in tt-ca2045.o
"_linphone_core_terminate_call", referenced from:
_main in tt-ca2045.o
"_ms_usleep", referenced from:
_main in tt-ca2045.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 got the sample code to compile using this:
clang -o hello hello.c -Ilinphone-sdk-3/include -Llinphone-sdk-3/lib -llinphone -lmediastreamer_base
Clang's -I parameter points to the where the header (.h) files live
And as for my additions, -L specifies the path for clang to get to where the lib files live. In your case, it might live in -L/Users/softdev/Downloads/linphone-sdk-3.11.1-mac/lib
then -l specifies which dylibs you want to include (strip off the lib prefix and the dylib suffix).
Lastly, you need to add a missing line to the sample code you pointed to. Add:
#include <unistd.h>
after signal.h

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.

Error while compiling ncurses app on Mac OS X

I'm trying to compile ncurses based app on Mac OS X 10.6.8 but I get this error.
Undefined symbols for architecture x86_64:
"_initscr", referenced from:
_main in ccf8K8YG.o
"_printw", referenced from:
_main in ccf8K8YG.o
"_stdscr", referenced from:
_main in ccf8K8YG.o
"_wrefresh", referenced from:
_main in ccf8K8YG.o
"_wgetch", referenced from:
_main in ccf8K8YG.o
"_endwin", referenced from:
_main in ccf8K8YG.o
What could be the problem ?
I'm pretty sure this is because you're not including the ncurses library when compiling.
Try adding:
-lncurses
when compiling.
For example (for C++):
g++ -o hello main.cpp -lncurses
Or using gcc (for C):
gcc -o hello main.cpp -lncurses
This short command will compile and execute:
gcc -o hello main.cpp -lncurses && ./hello
This was my issue, I hope this helps someone.

How to include hdf5 header files in a C program on Mac OS X?

I am trying to learn how to program in C, and I want to be able to import data into my C program from a .hdf file.
I am using a mid 2009 MacBook Pro with Mac OS X lion.
I think I am having problems, because I didn't know where on my system to put all the header files associated with hdd (remember, I'm a bit of a noob). So I just downloaded the hdf5-1.8.9-freebsd-shared folder from the hdd website, and manually dragged all the .h files from the /include subdirectory into the /usr/include directory onto my computer.
When I try to compile my .c program using the normal gcc terminal command, I get an error which is along the lines of (sorry about the formatting but I think the exact error doesn't matter too much anyway):
Undefined symbols for architecture x86_64:
"_H5check_version", referenced from:
_main in cc9FVO6S.o
"_H5Fcreate", referenced from:
_main in cc9FVO6S.o
"_H5Screate_simple", referenced from:
_main in cc9FVO6S.o
"_H5open", referenced from:
_main in cc9FVO6S.o
"_H5T_STD_I32LE_g", referenced from:
_main in cc9FVO6S.o
"_H5Dcreate2", referenced from:
_main in cc9FVO6S.o
"_H5T_NATIVE_INT_g", referenced from:
_main in cc9FVO6S.o
"_H5Dwrite", referenced from:
_main in cc9FVO6S.o
"_H5Dclose", referenced from:
_main in cc9FVO6S.o
"_H5Sclose", referenced from:
_main in cc9FVO6S.o
"_H5Fclose", referenced from:
_main in cc9FVO6S.o
"_H5Fopen", referenced from:
_main in cc9FVO6S.o
"_H5Dopen2", referenced from:
_main in cc9FVO6S.o
"_H5Dread", referenced from:
_main in cc9FVO6S.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
Though the exact error varies depending on exactly what code I am trying to compile. This was generated when I tried to compile a sample program.
Does anybody have any experience with getting hdf5 to work in C in Mac OS X? I have found it all very confusing.
By the way, I normally use python, and frequently use h5py without trouble.
You have to tell your linker when you are using a library using -l<library-name> and -L<library-dir> for non-standard locations.
If you installed hdf5 in /usr/local/hdf5, you need something like:
gcc -o h5ex_d_rdwr h5ex_d_rdwr.c -I/usr/local/hdf5/include -L/usr/local/hdf5/lib -lhdf5
If you are using the High-Level API, also add -lhdf5_hl.
If you have pkg-config installed and it is aware of your hdf5 installation, you can let it do it for you:
gcc -o h5ex_d_rdwr h5ex_d_rdwr.c `pkg-config hdf5 --cflags --libs`

How can I use GLUT with CUDA on MACOSX?

I'm having problems compiling a CUDA program that uses GLUT on MacOsX. Here is the command line I use to compile the source:
nvcc main.c -o main -Xlinker "-L/System/Library/Frameworks/OpenGL.framework/Libraries -lGL -lGLU" "-L/System/Library/Frameworks/GLUT.framework"
And here is the errors I get:
Undefined symbols:
"_glutInitWindowSize", referenced from:
_main in tmpxft_00001612_00000000-1_main.o
"_glutInitWindowPosition", referenced from:
_main in tmpxft_00001612_00000000-1_main.o
"_glutDisplayFunc", referenced from:
_main in tmpxft_00001612_00000000-1_main.o
"_glutInitDisplayMode", referenced from:
_main in tmpxft_00001612_00000000-1_main.o
"_glutCreateWindow", referenced from:
_main in tmpxft_00001612_00000000-1_main.o
"_glutMainLoop", referenced from:
_main in tmpxft_00001612_00000000-1_main.o
"_glutInit", referenced from:
_main in tmpxft_00001612_00000000-1_main.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
I am aware that I haven't specified any lib for GLUT but I just can't find it! Does anybody know where it is? By the way, there doesn't seem to be a way to use the GLUT.framework when compiling with nvcc.
Thanks a lot,
omegatai
Looks like you probably already have your answer, but for future reference, you can just use
-Xlinker -framework,OpenGL,-framework,GLUT
instead of the whole
-L/System/Library/Frameworks/OpenGL.framework/Libraries -lGL -lGLU
when working with nvcc. Source: http://forums.nvidia.com/index.php?showtopic=163995
Here it is:
http://developer.apple.com/mac/library/samplecode/glut/index.html
None of these solutions worked for me. What I needed was just:
-framework GLUT -framework openGL -lGLEW

Resources