compile C in CentOS face error: undefined reference to [duplicate] - c++

This question already has an answer here:
Why am I getting a gcc "undefined reference" error trying to create shared objects?
(1 answer)
Closed 7 years ago.
I compiled C in CentOS and face this error:
cc -c -o obj/BT.o BT.c -I./include -I/usr/dialogic/inc
cc -o BT obj/BT.o obj/util.o -I./include -I/usr/dialogic/inc -L/usr /dialogic/lib
obj/BT.o: In function 'main':
BT.c:(.text+0x52): undefined reference to `gc_Start'
collect2: ld returned 1 exit status
make: *** [BT] Error 1
I already linked to library -L/usr /dialogic/lib but i don't know why it does not link when create binary file
Please, any one can suggest me something ?

check if you had saved your.c file and also check of spelling of the functions' definition and their calls .

Related

Cuda compile error when "cuMemGetAddressRange" exists [duplicate]

This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 1 year ago.
Here comes the sample codes:
#include <cuda.h>
#include <cuda_runtime.h>
#include <stdio.h>
int main() {
unsigned char* cu_test;
cudaMalloc((void**)&cu_test, 3200);
CUdeviceptr pbase;
size_t psize;
CUresult res = cuMemGetAddressRange(&pbase, &psize, (CUdeviceptr)cu_test);
printf("cu_img_yuv size: %ld", psize);
return 0;
}
While it throws error when compiling whatever the cuda version is(tested from 11.3 to 11.5):
$ nvcc main.cu -o main
/tmp/tmpxft_0000e288_00000000-11_main.o: In function `main':
tmpxft_0000e288_00000000-6_main.cudafe1.cpp:(.text+0x54): undefined reference to `cuMemGetAddressRange_v2'
collect2: error: ld returned 1 exit status
Can someone help pointing out what the problem is plz?
The message:
error: ld returned 1 exit status
denotes that it is a linking error ( see ld ).
To see this is the case, you can run
nvcc -c main.cu -o main.o
and you will not get any error. This is the source-code compilation step!
Solution:
You need to explicitly specify linkage with the CUDA driver stub library:
nvcc main.cu -o main -lcuda
That is because cuMemGetAddressRange() is part of the CUDA Driver API, not the CUDA runtime API.
NOTE: you did not cudaFree() the allocated memory, you might want to fix this!
Edit: (credit to #talonmies comment) You do not have to explicitly link against the CUDA runtime library (-lcudart), because nvcc will automatically link against it.

g++ undefined reference with a shared library [duplicate]

This question already has answers here:
Why does the order in which libraries are linked sometimes cause errors in GCC?
(9 answers)
Closed 6 years ago.
I'm trying to compile a file with a shared library using the following command:
g++ -L. -lsubmit main.cpp
It outputs:
/tmp/ccRFpx1v.o: In function `main':
main.cpp:(.text+0x5): undefined reference to `Submit_test()'
collect2: error: ld returned 1 exit status
I have main.cpp and libsubmit.so in working directory. Here's my main.cpp
void Submit_test();
int main()
{
Submit_test();
}
Here's nm -D --demangle libsubmit.so:
...
0000000000000e0e T Submit_test()
...
How should I compile that code?
This is probably a dup of how-to-know-if-one-shared-library-depends-on-another-shared-library-or-not
TLDR is that you should put linked libs after object/source files.

C++ compile error. G++ gnu [duplicate]

This question already has answers here:
Can I get Unix's pthread.h to compile in Windows?
(5 answers)
Closed 6 years ago.
Hi I am having some issues with my c++ program. I am using g++ gnu and it is on windows 10. here is the error that is showing up:
ld.exe: cannot find -lpthread
collect2.exe: error: ld returned 1 exit status
please help because i can not work out what is going on.
Thanks,
Asher
That is a linker error. Not a compiler error.
It is complaining that it cannot find the pthread library in the library search path. Either it simply isn't there or you need to indicate where it is with the -L option. Or, in case pthread is not needed, remove the -lpthread option so you don't attempt to link to it.

Trying to run OpenGL on Linux, have the necessary libraries but won't run? (C++) [duplicate]

This question already has answers here:
Linker error : undefined reference to symbol 'glOrtho'
(2 answers)
Closed 8 years ago.
I am new to Linux and am currently using Linux Mint. I followed the instructions on this page, however whenever I go to compile the example code (given on the web page), the build fails.
g++ ~/Desktop/test.cpp -lglut gives me the following:
/usr/bin/ld: /tmp/cc3aKYsD.o: undefined reference to symbol 'glOrtho'
/usr/lib/x86_64-linux-gnu/mesa/libGL.so.1: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
Why does this keep occurring? I apologize for such a beginner question, but this is irritating.
You need to link with the OpenGL library as well:
g++ ~/Desktop/test.cpp -lglut -lGL

with -lpthread, g++ compiler error, "undefined reference to " semaphore calls such as `sem_open'

I am new to posix thread library, and I tried to compile a sample code from a tutorial with:
g++ -lpthread agreement.cpp -o agreement
however I was not able to compile the code and got the following error message:
a3q2.cpp:(.text+0x7e): undefined reference to `sem_open'
a3q2.cpp:(.text+0xab): undefined reference to `sem_wait'
a3q2.cpp:(.text+0x290): undefined reference to `sem_post'
a3q2.cpp:(.text+0x2af): undefined reference to `sem_close'
a3q2.cpp:(.text+0x2bb): undefined reference to `sem_unlink'
collect2: ld returned 1 exit status
make: *** [a3q2_exe] Error 1
I am aware that -lpthread is needed for compilation to work, but is there any other options i might need to solve the problem? if not how do I have to install the "proper" pthread library?
Thanks for your help!
You want the compile option -pthread (if you are really using pthreads). If you just need those functions they are in librt so use -lrt