undefined reference error CUDA, GPUJPEG Library - linker

I have successfully installed this library. My code compiles without issue but I'm getting this error, which I believe is during linking:
suvamsh#vai:~/gpujpeg-lib/src$ nvcc test.cu
/tmp/tmpxft_00002869_00000000-13_test.o: In function 'encoder()':
tmpxft_00002869_00000000-1_test.cudafe1.cpp:(.text+0x23d): undefined reference to `gpujpeg_set_default_parameters(gpujpeg_parameters*)'
collect2: ld returned 1 exit status
I have even set $LD_LIBRARY_PATH to location of the library .so file.
Any help would be greatly appreciated!

As indicated by #talonmies,
You will have to explicitly specify the library to the compiler and supply the path where you installed it, if it is in a "non-standard" place.
Try the following command
$ nvcc test.cu -o test -L"path/to/GPUJPEGLibrary" -l"name_of_GPUJPEGLibrary"
Note that if the name of the .so file is libxyz.so, the "name_of_GPUJPEGLibrary" should be "xyz".
For example, if your .so file is /usr/local/lib/libgpujpeg.so, the cmdline should be
$ nvcc test.cu -o test -L"/usr/local/lib" -l"gpujpeg"

Related

Linking fftw-3.3.6-pl2 while compiling my file using gcc

I'm trying to run a simple code that includes the fftw library. I know the code is right as it is provided as a test code by the authors. This is what I typed during compilation:
gcc my file.c -L/home/ankit/Desktop/fftw-3.3.6-pl2/lib/
-I/home/ankit/Desktop/fftw-3.3.6-pl2/include/ -lfftw -lm
I get the errors:
myfile.c: (.Text+0x2c):. undefined reference to 'fftw_plan_dft_2d'
collect2: ld returned 1 exit status
It wasn't a linking problem, installation was faulty and I had to use 'sudo make install' to get the permission for the installation to be successful. I could link it with 'gcc test.c -lfftw3 -lm' after. Thanks for your suggestions!

Can't link against WinPcap library wpcap.lib ("undefined reference to")

I am trying to build an example program which uses WinPcap-functions. I’m working under Windows 7 64 Bit edition with MinGW. I am able to compile the C-code to an object file, but I can’t link against wpcap.lib.
My linker call looks like this:
gcc -L ../../lib/x64 send_packet.o -lwpcap -o WinPcapTest.exe
With this call I get the following errors:
undefined reference to pcap_open
undefined reference to pcap_sendpacket
undefined reference to pcap_geterr
Obviously I am not linking against wpcap.lib, but I don’t know why. The library is definitely found. If I change the lib include path for example, I get this error:
cannot find -lwpcap
Why does the linker find the lib but does not link against it? Thanks for your help.
Try listing you libraries after binary definition. As far as I remember, with provided gcc command, ld would be symbol matching for pcap symbols between send_packet.o and libwpcap.lib but not with WinPcapTest.exe. I would suggest moving -lwpcap at the end:
gcc -I ..\..\..\Downloads\WpdPack_4_1_2\WpdPack\Include ..\send_packet.c -L ..\..\..\Downloads\WpdPack_4_1_2\WpdPack\Lib\x64 -O0 -g3 -Wall -o WinPcapTest.exe -lwpcap

/lib/libmatrix.a: file not recognized: File format not recognized collect2: ld returned 1 exit status

I'm trying to compile a makefile which includes the following line:
gcc -I. -I/home/usr/Documents/MTV/include -ggdb3 -Wall -O2 -o ascii2bin.c \
-L. -L../lib -lmatrix -lseq_io -lpic -lm
And this is what I get:
../lib/libmatrix.a: file not recognized: File format not recognized
collect2: ld returned 1 exit status
Any idea on what might happen to libmatrix.a? How can I read what's inside libmatrix.a? I tried using the 'ar -t' command, but it also says file format not recognized.
The project was compiled on Cygwin before by others, and now I'm using ubuntu gcc to try to redo it, could this be the problem?
A library file built for cygwin will not work on linux.
The library itself must be recompiled from source to match the details (ABI, dynamic system library dependencies, etc) of the system on which it is intended to be used.
Cygwin tries to be source compatible with Linux, so if you have the source rebuilding may be straightforward. But it is not binary-compatible, and libraries are basically binary building blocks with metadata to permit linking them together.

I can't compile this code of mongoose web server's sample example

Short Intro :- (GCC version 4.6.3, OS-Ubuntu 12.04 ,working around mongoose web server program so when I run "make" command to compile and install mongoose , it has done the task fine ).
[Part 1 of question]
This question is in reference to this post on stackowerflow.
mongoose web server helloworld program
Valenok has answered on this post by giving a link to hello sample program.
basically, I am trying to compile the sample hello program code given on this link :-
http://code.google.com/p/mongoose/source/browse/examples/hello.c
and put this code in already compiled directory of mongoose.(directory has mongoose.h file)
Following is command line output for my compilation of hello program.
akshay#akshay-Inspiron-N5010:~$ gcc mongoose/hello.c -o mongoose/hello
/tmp/ccroC5Z6.o: In function `callback':
hello.c:(.text+0x32): undefined reference to `mg_get_request_info'
hello.c:(.text+0x96): undefined reference to `mg_printf'
/tmp/ccroC5Z6.o: In function `main':
hello.c:(.text+0xee): undefined reference to `mg_start'
hello.c:(.text+0x103): undefined reference to `mg_stop'
collect2: ld returned 1 exit status
akshay#akshay-Inspiron-N5010:~$
[Part 2 of question]
Now , I find implementations of mg_stop , mg_start,mg_printf and mg_get_request_info in mongoose.c file , so I compile mongoose.c file with -c option as :
gcc -c -o mongoose.o mongoose.c
I think my question is similar to :-
undefined reference to function declared in *.h file
but then when I link libmongoose.so with -L option on gcc I get following errors:-
(libmongoose.so is present in same directory ,my cwd)
akshay#akshay-Inspiron-N5010:~/mongoose$ gcc -L libmongoose.so -o hello hello.o mongoose.o
mongoose.o: In function `mg_start_thread':
mongoose.c:(.text+0x1369): undefined reference to `pthread_create'
mongoose.o: In function `load_dll':
mongoose.c:(.text+0xa955): undefined reference to `dlopen'
mongoose.c:(.text+0xa9b4): undefined reference to `dlsym'
collect2: ld returned 1 exit status
also , I continue to get above ^^ errors when I compile without using libmongoose.so
[EDIT] : added -pthread option on gcc, still shows errors :-
mongoose.o: In function load_dll':
mongoose.c:(.text+0xa955): undefined reference todlopen'
mongoose.c:(.text+0xa9b4): undefined reference to `dlsym'
collect2: ld returned 1 exit status
For part 1 and part 2 of my question : I want to get rid of these errors and successfully run hello.c program sample successfully.
Thanks in advance .
The -L option is not used for linking against a library, it's used for specifying a search path for dynamic libraries. To link against a specific library, use -l. However, you don't need to link against both of mongoose.o and libmongoose.so, either one is sufficient.
On Linux, you also have to link against the pthread and the dynamic loading library as well, because despite being part of the C standard library, they're not present in libc.so. One more thing to pay attention to is that recent versions of binutils (specifically, of ld) require that the libraries and object files be specified in the order the symbols depend on each other, i. e. libraries must go to the end of the command line.
All in all, use one of the following commands:
gcc -o hello hello.o mongoose.o -ldl -lpthread
or
gcc -L. -o hello hello.o -lmongoose -ldl -lpthread

Getting following error "collect2: ld returned 1 exit status"

I have created a C source file using the modules from other source files. Suppose the created source file is abc.c .Mine C file compiles fine using the following command.
gcc -c abc.c
I have compiled each and every source file that are linked to the abc.c .While creating the executable file using the following command:
gcc abc.o b.o c.o ....strings.o -o abc
It shows the following error, although i have used strings.o for creating executable file:
strings.o: In function `string_IntToString':
strings.c:(.text+0x5d3): undefined reference to `log10'
strings.c:(.text+0x606): undefined reference to `log10'
collect2: ld returned 1 exit status
Could you suggest me what can be the wrong here?
You forgot to link against libm.
gcc ... -lm ...

Resources