This question already has answers here:
Undefined reference to `pow' and `floor'
(6 answers)
Closed 9 years ago.
I'm trying to compile a simple example of C code that includes Lua(5.2) libraries. I'm using the following command:
gcc graph.c -o graph -I/usr/local/include -L/usr/local/lib -llua
And getting the following errors:
/usr/local/lib/liblua.a(lobject.o): In function `luaO_arith':
lobject.c:(.text+0x15c): undefined reference to `floor'
lobject.c:(.text+0x111): undefined reference to `pow'
/usr/local/lib/liblua.a(lvm.o): In function `luaV_execute':
lvm.c:(.text+0x24e9): undefined reference to `floor'
lvm.c:(.text+0x25fe): undefined reference to `pow'
...
Looks like the math library is not linked, but not sure how to fix it... Any suggestions? I installed Lua following instructions from the Readme with make linux and install linux (have Ubuntu 12.04). Thanks!
Very simple: you just need to add -lm to the end of the line.
(The man pages for all the functions that require it will mention this.)
Related
This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it in Fortran?
(5 answers)
"__gfortran_pow_c8_i4" error when linking .o files from g++ and gfortran using g++
(1 answer)
Undefined reference to pow( ) in C, despite including math.h [duplicate]
(1 answer)
Closed 1 year ago.
I am trying to use OMPTrace which is a tool for tracing and visualizing OpenMP program execution as shown here https://github.com/passlab/omptrace. I have already tested the library on a simple code written in C and it works perfectly (the library is well installed in /home/hakim/llvm-openmp/BUILD/omptrace/build/libomptrace.so). I wonder now if it works also for codes written in Fortran.
I created a makefile as following:
OMP_INSTALL=/home/hakim/llvm-openmp-install
OMP_LIB_PATH=${OMP_INSTALL}/lib
OMPTRACE_LIB=/home/hakim/llvm-openmp/BUILD/omptrace/build/libomptrace.so
default:runhecese
heceseclang: hecese_OpenMP.f90
clang -g -fopenmp hecese_OpenMP.f90 -o heceseclang
objdump -d heceseclang >heceseclang.objdump
runhecese: heceseclang
LD_PRELOAD=${OMP_LIB_PATH}/libomp.so:${OMPTRACE_LIB} ./heceseclang
clean:
rm heceselang heceseclang.objdump core
and when executing it, I get :
/usr/bin/ld: /tmp/hecese_OpenMP-67d132.o: in function `__tasks_MOD_ww0':
hecese_OpenMP.f90:(.text+0x1dc6): undefined reference to `pow'
/usr/bin/ld: hecese_OpenMP.f90:(.text+0x1df7): undefined reference to `pow'
/usr/bin/ld: hecese_OpenMP.f90:(.text+0x1e1c): undefined reference to `pow'
/usr/bin/ld: hecese_OpenMP.f90:(.text+0x1e37): undefined reference to `pow'
/usr/bin/ld: /tmp/hecese_OpenMP-67d132.o: in function `__tasks_MOD_w':
hecese_OpenMP.f90:(.text+0x1ed0): undefined reference to `pow'
/usr/bin/ld: /tmp/hecese_OpenMP-67d132.o:hecese_OpenMP.f90:(.text+0x1eeb): more undefined references to `pow' follow
/usr/bin/ld: /tmp/hecese_OpenMP-67d132.o: in function `MAIN__':
hecese_OpenMP.f90:(.text+0x36f1): undefined reference to `_gfortran_st_open'
/usr/bin/ld: hecese_OpenMP.f90:(.text+0x372c): undefined reference to `_gfortran_st_read'
/usr/bin/ld: hecese_OpenMP.f90:(.text+0x373b): undefined reference to `_gfortran_st_read_done'
/usr/bin/ld: hecese_OpenMP.f90:(.text+0x3776): undefined reference to `_gfortran_st_read'
/usr/bin/ld: hecese_OpenMP.f90:(.text+0x3794): undefined reference to `_gfortran_transfer_integer'
/usr/bin/ld: hecese_OpenMP.f90:(.text+0x37a3): undefined reference to `_gfortran_st_read_done'
I didn't show you all the errors because the following ones are the same as the ones I've already showed. It is all about the undefined references.
I wonder if it comes from the clang compiler.
Should I install the flang compiler and use it instead of the clang one?
The result I'm waiting for is a .graphml file.
Any help, please ?
This question already has answers here:
Statically link ncurses to program
(3 answers)
Closed 1 year ago.
I'm trying ncurses C library for the first time in a little test program and every time I try to output the executable file using gcc it gives me an error.
Here is the test program:
#include <ncurses.h>
int main() {
initscr();
printw("--------\n| test |\n--------\n\n");
refresh();
printw("\npress any key to exit...");
refresh();
getch();
endwin();
return 0;
}
Here are the gcc commands and their output:
$ gcc -Wall -lncurses -c tests.c
$ gcc tests.o -o tests
/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../x86_
/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: tests.o: warning: relocation against `stdscr' in read-only section `.text'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: tests.o: in function `main':
tests.c:(.text+0x5): undefined reference to `initscr'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: tests.c:(.text+0x16): undefined reference to `printw'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: tests.c:(.text+0x1d): undefined reference to `stdscr'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: tests.c:(.text+0x25): undefined reference to `wrefresh'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: tests.c:(.text+0x36): undefined reference to `printw'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: tests.c:(.text+0x3d): undefined reference to `stdscr'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: tests.c:(.text+0x45): undefined reference to `wrefresh'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: tests.c:(.text+0x4c): undefined reference to `stdscr'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: tests.c:(.text+0x54): undefined reference to `wgetch'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: tests.c:(.text+0x59): undefined reference to `endwin'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: warning: creating DT_TEXTREL in a PIE
collect2: error: ld returned 1 exit status
I tried to find a solution but didn't find any, so any help is appreciated.
Note: Does the fact that I'm using Wayland display server with no X client has something to do with the error ?
The libraries have to be added at the end of the command line as they are searched for symbols only one-time and the linking is done in the order specified.
gcc tests.o -o tests -lncurses
This question already has answers here:
Why does the order in which libraries are linked sometimes cause errors in GCC?
(9 answers)
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 3 years ago.
Github :: https://github.com/mmgaggle/sslsqueeze
I am trying to build from source a code from github called "sslsqueeze". I have installed all required libraries but "make" command is still unable to link them for some reason. I am sure there is a very simple point/step I am missing here, but after hours of debugging, I am turning to you.
sslsqueeze.c file contains the line:
**sslsqueeze** needs to be linked with -levent_core from libevent2 library.
Accordingly I have installed libevent-dev library. And I run this command:
make
This is my list of errors :
sslsqueeze.o: In function `new_connection':
sslsqueeze.c:(.text+0x57): undefined reference to `bufferevent_socket_new'
sslsqueeze.c:(.text+0x68): undefined reference to `bufferevent_set_timeouts'
sslsqueeze.c:(.text+0x88): undefined reference to `bufferevent_setcb'
sslsqueeze.c:(.text+0x9d): undefined reference to `bufferevent_socket_connect'
sslsqueeze.o: In function `read_cb':
sslsqueeze.c:(.text+0x161): undefined reference to `bufferevent_read'
sslsqueeze.c:(.text+0x20d): undefined reference to `bufferevent_free'
sslsqueeze.c:(.text+0x25d): undefined reference to `bufferevent_write'
sslsqueeze.c:(.text+0x288): undefined reference to `bufferevent_write'
sslsqueeze.c:(.text+0x2b3): undefined reference to `bufferevent_write'
sslsqueeze.o: In function `event_cb':
sslsqueeze.c:(.text+0x2ed): undefined reference to `bufferevent_free'
sslsqueeze.o: In function `write_cb':
sslsqueeze.c:(.text+0x136): undefined reference to `bufferevent_enable'
sslsqueeze.o: In function `event_cb':
sslsqueeze.c:(.text+0x32c): undefined reference to `bufferevent_write'
sslsqueeze.o: In function `main':
sslsqueeze.c:(.text.startup+0x1f9): undefined reference to `event_base_new'
sslsqueeze.c:(.text.startup+0x229): undefined reference to `event_base_dispatch'
collect2: error: ld returned 1 exit status
<builtin>: recipe for target 'sslsqueeze' failed
make: *** [sslsqueeze] Error 1
After some research I tried the following commands ALL to the same result :
make -levent_core
gcc -levent_core sslsqueeze.c -o take6
gcc -L/usr/lib/x86_64-linux-gnu sslsqueeze.c -o take8
The following were also not successful. They gave "file not found" errors.
gcc -L/usr/lib/x86_64-linux-gnu -libevent_core.so sslsqueeze.c -o take7
gcc -L/usr/lib/x86_64-linux-gnu -libevent_core.a sslsqueeze.c -o take7
Final piece of information.
Header files are in /usr/include/event2
libevent_core files are in /usr/lib/x86_64-linux-gnu/(2 files, one with .so extension and the other with .a)
Any help would be appreciated!
This question already has answers here:
Cannot find libcrypto library error
(2 answers)
Closed 9 years ago.
I am trying to build a C file using OpenSSL on (64-bit) Windows 7. I have downloaded the latest full binary from the official OpenSSL site, and am using MinGW, and have added the respective bin directories to PATH. However I am getting the following error :
c:\Workspace\OSAccess\c>gcc -I%JAVA_HOME%\include -I%JAVA_HOME%\include\win32 -Ic:\OpenSSL-Win64\include -std=c99 -lm -lcrypto -o libosaccess.dll osaccess.c
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: cannot find -lcrypto
collect2.exe: error: ld returned 1 exit status
I cannot find any file called libcrypto.dll or cryptolib.dll, so I tried to build my own OpenSSL from source, using the install notes supplied, as I can see that the static libraries for crypto and ssl do not seem to be shipped with the Windows install. I have seen references in other posts to a couple of other libraries, libeay32 and ssleay32, but these return the same error.
If I remove the -lcrypto (or other) then I get Undefined reference errors:
c:\Workspace\OSAccess\c>gcc -I%java_home%\include -I%java_home%\include\win32 -Ic:\OpenSSL-Win64\include -std=c99 -lm -o libosaccess.dll osaccess.c
C:\Users\xxxx\AppData\Local\Temp\ccbi3e1T.o:osaccess.c:(.text+0x383): undefined reference to 'Netbios#4'
C:\Users\xxxx\AppData\Local\Temp\ccbi3e1T.o:osaccess.c:(.text+0x3d1): undefined reference to 'Netbios#4'
C:\Users\xxxx\AppData\Local\Temp\ccbi3e1T.o:osaccess.c:(.text+0x445): undefined reference to 'Netbios#4'
C:\Users\xxxx\AppData\Local\Temp\ccbi3e1T.o:osaccess.c:(.text+0x73d): undefined reference to 'EVP_CIPHER_CTX_init'
C:\Users\xxxx\AppData\Local\Temp\ccbi3e1T.o:osaccess.c:(.text+0x742): undefined reference to 'EVP_aes_256_cbc'
C:\Users\xxxx\AppData\Local\Temp\ccbi3e1T.o:osaccess.c:(.text+0x76a): undefined reference to 'EVP_EncryptInit_ex'
C:\Users\xxxx\AppData\Local\Temp\ccbi3e1T.o:osaccess.c:(.text+0x794): undefined reference to 'EVP_EncryptUpdate'
C:\Users\xxxx\AppData\Local\Temp\ccbi3e1T.o:osaccess.c:(.text+0x7d2): undefined reference to 'EVP_EncryptFinal_ex'
C:\Users\xxxx\AppData\Local\Temp\ccbi3e1T.o:osaccess.c:(.text+0x81c): undefined reference to 'EVP_CIPHER_CTX_cleanup'
C:\Users\xxxx\AppData\Local\Temp\ccbi3e1T.o:osaccess.c:(.text+0x865): undefined reference to 'EVP_CIPHER_CTX_init'
C:\Users\xxxx\AppData\Local\Temp\ccbi3e1T.o:osaccess.c:(.text+0x86a): undefined reference to 'EVP_aes_256_cbc'
C:\Users\xxxx\AppData\Local\Temp\ccbi3e1T.o:osaccess.c:(.text+0x892): undefined reference to 'EVP_DecryptInit_ex'
C:\Users\xxxx\AppData\Local\Temp\ccbi3e1T.o:osaccess.c:(.text+0x8bc): undefined reference to 'EVP_DecryptUpdate'
C:\Users\xxxx\AppData\Local\Temp\ccbi3e1T.o:osaccess.c:(.text+0x8fa): undefined reference to 'EVP_DecryptFinal_ex'
C:\Users\xxxx\AppData\Local\Temp\ccbi3e1T.o:osaccess.c:(.text+0x930): undefined reference to 'EVP_CIPHER_CTX_cleanup'
If libcrypto.dll or cryptolib.dll are not there , i will recommend you to try and copy it from any other system . I had similar problem with , luckily found it on another system and copying worked well too.
Regards,
Jain
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Linker order - GCC
GCC C++ Linker errors: Undefined reference to 'vtable for XXX', Undefined reference to 'ClassName::ClassName()'
I am using GCC to build an application. The main program calls a function (say, myfunc())that resides in a static library (say, libmylib.a). This function calls the cosf() and sinf() function from math library.
Now, in gcc command line, I give the -lmylib -lm options, and the build goes fine. However, when the order of the libraries is changed, then the build fails with the error:
libmylib.a(mylib.o): In function `myfunc':
mylib.c:22: undefined reference to `cosf'
mylib.c:23: undefined reference to `sinf'
Why doesn't gcc complete the build with the libraries given in some order?