I have created an assembly code from a C project, but when i run it I get this compilation error:
Compilation Error
/usr/bin/x86_64-linux-gnu-ld: warning: cannot find entry symbol _start;
defaulting to 00000000004000b0
/tmp/tmpM7HOI5/squares.o: In function `main':
main.c:(.text+0x2e): undefined reference to `malloc'
main.c:(.text+0x43): undefined reference to `perror'
main.c:(.text+0x4d): undefined reference to `exit'
main.c:(.text+0x54): undefined reference to `stdin'
main.c:(.text+0x68): undefined reference to `fgets'
main.c:(.text+0xb5): undefined reference to `atoi'
main.c:(.text+0x12d): undefined reference to `free'
main.c:(.text+0x14d): undefined reference to `malloc'
main.c:(.text+0x158): undefined reference to `stdin'
main.c:(.text+0x16c): undefined reference to `fgets'
main.c:(.text+0x17f): undefined reference to `strtok'
main.c:(.text+0x18f): undefined reference to `atoi'
main.c:(.text+0x1b5): undefined reference to `strtok'
main.c:(.text+0x1c5): undefined reference to `atoi'
main.c:(.text+0x1ef): undefined reference to `strtok'
main.c:(.text+0x1ff): undefined reference to `atoi'
main.c:(.text+0x229): undefined reference to `strtok'
main.c:(.text+0x239): undefined reference to `atoi'
main.c:(.text+0x25e): undefined reference to `free'
main.c:(.text+0x2f6): undefined reference to `printf'
It seems that all library calls become undefined.
To compile I used:
gcc -std=c99 -Wall -O2 -lm -S main.c
Your GCC command only generates assembly code, but your error list is for a linker invocation.
I suspect the -lm option is causing the compiler driver to invoke the linker - it is not necessary to specify a library if you are generating only assembly for a single translation unit.
The linker is complaining about the lack of the C standard library and crt0.0 C runtime-start-up.
Remove the unnecessary -lm option - you are not intending to link, so teh library is irrelevant.
Your -lm links to the math library. Similarly, you need -lc to link to the C library.
Related
gcc -I/opt/cplex-studio-125/cplex/include -lcplex -L/opt/cplex-studio-125/cplex/lib/x86-64_sles10_4.1/static_pic mipex1.c
I'm trying to compile an example from cplex. -I option is fine. The -L option seems to be corrupt, since it can't find the function names.
Where is the error? In the specifiec link there is a libcplex.a.
/tmp/ccf5sKky.o: In function `main':
mipex1.c:(.text+0x9f): undefined reference to `CPXopenCPLEX'
mipex1.c:(.text+0xee): undefined reference to `CPXgeterrorstring'
mipex1.c:(.text+0x125): undefined reference to `CPXsetintparam'
mipex1.c:(.text+0x222): undefined reference to `CPXcreateprob'
mipex1.c:(.text+0x2e1): undefined reference to `CPXcopylp'
mipex1.c:(.text+0x334): undefined reference to `CPXcopyctype'
mipex1.c:(.text+0x380): undefined reference to `CPXmipopt'
mipex1.c:(.text+0x3cc): undefined reference to `CPXgetstat'
mipex1.c:(.text+0x403): undefined reference to `CPXgetobjval'
mipex1.c:(.text+0x474): undefined reference to `CPXgetnumrows'
mipex1.c:(.text+0x490): undefined reference to `CPXgetnumcols'
mipex1.c:(.text+0x4be): undefined reference to `CPXgetx'
mipex1.c:(.text+0x51c): undefined reference to `CPXgetslack'
mipex1.c:(.text+0x5f9): undefined reference to `CPXwriteprob'
mipex1.c:(.text+0x64d): undefined reference to `CPXfreeprob'
mipex1.c:(.text+0x697): undefined reference to `CPXcloseCPLEX'
mipex1.c:(.text+0x6e3): undefined reference to `CPXgeterrorstring'
collect2: error: ld returned 1 exit status
The order of appearance of the library matters. Change your compilation statement to
gcc -I/opt/cplex-studio-125/cplex/include mipex1.c L/opt/cplex-studio-125/cplex/lib/x86-64_sles10_4.1/static_pic -lcplex
(Generic version)
gcc -I/<path> -L<path> <source.c> -l<lib>
to put the library after the source file, so that, linker will search the library for the function called from the source file.
I want to compile the client for redis in C. I've downloaded and installed the libevent library and the hiredis files. I've used this command:
gcc -I/home/tasos/Dropbox/lists/hiredis example-libevent.c -levent
but I get these errors:
/tmp/ccxoerYJ.o: In function `redisLibeventReadEvent':
example-libevent.c:(.text+0x28): undefined reference to `redisAsyncHandleRead'
/tmp/ccxoerYJ.o: In function `redisLibeventWriteEvent':
example-libevent.c:(.text+0x56): undefined reference to `redisAsyncHandleWrite'
/tmp/ccxoerYJ.o: In function `getCallback':
example-libevent.c:(.text+0x2d2): undefined reference to `redisAsyncDisconnect'
/tmp/ccxoerYJ.o: In function `main':
example-libevent.c:(.text+0x393): undefined reference to `redisAsyncConnect'
example-libevent.c:(.text+0x3f3): undefined reference to `redisAsyncSetConnectCallback'
example-libevent.c:(.text+0x404): undefined reference to `redisAsyncSetDisconnectCallback'
example-libevent.c:(.text+0x45d): undefined reference to `redisAsyncCommand'
example-libevent.c:(.text+0x47d): undefined reference to `redisAsyncCommand'
collect2: ld returned 1 exit status
why isn't this working?
Use -levent and -lhiredis compile option in command.
I'm new to linear programming and C. I am trying to use the lp_solve library to solve a linear equation. The problem is I can't get the demo code to work.
As described in the documentation, I downloaded lp_solve_5.5_dev.gz to my Linux machine. I extracted the files into the same folder as my code and tried to compile:
~/Desktop/Code/CA$ cc -o demo demo.c
/tmp/ccpeN8ZV.o: In function `demo':
demo.c:(.text+0x31): undefined reference to `make_lp'
demo.c:(.text+0x62): undefined reference to `set_col_name'
demo.c:(.text+0x7d): undefined reference to `set_col_name'
demo.c:(.text+0xcf): undefined reference to `set_add_rowmode'
demo.c:(.text+0x150): undefined reference to `add_constraintex'
demo.c:(.text+0x1e6): undefined reference to `add_constraintex'
demo.c:(.text+0x274): undefined reference to `add_constraintex'
demo.c:(.text+0x29c): undefined reference to `set_add_rowmode'
demo.c:(.text+0x30b): undefined reference to `set_obj_fnex'
demo.c:(.text+0x327): undefined reference to `set_maxim'
demo.c:(.text+0x33b): undefined reference to `write_LP'
demo.c:(.text+0x34e): undefined reference to `set_verbose'
demo.c:(.text+0x359): undefined reference to `solve'
demo.c:(.text+0x383): undefined reference to `get_objective'
demo.c:(.text+0x3a6): undefined reference to `get_variables'
demo.c:(.text+0x3d2): undefined reference to `get_col_name'
demo.c:(.text+0x429): undefined reference to `delete_lp'
collect2: ld returned 1 exit status
When I add liblpsolve55.a to the command I get the following errors:
~/Desktop/Code/CA$ cc -o demo demo.c liblpsolve55.a
liblpsolve55.a(lp_lib.o): In function `scaled_floor':
lp_lib.c:(.text+0x6923): undefined reference to `floor'
liblpsolve55.a(lp_lib.o): In function `scaled_ceil':
lp_lib.c:(.text+0x6f03): undefined reference to `ceil'
liblpsolve55.a(lp_lib.o): In function `set_XLI':
lp_lib.c:(.text+0x7aa2): undefined reference to `dlclose'
lp_lib.c:(.text+0x7bb3): undefined reference to `dlopen'
lp_lib.c:(.text+0x7bd1): undefined reference to `dlsym'
lp_lib.c:(.text+0x7d8a): undefined reference to `dlsym'
lp_lib.c:(.text+0x7da6): undefined reference to `dlsym'
lp_lib.c:(.text+0x7dc2): undefined reference to `dlsym'
liblpsolve55.a(lp_lib.o): In function `set_BFP':
lp_lib.c:(.text+0x7eb4): undefined reference to `dlclose'
lp_lib.c:(.text+0x7fc3): undefined reference to `dlopen'
lp_lib.c:(.text+0x7fe1): undefined reference to `dlsym'
lp_lib.c:(.text+0x831a): undefined reference to `dlsym'
lp_lib.c:(.text+0x8336): undefined reference to `dlsym'
lp_lib.c:(.text+0x8352): undefined reference to `dlsym'
lp_lib.c:(.text+0x836e): undefined reference to `dlsym'
liblpsolve55.a(lp_lib.o):lp_lib.c:(.text+0x838a): more undefined references to `dlsym' follow
................
I understand that the lp_solve libraries are not loaded in my code. Can you please tell me how I can properly link the lp_solve libraries?
You're just missing some compiler flags to include the proper libraries. As danielko said, a quick google search on the missing libraries brings up some suggestions. E.g.
Linux c++ error: undefined reference to 'dlopen'
http://sourceforge.net/p/dev-cpp/discussion/48211/thread/3bd8b8a1
These suggest your compilation should be something more like:
cc -o demo demo.c -ldl -llpsolve55
and the lpsolve documentation suggests a command that includes the project directory such as:
cc -I/lp_solve_5.5 -I/lp_solve_5.5/bfp -I/lp_solve_5.5/bfp/bfp_etaPFI -I/lp_solve_5.5/colamd $src -o MyExe.exe -lm -ldl
I am trying to compile my code for GnuTLS, but on compiling it gives the following errors.
I have checked gnutls.h is present on my system in /usr/include/gnutls/.
What else can be the cause?
gcc -o tls.o tls.c
/tmp/ccfyZ1Bd.o: In function `main':
tls.c:(.text+0x1c): undefined reference to `gnutls_global_init'
tls.c:(.text+0x28): undefined reference to `gnutls_anon_allocate_client_credentials'
tls.c:(.text+0x3c): undefined reference to `gnutls_init'
tls.c:(.text+0x58): undefined reference to `gnutls_priority_set_direct'
tls.c:(.text+0x74): undefined reference to `gnutls_credentials_set'
tls.c:(.text+0x79): undefined reference to `tcp_connect'
tls.c:(.text+0x91): undefined reference to `gnutls_transport_set_ptr'
tls.c:(.text+0x9d): undefined reference to `gnutls_handshake'
tls.c:(.text+0xdc): undefined reference to `gnutls_perror'
tls.c:(.text+0x109): undefined reference to `gnutls_record_send'
tls.c:(.text+0x125): undefined reference to `gnutls_record_recv'
tls.c:(.text+0x154): undefined reference to `gnutls_strerror'
tls.c:(.text+0x1e6): undefined reference to `gnutls_bye'
tls.c:(.text+0x1f2): undefined reference to `tcp_close'
tls.c:(.text+0x1fe): undefined reference to `gnutls_deinit'
tls.c:(.text+0x20a): undefined reference to `gnutls_anon_free_client_credentials'
tls.c:(.text+0x20f): undefined reference to `gnutls_global_deinit'
collect2: ld returned 1 exit status
This is a linking error. You need to include some library with the -l flag. Taking a wild guess without knowing your setup, I would try -lgnutls
I'm having some problems statically linking ncurses to one of my programs
Here's a really simple sample program:
#include<ncurses.h>
int main(){
initscr();
printw("Hello world\n");
refresh();
getch();
endwin();
return 0;
}
When I compile it with
gcc -static -lncurses hello_curses.c -o curses
I get these errors:
/tmp/ccwHJ6o1.o: In function `main':
curses_hello.c:(.text+0x5): undefined reference to `initscr'
curses_hello.c:(.text+0x14): undefined reference to `printw'
curses_hello.c:(.text+0x1b): undefined reference to `stdscr'
curses_hello.c:(.text+0x20): undefined reference to `wrefresh'
curses_hello.c:(.text+0x27): undefined reference to `stdscr'
curses_hello.c:(.text+0x2c): undefined reference to `wgetch'
curses_hello.c:(.text+0x31): undefined reference to `endwin'
collect2: ld returned 1 exit status
I'm a little confused why this isn't working. What am I missing here?
You need to pass -l options at the end of the command line:
gcc -static hello_curses.c -o curses -lncurses
When the compiler encounters -lfoo, it links in all the symbols from foo that have been requested by a previous file. If you put -lfoo at the beginning, no symbol has been requested yet, so no symbol gets linked.
Edit:
I think the real problem is that you need to specify your -l option at the end of the command. I just tried it the way you had it and reproduced your error. If I put -l:libncurses.a at the end of the line then it works. All without the -static option BTW.
I think what is happening is that you have a dynamic library for ncurses but you have used the -static option which means to not use any dynamic libraries. I suspect you do not actually have a static version of the ncurses library i.e. one ending with a .a suffix.
If you want to link with the static version (.a) of ncurses rather than the dynamic version (.so) then temporarily remove the symlink for libncurses.so so that the linker picks up the .a file instead. Alternatively copy the .a file somewhere else and add that to an earlier search path.
Alternatively if your linker supports it (eg. ld) then you could specify -l:libncurses.a instead of -lncurses.
I just spent a few hours on an ARM processor, trying to get it to work, as the accepted answer didn't work for me.
Here are my findings:
Apparently
gcc -static hello_curses.c -o curses -lncurses
works on an x64 processor, but not on an ARM processor.
When I tried with the above line, I still got all the "undefined reference errors" (and a lot more) of the OP.
You need to also link against libtinfo.a, and note that sequence matters.
This is the correct command line that works:
gcc -static hello_curses.c -o curses -lncurses -ltinfo
If you mix up the sequence, then it won't work...
gcc -static hello_curses.c -o curses -ltinfo -lncurses
undefined reference to `unctrl'
Of course this also works if you use the :lib syntax
This compiles
gcc -static hello_curses.c -o curses -l:libncursesw.a -l:libtinfo.a
This does not compile
gcc -static hello_curses.c -o curses -l:libtinfo.a -l:libncursesw.a
Oh how I like gcc...
This program should never have been allowed to graduate from kindergarden
(.text+0x2a8): undefined reference to cur_term'
/usr/lib/gcc/arm-linux-gnueabihf/4.8/../../../arm-linux-gnueabihf/libncursesw.a(lib_color.o):
In functioninit_pair': (.text+0x2ac): undefined reference to
cur_term'
/usr/lib/gcc/arm-linux-gnueabihf/4.8/../../../arm-linux-gnueabihf/libncursesw.a(lib_color.o):
In functioninit_pair': (.text+0x50a): undefined reference to tparm'
/usr/lib/gcc/arm-linux-gnueabihf/4.8/../../../arm-linux-gnueabihf/libncursesw.a(lib_color.o):
In functioninit_pair': (.text+0x518): undefined reference to
_nc_putp'
/usr/lib/gcc/arm-linux-gnueabihf/4.8/../../../arm-linux-gnueabihf/libncursesw.a(lib_color.o):
In functioninit_color': (.text+0x552): undefined reference to
cur_term'
/usr/lib/gcc/arm-linux-gnueabihf/4.8/../../../arm-linux-gnueabihf/libncursesw.a(lib_color.o):
In functioninit_color': (.text+0x556): undefined reference to
cur_term'
/usr/lib/gcc/arm-linux-gnueabihf/4.8/../../../arm-linux-gnueabihf/libncursesw.a(lib_color.o):
In functioninit_color': (.text+0x5e4): undefined reference to
tparm'
/usr/lib/gcc/arm-linux-gnueabihf/4.8/../../../arm-linux-gnueabihf/libncursesw.a(lib_color.o):
In functioninit_color': (.text+0x5f2): undefined reference to
_nc_putp'
/usr/lib/gcc/arm-linux-gnueabihf/4.8/../../../arm-linux-gnueabihf/libncursesw.a(lib_color.o):
In functioncan_change_color': (.text+0x740): undefined reference to
cur_term'
/usr/lib/gcc/arm-linux-gnueabihf/4.8/../../../arm-linux-gnueabihf/libncursesw.a(lib_color.o):
In functioncan_change_color': (.text+0x744): undefined reference to
cur_term'
/usr/lib/gcc/arm-linux-gnueabihf/4.8/../../../arm-linux-gnueabihf/libncursesw.a(lib_color.o):
In functionhas_colors': (.text+0x768): undefined reference to
cur_term'
/usr/lib/gcc/arm-linux-gnueabihf/4.8/../../../arm-linux-gnueabihf/libncursesw.a(lib_color.o):
In functionhas_colors': (.text+0x76c): undefined reference to
cur_term'
/usr/lib/gcc/arm-linux-gnueabihf/4.8/../../../arm-linux-gnueabihf/libncursesw.a(lib_color.o):
In functioncolor_content': (.text+0x7c2): undefined reference to
cur_term'
/usr/lib/gcc/arm-linux-gnueabihf/4.8/../../../arm-linux-gnueabihf/libncursesw.a(lib_color.o):(.text+0x7c6):
more undefined references tocur_term' follow
/usr/lib/gcc/arm-linux-gnueabihf/4.8/../../../arm-linux-gnueabihf/libncursesw.a(lib_color.o):
In function _nc_do_color': (.text+0x8de): undefined reference to
tparm'
/usr/lib/gcc/arm-linux-gnueabihf/4.8/../../../arm-linux-gnueabihf/libncursesw.a(lib_color.o):
In function _nc_do_color': (.text+0x8e6): undefined reference to
tputs'
/usr/lib/gcc/arm-linux-gnueabihf/4.8/../../../arm-linux-gnueabihf/libncursesw.a(lib_color.o):
In function _nc_do_color': (.text+0x958): undefined reference to
tputs'
/usr/lib/gcc/arm-linux-gnueabihf/4.8/../../../arm-linux-gnueabihf/libncursesw.a(lib_color.o):
In function set_foreground_color': (.text+0x62): undefined reference
totputs'
/usr/lib/gcc/arm-linux-gnueabihf/4.8/../../../arm-linux-gnueabihf/libncursesw.a(lib_color.o):
In function set_background_color': (.text+0xa2): undefined reference
totputs'
/usr/lib/gcc/arm-linux-gnueabihf/4.8/../../../arm-linux-gnueabihf/libncursesw.a(lib_hline.o):
In function whline': (.text+0xec): undefined reference toacs_map'
/usr/lib/gcc/arm-linux-gnueabihf/4.8/../../../arm-linux-gnueabihf/libncursesw.a(lib_hline.o):
In function whline': (.text+0xf0): undefined reference toacs_map'
/usr/lib/gcc/arm-linux-gnueabihf/4.8/../../../arm-linux-gnueabihf/libncursesw.a(lib_add_wch.o):
In function wadd_wch': (.text+0x4fe): undefined reference to
TABSIZE'
/usr/lib/gcc/arm-linux-gnueabihf/4.8/../../../arm-linux-gnueabihf/libncursesw.a(lib_add_wch.o):
In function wadd_wch': (.text+0x502): undefined reference to
TABSIZE'
/usr/lib/gcc/arm-linux-gnueabihf/4.8/../../../arm-linux-gnueabihf/libncursesw.a(lib_add_wch.o):
In function wecho_wchar': (.text+0x6d8): undefined reference to
TABSIZE'
/usr/lib/gcc/arm-linux-gnueabihf/4.8/../../../arm-linux-gnueabihf/libncursesw.a(lib_add_wch.o):
In function wecho_wchar': (.text+0x6dc): undefined reference to
TABSIZE'
/usr/lib/gcc/arm-linux-gnueabihf/4.8/../../../arm-linux-gnueabihf/libncursesw.a(lib_wunctrl.o):
In function wunctrl': (.text+0x30): undefined reference tounctrl'
collect2: error: ld returned 1 exit status