C: Undefined reference to 'xxx' function [duplicate] - c

This question already has answers here:
Why does the order in which libraries are linked sometimes cause errors in GCC?
(9 answers)
'Undefined reference to function' issue even after linking the library which has the defination
(1 answer)
Closed 4 years ago.
I am facing undefined reference issue while creating executable.
Error:
../build/kl/Release/test/maker/guibase.o: In function `decodeAddrList':
tree234.c:(.text+0xc): undefined reference to `ptritclStubsPtr'
tree234.c:(.text+0x20): undefined reference to `ptritclStubsPtr'
tree234.c:(.text+0x12c): undefined reference to `ptritclStubsPtr'
tree234.c:(.text+0x140): undefined reference to `ptritclStubsPtr'
Build Command:-
pkgs/gcc/v4.8.3/bin/gcc -L/usr/X11R6/lib -O2 -DUSE_FLEX -Wall -Wno-char-subscripts -fPIC -DLINUX -DG_DISABLE_CONST_RETURNS -fno-strict-aliasing -o ../build/kl/Release/test/bin/pure.exe -L../build/kl/Release/test/modules ../build/kl/Release/test/maker/constrfunc.TCL.o ../../build/kl/Release/test/maker/pvdbprocs.TCL.o .. ../build/kl/Release/test/maker/maker/memmaker.TCL.o .. ../build/kl/Release/test/maker/modules/libdenbase.a .. ../build/kl/Release/test/maker/guibase.o -lcdnviptcl8.4 -ldenbase -lglib-2.0 -ldenbase -lX11 -ldl -lm -lviputil -lvippli -lcdsCommonMT_sh -lpthread -L/home/dlb/extlibs/arm/lib
I have that symbol defined in the library 'libcdnviptcl8.4' at path '/home/dlb/extlibs/arm/lib' . But still facing the same issue.
Symbol :-
readelf -s libcdnviptcl8.4.so | grep ptritclStubsPtr
636: 00000000000d8068 8 OBJECT GLOBAL DEFAULT 24 itclStubsPtr
1240: 00000000000d8068 8 OBJECT GLOBAL DEFAULT 24 ptritclStubsPtr
Am I missing some thing here? Please help
Quote from comment by OP:
"Due to some privacy issues...I am renaming the symbols.. It was edited by me... It was typo...I just corrected it...:)"
I.e. the identifiers in the error message and the grep line and the output of the grep line have been manually altered.

Related

Undefined reference to pow when compiled using gcc [duplicate]

This question already has answers here:
Undefined reference to `sin` [duplicate]
(4 answers)
Closed 1 year ago.
I am using pow function in C and included the math.h library too
The following is the error that I am getting :
/usr/bin/ld: /tmp/ccUkOL31.o: in function `main': a1B.c:(.text+0xf3):
undefined reference to 'pow' collect2: error: ld returned 1 exit
status
Although I read on StackOverflow that linking is required. But that's weird. Is there any way to avoid that extra step when we are compiling with gcc. g++ seems to be doing it automatically.
Is there any way to avoid that extra step when we are compiling with gcc?
The way I do it is having a script that invokes gcc (I have ~/bin in my SPATH)
$ cat ~/bin/mycc
#!/bin/sh
gcc -std=c11 -pedantic -Wall $* -lm
$ mycc example1.c example2.c

using correct -l -L and -I flags with cc still leads to undefined reference [duplicate]

This question already has answers here:
Ordering of object files and libraries in static linking
(1 answer)
Why does the order in which libraries are linked sometimes cause errors in GCC?
(9 answers)
Closed 2 years ago.
I'm working with a Makefile that issues the following command:
cc -g -O -I/opt/local/include -lsndfile -lm -lpvoc -L/opt/local/lib/ -L/usr/lib/x86_64-linux-gnu/ -c -o fileio.o fileio.c
followed by eventually:
cc -o plainpv -g -O -I/opt/local/include -lsndfile -lm -lpvoc -L/opt/local/lib/ -L/usr/lib/x86_64-linux-gnu/ plainpv.o -L../PVC_LIB -lsndfile -lm -lpvoc -L/opt/local/lib/ -L/usr/lib/x86_64-linux-gnu/
but that results in the following error:
../PVC_LIB/libpvoc.a(fileio.o): In function `getInputFileDataToSetOutputChannels':
/home/meeshkan-abel/Downloads/PVCplus.Beta.Public.Distribution.5-25-2017/PVC_LIB/fileio.c:63: undefined reference to `sf_open'
/home/meeshkan-abel/Downloads/PVCplus.Beta.Public.Distribution.5-25-2017/PVC_LIB/fileio.c:168: undefined reference to `sf_seek'
even though both of these functions are in libsndfile. I'm wondering why, even though libsndfile is linked when building fileio and when building plainpv, there are still undefined reference errors. Usually I see these when forgetting to link to a library, but it seems like the linking is correct here. Any thoughts on where to investigate? Thanks!

How to fix "undefined reference to 'something'" although all required files are already included? [duplicate]

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!

Unable to link to libgfortran.a [duplicate]

This question already has answers here:
Why does the order in which libraries are linked sometimes cause errors in GCC?
(9 answers)
Closed 8 years ago.
I have gfortran installed on my system and the file libgfortran.a can be found at /usr/lib/gcc/x86_64-linux-gnu/4.6/. Using nm I made sure that the function _gfortran_compare_string is defined in there:
$ nm /usr/lib/gcc/x86_64-linux-gnu/4.6/libgfortran.a | grep _gfortran_compare_string
Returns
0000000000000000 T _gfortran_compare_string
0000000000000000 T _gfortran_compare_string_char4
But, the linker of my CUDA-C program throws errors:
/usr/local/cuda-6.0/bin/nvcc --cudart static -L/usr/lib/gcc/x86_64-linux-gnu/4.6 -L/home/chung/lapack-3.5.0 -link -o "pQP" ./src/pQP.o -lgfortran -llapacke -llapack -lcublas -lblas -lcurand
nvcc warning : The 'compute_10' and 'sm_10' architectures are deprecated, and may be removed in a future release.
/home/chung/lapack-3.5.0/liblapack.a(ilaenv.o): In function `ilaenv_':
ilaenv.f:(.text+0x81): undefined reference to `_gfortran_compare_string'
and later on another error, again related to libgfortran:
/home/chung/lapack-3.5.0/liblapack.a(xerbla.o): In function `xerbla_':
xerbla.f:(.text+0x49): undefined reference to `_gfortran_st_write'
xerbla.f:(.text+0x54): undefined reference to `_gfortran_string_len_trim'
xerbla.f:(.text+0x66): undefined reference to `_gfortran_transfer_character_write'
xerbla.f:(.text+0x76): undefined reference to `_gfortran_transfer_integer_write'
xerbla.f:(.text+0x7e): undefined reference to `_gfortran_st_write_done'
xerbla.f:(.text+0x87): undefined reference to `_gfortran_stop_string'
But, again using nm, I found that _gfortran_st_write, etc are defined in libgfortran.a.
Links: Complete log and source code.
Note: Lapack makes use of libgfortran. I recently installed lapack and ran all the tests and they all passed.
You need to change the order in which you specify static libraries to the linker. If you do something like this:
nvcc --cudart static -L/usr/lib/gcc/x86_64-linux-gnu/4.6 \
-L/home/chung/lapack-3.5.0 -link -o "pQP" ./src/pQP.o \
-llapacke -llapack -lcublas -lblas -lcurand -lgfortran
You should find it will work.
The underlying reason (and this is a trait of the gcc/gnu toolchain and not anything to do with nvcc) is that linking dependency lists for static libraries are parsed from left to right by the gnu linker. If you specify a static library before any library which depends on it, it will be skipped because it has no dependencies in the link list at the point in processing when it is first encountered.

undefined reference to `sqrt' [duplicate]

This question already has answers here:
Undefined reference to sqrt (or other mathematical functions)
(5 answers)
Closed 3 years ago.
Part of my program is to calculate sqrt of float number.
When I write sqrt(1.0f); I success to compile the program,but when I write sqrt(-1.0f);
the compilation fails with undefined reference to 'sqrt' - I suppose that in this case the nan value will be returned...
I compile the program uing gcc.
When I compile it with visual studio it is compiled successfuly with negative argument to sqrt.
How the problem could be solved
Thank you
You have to add the -lm flag on most Unix-based systems, as in:
Compile using:
gcc -c file.c
and then link using:
gcc -o program file.o -lm
Or if you don't want to separate the two compilation steps, simply write:
gcc -o program file.c -lm
Link with -lm to link with the math library

Resources