I'm on OS X 10.7 Lion and have all the dev tools installed, but when I run GCC on a relatively simple program, just straight C with a few calls to openCL functions like clCreateProgramFromSource and the like, I get the following list of errors:
Undefined symbols for architecture x86_64:
"_CreateContext", referenced from:
_build_kernel in ccFuZYMI.o
"_GetDevices", referenced from:
_build_kernel in ccFuZYMI.o
"_CreateCommandQueue", referenced from:
_build_kernel in ccFuZYMI.o
"_clCreateProgramWithSource", referenced from:
_build_kernel in ccFuZYMI.o
"_clBuildProgram", referenced from:
_build_kernel in ccFuZYMI.o
"_clCreateKernel", referenced from:
_build_kernel in ccFuZYMI.o
"_clCreateBuffer", referenced from:
_build_kernel in ccFuZYMI.o
"_clEnqueueWriteBuffer", referenced from:
_sync_run_kernel in ccFuZYMI.o
"_clSetKernelArg", referenced from:
_sync_run_kernel in ccFuZYMI.o
"_clEnqueueNDRangeKernel", referenced from:
_sync_run_kernel in ccFuZYMI.o
"_clEnqueueReadBuffer", referenced from:
_sync_run_kernel in ccFuZYMI.o
"_clReleaseContext", referenced from:
_destroy_kernel in ccFuZYMI.o
"_clReleaseCommandQueue", referenced from:
_destroy_kernel in ccFuZYMI.o
"_clReleaseMemObject", referenced from:
_destroy_kernel in ccFuZYMI.o
"_clReleaseProgram", referenced from:
_destroy_kernel in ccFuZYMI.o
"_clReleaseKernel", referenced from:
_destroy_kernel in ccFuZYMI.o
ld: symbol(s) not found for architecture x86_64
There are some other warnings, but no other errors at compulation stage. This is (in case not clear) a linker error. It seems to be able to see the definitions from the header file while creating the object file, because it gives me warnings about incompatible pointer types.
I have tried pasting into an xcode project, but I get exactly the same errors. I have tried the only other OS X Lion / OpenCL result's solution, and it didn't help.
Looks like you're missing the OpenCL framework - try:
$ gcc -Wall foo.c -framework OpenCL -o foo
It looks to me like you're not linking against the OpenCL libraries. Can you post the link command that you are trying to use? Without that information, simply shooting from the hip: add -framework OpenCL.
Related
This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
How to use SDL with gcc?
(1 answer)
Closed 3 years ago.
I wrote a simple Chip-8 emulator in C (mostly taking inspiration from this; to be honest, just rewriting it in C). It uses SDL 2.0, which I definitely have installed.
As I tried compiling the files (gcc main.c chip8.c -o chip8), I got this stack of errors:
Undefined symbols for architecture x86_64:
"_SDL_CreateRenderer", referenced from:
_main in main-638d2a.o
"_SDL_CreateTexture", referenced from:
_main in main-638d2a.o
"_SDL_CreateWindow", referenced from:
_main in main-638d2a.o
"_SDL_GetError", referenced from:
_main in main-638d2a.o
"_SDL_Init", referenced from:
_main in main-638d2a.o
"_SDL_PollEvent", referenced from:
_main in main-638d2a.o
"_SDL_RenderClear", referenced from:
_main in main-638d2a.o
"_SDL_RenderCopy", referenced from:
_main in main-638d2a.o
"_SDL_RenderPresent", referenced from:
_main in main-638d2a.o
"_SDL_RenderSetLogicalSize", referenced from:
_main in main-638d2a.o
"_SDL_UpdateTexture", referenced from:
_main in main-638d2a.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 very sure I used the correct #include (#include "SDL2/SDL.h"). This is my project structure:
chip-8
—— main.c
–– chip8.c
–– chip8.h
–– INVADERS (rom file)
Why doesn't the linker work with this? Are any other compiler flags required?
Why doesn't the linker work with this? Are any other compiler flags required?
Yes, you need to tell the linker which libraries to link against, e.g.:
-lSDL2
See How to use SDL with gcc?
I'm very new to Rust. It seems to be a very interesting language, but when I compile a simple hello world program, I get a gigantic error. This is the error I'm getting:
note: "cc" "-m64" "-L" "/usr/local/lib/rustlib/x86_64-apple-darwin/lib" "hello.0.o" "-o" "hello" "-Wl,-force_load,/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libmorestack.a" "-Wl,-dead_strip" "-nodefaultlibs" "/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libstd-198068b3.rlib" "/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libcollections-198068b3.rlib" "/usr/local/lib/rustlib/x86_64-apple-darwin/lib/librustc_unicode-198068b3.rlib" "/usr/local/lib/rustlib/x86_64-apple-darwin/lib/librand-198068b3.rlib" "/usr/local/lib/rustlib/x86_64-apple-darwin/lib/liballoc-198068b3.rlib" "/usr/local/lib/rustlib/x86_64-apple-darwin/lib/liblibc-198068b3.rlib" "/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libcore-198068b3.rlib" "-L" "/usr/local/lib/rustlib/x86_64-apple-darwin/lib" "-L" "/Users/<removed>/Documents/cringe/.rust/lib/x86_64-apple-darwin" "-L" "/Users/<removed>/Documents/cringe/lib/x86_64-apple-darwin" "-l" "System" "-l" "pthread" "-l" "c" "-l" "m" "-l" "compiler-rt"
note: couldn't understand kern.osversion `14.5.0'
ld: warning: directory not found for option '-L/Users/<removed>/Documents/cringe/.rust/lib/x86_64-apple-darwin'
ld: warning: directory not found for option '-L/Users/<removed>/Documents/cringe/lib/x86_64-apple-darwin'
Undefined symbols for architecture x86_64:
"__Unwind_GetLanguageSpecificData", referenced from:
___gcc_personality_v0 in libcompiler-rt.a(gcc_personality_v0.o)
"__Unwind_GetIP", referenced from:
___gcc_personality_v0 in libcompiler-rt.a(gcc_personality_v0.o)
"__Unwind_SetIP", referenced from:
___gcc_personality_v0 in libcompiler-rt.a(gcc_personality_v0.o)
"__Unwind_DeleteException", referenced from:
rt::lang_start::hd654f015947477d622w in libstd-198068b3.rlib(std-198068b3.0.o)
"__Unwind_RaiseException", referenced from:
rt::unwind::imp::panic::h3a53abf3818f0dd1jqw in libstd-198068b3.rlib(std-198068b3.0.o)
"__Unwind_SetGR", referenced from:
___gcc_personality_v0 in libcompiler-rt.a(gcc_personality_v0.o)
"__Unwind_GetIPInfo", referenced from:
sys::backtrace::write::trace_fn::h510f8e821e33fb3fMus in libstd-198068b3.rlib(std-198068b3.0.o)
"__Unwind_Backtrace", referenced from:
sys::backtrace::write::h71ee98355e9ff89fUss in libstd-198068b3.rlib(std-198068b3.0.o)
"__Unwind_GetRegionStart", referenced from:
___gcc_personality_v0 in libcompiler-rt.a(gcc_personality_v0.o)
"__Unwind_Resume", referenced from:
error::Box$LT$Error$u2b$$u20$Send$u20$$u2b$$u20$Sync$u20$$u2b$$u20$$u27$a$GT$.From$LT$$RF$$u27$b$u20$str$GT$::from::haef03d11abb0506f6da in libstd-198068b3.rlib(std-198068b3.0.o)
thread..Inner::drop.33811::h2d4ce2ad919a880a in libstd-198068b3.rlib(std-198068b3.0.o)
sys_common::thread_info::current_thread::h002e72f07e6510beVwr in libstd-198068b3.rlib(std-198068b3.0.o)
thread::Thread::new::h823fd9fbff518de4EBb in libstd-198068b3.rlib(std-198068b3.0.o)
rt::unwind::begin_unwind_inner::h1a353d5ea12e1abeVBw in libstd-198068b3.rlib(std-198068b3.0.o)
rt::unwind::begin_unwind_fmt::h523af64a13dd33d21Aw in libstd-198068b3.rlib(std-198068b3.0.o)
sys::os::getenv::hdf9b4093693c98ceLLu in libstd-198068b3.rlib(std-198068b3.0.o)
...
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
error: aborting due to previous error
This is the program:
fn main() {
println!("Hello, World!");
}
I'm on OS X 10.10.5 (14F27). My Rust version is rustc 1.3.0 (9a92aaf19 2015-09-15)
Try to install libpq-dev, libpq-devel, gcc-multilib, postgresql-devel
(Install them by your own package manager, Sometimes package names differ depending on your platform, so do a quick google search "if doesn't work")
If none of these solutions work:
Try:
rustup self uninstall and reinstall it by: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
I am following this short tutorial
and trying to compile Webots application (written in C) using GHC (Glasgow Haskell Compiler, Version 7.10.1) with following command:
ghc --make -no-hs-main -optc-O
-I"/Applications/Webots/include/controller/c/"
-L"/Applications/Webots/lib/"
-outputdir build/release/
advanced_genetic_algorithm_supervisor.c
Safe
-o advanced_genetic_algorithm_supervisor
and getting the following error during the linking phase:
Linking advanced_genetic_algorithm_supervisor ...
Undefined symbols for architecture x86_64:
"_wb_display_draw_text", referenced from:
_main in advanced_genetic_algorithm_supervisor.o
"_wb_display_get_height", referenced from:
_main in advanced_genetic_algorithm_supervisor.o
"_wb_display_get_width", referenced from:
_main in advanced_genetic_algorithm_supervisor.o
"_wb_emitter_send", referenced from:
_evaluate_genotype in advanced_genetic_algorithm_supervisor.o
"_wb_receiver_enable", referenced from:
_main in advanced_genetic_algorithm_supervisor.o
"_wb_receiver_get_data", referenced from:
_check_for_slaves_data in advanced_genetic_algorithm_supervisor.o
"_wb_receiver_get_queue_length", referenced from:
_check_for_slaves_data in advanced_genetic_algorithm_supervisor.o
"_wb_receiver_next_packet", referenced from:
_check_for_slaves_data in advanced_genetic_algorithm_supervisor.o
"_wb_robot_cleanup", referenced from:
_run_optimization in advanced_genetic_algorithm_supervisor.o
"_wb_robot_get_basic_time_step", referenced from:
_main in advanced_genetic_algorithm_supervisor.o
"_wb_robot_get_device", referenced from:
_main in advanced_genetic_algorithm_supervisor.o
"_wb_robot_init", referenced from:
_main in advanced_genetic_algorithm_supervisor.o
"_wb_robot_step", referenced from:
_run_seconds in advanced_genetic_algorithm_supervisor.o
_evaluate_genotype in advanced_genetic_algorithm_supervisor.o
"_wb_supervisor_field_get_sf_rotation", referenced from:
_main in advanced_genetic_algorithm_supervisor.o
"_wb_supervisor_field_get_sf_vec3f", referenced from:
_main in advanced_genetic_algorithm_supervisor.o
"_wb_supervisor_field_set_sf_rotation", referenced from:
_evaluate_genotype in advanced_genetic_algorithm_supervisor.o
"_wb_supervisor_field_set_sf_vec3f", referenced from:
_evaluate_genotype in advanced_genetic_algorithm_supervisor.o
"_wb_supervisor_node_get_field", referenced from:
_main in advanced_genetic_algorithm_supervisor.o
"_wb_supervisor_node_get_from_def", referenced from:
_main in advanced_genetic_algorithm_supervisor.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 believe that it means that the compiler cannot find functions ('symbols'), although it managed to pass through compilation process parsing all includes specified in the program using -I path
It means the linker can't find those functions/symbols, because you didn't tell it to link with the Webots library.
You need to add -lsomething, assuming the library file name is /Applications/Webots/lib/libsomething.dylib (or libsomething.a).
I'm trying to learn some libuv and it seems there's a great book that goes through it. However, the book doesn't explain how to actually compile it. I ran make on the code that I pulled from github, and compiled with GYP as described on the github (https://github.com/joyent/libuv). However I'm not sure what kind of libraries I need to include to get the code to compile. I tried to compile this code:
/* first.c */
#include <stdio.h>
#include <uv.h>
int main() {
uv_loop_t *loop = uv_loop_new();
printf("Now quitting.\n");
uv_run(loop, UV_RUN_DEFAULT);
return 0;
}
I compiled it with the following command from the libuv folder:
gcc -o first first.c build/Release/libuv.a
and I got the following missing symbols:
Undefined symbols for architecture x86_64:
"_CFArrayCreate", referenced from:
_uv__fsevents_init in libuv.a(fsevents.o)
"_CFRunLoopAddSource", referenced from:
_uv__cf_loop_runner in libuv.a(darwin.o)
"_CFRunLoopGetCurrent", referenced from:
_uv__cf_loop_runner in libuv.a(darwin.o)
"_CFRunLoopRemoveSource", referenced from:
_uv__cf_loop_runner in libuv.a(darwin.o)
"_CFRunLoopRun", referenced from:
_uv__cf_loop_runner in libuv.a(darwin.o)
"_CFRunLoopSourceCreate", referenced from:
_uv__platform_loop_init in libuv.a(darwin.o)
"_CFRunLoopSourceSignal", referenced from:
_uv__cf_loop_signal in libuv.a(darwin.o)
"_CFRunLoopStop", referenced from:
_uv__platform_loop_delete in libuv.a(darwin.o)
"_CFRunLoopWakeUp", referenced from:
_uv__cf_loop_signal in libuv.a(darwin.o)
"_CFStringCreateWithCString", referenced from:
_uv__fsevents_init in libuv.a(fsevents.o)
"_CFStringGetSystemEncoding", referenced from:
_uv__fsevents_init in libuv.a(fsevents.o)
"_FSEventStreamCreate", referenced from:
_uv__fsevents_init in libuv.a(fsevents.o)
"_FSEventStreamInvalidate", referenced from:
_uv__fsevents_close in libuv.a(fsevents.o)
"_FSEventStreamRelease", referenced from:
_uv__fsevents_close in libuv.a(fsevents.o)
"_FSEventStreamScheduleWithRunLoop", referenced from:
_uv__fsevents_schedule in libuv.a(fsevents.o)
"_FSEventStreamStart", referenced from:
_uv__fsevents_schedule in libuv.a(fsevents.o)
"_FSEventStreamStop", referenced from:
_uv__fsevents_close in libuv.a(fsevents.o)
"_kCFRunLoopDefaultMode", referenced from:
_uv__cf_loop_runner in libuv.a(darwin.o)
_uv__fsevents_schedule in libuv.a(fsevents.o)
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
Can someone give me a quick tutorial for how to build libuv, or if there's anything else I need?
With libuv installed through homebrew do:
$ gcc -luv main.c
OK, figured it out. I have to use the OSX "CoreFoundation" and "CoreServices" frameworks. The following command compiles successfully:
gcc -o first first.c build/Release/libuv.a -framework CoreFoundation -framework CoreServices
Thanks for the solution – I was struggling with the same problem.
I developed your answer so that I could compile and link from any folder by using the following options:
gcc -o first -L/my/folders/libuv/ -I/my/folders/libuv/include/ first.c -luv -framework CoreFoundation -framework CoreServices
Also, I added the library into Eclipse using the following steps:
To add the path to the header file uv.h:
Right click on project and select Properties->C/C++ General->Paths and Symbols->Includes. Click on Add.. and in the text box enter:
/my/folders/libuv/include/
Click Apply->Okay.
To add the library:
While in same screen, as above, click Libraries. Click on Add.. and in the text box enter:
uv
To add the path to the library:
Still on the same screen click on Library Paths. Click Add.. and enter in the text box:
/my/folders/libuv/
To add the frameworks:
Right click on project Properties->C/C++Build->Setting->Tool Settings->Miscellaneous->Mac OS X C++ Linker. Then in the text box with the title Linker Flags add:
-framework CoreFoundation –framework CoreServices
Click on Apply then build.
You can use GYP to generate an xcodeproj for libuv (as explained in libuv's README) and add this xcodeproj to your main Xcode project.
It can be automated (for easy updating) with a simple shell script (assumes you put the libuv submodule in Externals/libuv, but can be changed):
git submodule update --init
git clone https://chromium.googlesource.com/external/gyp.git Externals/libuv/build/gyp
Externals/libuv/gyp_uv.py -f xcode
Then you'll be able to add libuv as a dependency and to the libraries to link your target to:
The last thing to do is to tell Xcode where are libuv's headers:
See this post
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`