Gigantic error for Rust hello world - linker

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

Related

Why doesn't gcc link an SDL 2.0 C project? (macOS) [duplicate]

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?

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

Linking with GHC

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).

Compile simple hello world ZeroMQ C example, compile flags?

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.

why are my openCL builds failing on OS X?

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.

Resources