I'm trying to compile a C file against a shared library at a specific location (/home/user/cuda_sync_analyzer-install/lib/libInsertTimingInstr.so), but ld cannot seem to find it -
$ gcc -g -I/home/user/tools/cuda_sync_analyzer/src/InsertTimingInstr \
-L/home/user/cuda_sync_analyzer-install/lib/ \
callback.c -o callback -lInsertTimingInstr.so
/usr/bin/ld: cannot find -lInsertTimingInstr.so
collect2: error: ld returned 1 exit status
I also tried
$ gcc -g -I/home/user/tools/cuda_sync_analyzer/src/InsertTimingInstr \
-L/home/user/cuda_sync_analyzer-install/lib/ \
-lInsertTimingInstr.so callback.c -o callback
/usr/bin/ld: cannot find -lInsertTimingInstr.so
collect2: error: ld returned 1 exit status
as well as setting LD_LIBRARY_PATH
$ export LD_LIBRARY_PATH=/home/user/cuda_sync_analyzer-install/lib/
$ gcc -g -I/home/user/tools/cuda_sync_analyzer/src/InsertTimingInstr \
callback.c -o callback -lInsertTimingInstr.so
/usr/bin/ld: cannot find -lInsertTimingInstr.so
collect2: error: ld returned 1 exit status
The file libInsertTimingInstr.so is present in the directory -
$ ls -l /home/user/cuda_sync_analyzer-install/lib/ | grep Timing
-rw-r--r-- 1 user user 51992 Mar 18 18:04 libInsertTimingInstr.so
but ld cannot seem to find it
This command line: gcc ... -lInsertTimingInstr.so ... asks the linker to link against libInsertTimingInstr.so.a or libInsertTimingInstr.so.so, neither of which exists.
You want: gcc ... -lInsertTimingInstr ... (i.e. drop the lib prefix and the .so suffix).
Alternatively, you could do this: gcc ... /home/user/cuda_sync_analyzer-install/lib/libInsertTimingInstr.so ...
Related
Trying to link a program which (for unknown reasons) generates a reference to "xmemdup".
I found the source code for xmemdup.c, and compiled it, and included the .o file in the link, but ld still claims it is undefined.
$ gcc -Wall -g -O2 -pipe -DBINDIR=\"/usr/bin\" -c -o rsh.o rsh.c
This worked, generating rsh.o
$ ll rsh.o ../publib-0.40/alloc/xmemdup.o
-rw-r--r-- 1 perryh perryh 2344 Dec 29 22:25 ../publib-0.40/alloc/xmemdup.o
-rw-r--r-- 1 perryh perryh 68656 Dec 30 00:47 rsh.o
Proves that the .o files I am about to pass to the linker do exist. BTW xmemdup.o is an object file, not a library, so it should get included unconditionally even if it were not needed to resolve a reference.
$ gcc -Wall -g -O2 -pipe -DBINDIR=\"/usr/bin\" -o rsh rsh.o ../publib-0.40/alloc/xmemdup.o
/usr/bin/ld: symbol lookup error: /usr/bin/ld: undefined symbol: xmemdup
collect2: error: ld returned 127 exit status
and yet the linker can't see the definition of xmemdup in xmemdup.o
I've install raylib according to this wiki page.
My Project Folder is look like this:
[this][1]
> ..\build>mingw32-make
g++ ../main.cpp -o test.exe -O2 -Wall -Wno-missing-braces -I ../include/ -L ../lib/ -lraylib -lopeng132 -lgdi32 -lwinmm
D:/Software/raylib/mingw/bin/../lib/gcc/i686-w64-mingw32/8.1.0/../../../../i686-w64-mingw32/bin/ld.exe: cannot find -lopeng132
collect2.exe: error: ld returned 1 exit status
mingw32-make: *** [Makefile:2: default] Error 1```
[1]: https://i.stack.imgur.com/QK2X3.png
It seems you have typed openg132 instead of opengl132. You have mistaken the letter l for the number 1
I have the problem about linking libraries.
"見つかりません" means "Not found"
edit LD_LIBRARY_PATH
$ LD_LIBRARY_PATH="/home/myname/.local/boost/lib" g++ main.cc -lboost_serialization
/home/myname/.linuxbrew/bin/ld: -lboost_serialization が見つかりません
collect2: error: ld returned 1 exit status
edit LIBRARY_PATH
$ LIBRARY_PATH="/home/myname/.local/boost/lib" g++ main.cc -lboost_serialization
/home/myname/.linuxbrew/bin/ld: -lboost_serialization が見つかりません
collect2: error: ld returned 1 exit status
adding the -L option (successfully compiled)
$ g++ main.cc -lboost_serialization -L "/home/myname/.local/boost/lib"
$
Indeed I have successfully compiled my program with the -L option.
But I want to compile without this (like 1 or 2, not 3).
In this case, what do I have to check or modify in my environmental variables?
note: my gcc is 5.3.0 (Homebrew gcc 5.3.0).
I can't compile yacc i lex:
$ cc gramatyka.c gramatyka.h semantyka.c -ly -ll
output error:
/usr/bin/ld: cannot find -ly collect2: error: ld returned 1 exit status
How to fix it?
Most probably you are missing the -L path/to/dir/with/liby in your LDFLAGS (in case liby is in the same folder, just prepend -L. before -ly).
The reason you are getting this error is because compiler is not able to link this library. Add the complete path using "-L" option if you are not sure about default location of this library.
I know this is something so simple I'm going to hate myself for having to ask it, but my head is aching from repeated hits on the desktop. I've read dozens of stackoverflow and google results which suggest that the following should work:
$ ls /usr/local/lib/libusb*
/usr/local/lib/libusb-1.0.a /usr/local/lib/libusb-1.0.so /usr/local/lib/libusb-1.0.so.0.1.0
/usr/local/lib/libusb-1.0.la /usr/local/lib/libusb-1.0.so.0
$ gcc -I ~/libusb-1.0.18/libusb -c test.c
$ gcc -L/usr/local/lib -o test test.o -llibusb
/usr/bin/ld: cannot find -llibusb
collect2: error: ld returned 1 exit status
$ gcc -L/usr/local/lib -o test test.o -llibusb-1.0
/usr/bin/ld: cannot find -llibusb-1.0
collect2: error: ld returned 1 exit status
Why is that not correct? One of those should have worked and I've tried many, many more variations.
For completeness I'm running Ubuntu 14.04 (fresh VM installation).
I built libusb from source (~/libusb-1.0.18) with:
./configure --disable-udev
make
sudo make install
The leading lib and trailing .so are automatically filled in by the linker, so you should not specify either on the command line. Your command should be:
gcc -L/usr/local/lib -o test test.o -lusb-1.0