I have used libftdi in the past and compiled using the command:
gcc -lftdi -o i2csend i2csend.c
Everything went fine.
Today, on Ubuntu 12.10 I get many errors such as undefined reference toftdi_init'`
I understand that libftdi was renamed to libftdi1 so I tried the same command with -lftdi1 and got error:
/usr/bin/ld: cannot find -lftdi1
collect2: error: ld returned 1 exit status
Can anyone explain why?
You should typically not directly specify external package's library names.
It's better to use the packaging system's help program, i.e. pkg-config, like so:
$ gcc -o i2csend i2csend.c $(pkg-config --cflags --libs libftdi1)
Note that this assumes that the package name is libftdi1 in pkg-config's database; I'm not sure how to verify this portably. You can run pkg-config --list-all | grep ftdi to find out.
It's generally a good idea to keep the libraries part (-l option) at the end of the command line, which the above is doing. It's somewhat cleaner to factor out the CFLAGS part, but that requires repeating the command:
$ gcc $(pkg-config --cflags libftdi1) -o i2csend i2csend.c $(pkg-config --libs libftdi1)
Here, I've used double spaces to separate the logical parts of the command line for improved clarity.
Related
After much research, trying to find out how to link libraries to gcc, going to /usr/bin and /usr/lib confirming the stuff are there. When I try to compile my keygen file, this is the error it blurts out.
$ gcc keygen.c -W -Wall /usr/bin/libgcrypt-config
/usr/bin/libgcrypt-config: file not recognized: File format not recognized
collect2: error: ld returned 1 exit status
I've been told by numerous sources that I should compile this way to check if libgcrypt installed correctly.
$ gcc -o foo foo.c 'libgcrypt-config --cflags --libs'
But everytime I try to do that this is what it blurts out:
gcc: error: libgcrypt-config --cflags --libs: No such file or directory
I've confirmed that libgcrypt20 and libgcrypt20-dev are installed using dpkg --get-selections>installed. But I am just so utterly confused as to what may be wrong.
Any form of help would be much appreciated.
Try:
$ gcc -o foo foo.c `libgcrypt-config --cflags --libs`
` instead of '
I follow the ffmpeg tuorial, and install ffmpeg via ppa
But when I compiled the tuorial02.c, I got gcc error:
/usr/bin/ld: /opt/ffmpeg/lib//libavcodec.a(libvorbisenc.o): undefined reference to symbol 'vorbis_encode_setup_vbr'
//usr/lib/x86_64-linux-gnu/libvorbisenc.so.2: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
My compile command is:
gcc -I /opt/ffmpeg/include/ -L /opt/ffmpeg/lib/ -o tutorial02 tutorial02.c -lavformat -lavcodec -lswscale `sdl-config --cflags --libs` -lpthread -lz -lm -ldl
I have searched the reason for hours. I can't solve this. Can anyone help me?
Added I have add -lvorbisenc to the end. the error is lib not found. and libvorivisenc2 has been install. so this question is not a duplicate of Strange linking error: DSO missing from command line
And My OS is Linux mint 17.3
The error is telling you that the static library libavcodec.a references symbols from libvorbisenc but libvorbisenc isn't explicitly in your link command (though it did find a good candidate from another shared library in the link command). You'll need to add -lvorbisenc or $(pkg-config --libs vorbisenc) explicitly to your command line.
(Older versions of binutils would let you bring in shared libraries implicitly in this situation; however, newer versions of binutils are stricter.)
I'm trying to recompile my software for debian 8, but i have run into this strange issue of libgssappi refusing to link with anything.
>~/torque_github$ gcc test.c -lgssapi
/usr/bin/ld: cannot find -lgssapi
collect2: error: ld returned 1 exit status
The library is present in the system, as seen here:
>~/torque_github$ /sbin/ldconfig -p | grep gssapi
libgssapi_krb5.so.2 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libgssapi_krb5.so.2
libgssapi.so.3 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libgssapi.so.3
On my Debian/Jessie/x86-64 system, /usr/lib/x86_64-linux-gnu/libgssapi_krb5.so is provided (according to dpkg -S) by the libkrb5-dev package and /usr/lib/x86_64-linux-gnu/libgssapi.so.3 is provided by libgssapi3-heimdal package (and I don't have any libgssapi*dev package).
You probably should install both of them (with sudo aptitude install libkrb5-dev libgssapi3-heimdal command), and use pkg-config with krb5-gssapi to get compilation and linking flags.
gcc -Wall -g $(pkg-config --cflags krb5-gssapi) \
test.c \
$(pkg-config --libs krb5-gssapi) \
-o myprog
(you could have to change your test.c source code if some API has changed; perhaps you'll need to #include <krb5/krb5.h>)
You might even use gcc -v instead of gcc above.
Remember that order of arguments to gcc matters a big lot. Your initial question had a different order (and that is enough to make gcc fail)!
I need to include libexplain to my project to do certain job. I install it and add the header libexplain/read.h to my code, so far so good and no error reported by the complier. But when I use the function explain_read() provided by libexplain and build the project it says:
/tmp/cc7NjAw0.o: In function `xl45_read(int, unsigned char*)':
connections.cpp:(.text+0x2f): undefined reference to `explain_read'
collect2: error: ld returned 1 exit status
and the build script is:
#!/bin/bash
echo > ./stdafx.h
g++ -O1 -Wall -o ./local_proxy (*.cpp...here is the source file list) -lz -lpthread -lpcap -L/usr/local/lib
actually when I type
whereis libexplain
in terminal, I get
libexplain: /usr/lib/libexplain.so /usr/lib/libexplain.a /usr/include/libexplain
I do a lot of searches and still have no idea what's going wrong. ):
You need to link your object files with libexplain. You can do it using the -l<library name>, like so:
g++ -O1 -Wall -o ./local_proxy *.cpp -lz -lpthread -lpcap -lexplain -L/usr/local/lib
Note the -lexplain flag. For a library with the a file name like libABC.so, you'd use -lABC to refer to that library. The documentation for link options with GCC can shed more light on it.
I'm trying to compile some c code via make with gcc, but I keep getting:
/usr/bin/ld: cannot find -lnetlink
I have -lnetlink included in the gcc make parameters. Using locate netlink is able to find multiple items. I've even told gcc exactly where to find one by using -L/usr/include/linux, but it still gives the error.
The gcc command arguments below:
gcc -g -ggdb -Wall -Wextra -o mt6d mt6d.o address_worker.o tunnel_worker.o mt6d_assoc.o addr_gen.o send_utils.o if_utils.o tun_utils.o icmp_utils.o utils.o -lcrypto -lssl -lnetlink -lpthread -lnetfilter_queue
I've also been having errors with libnetlink.h, but was able to get them resolved, but I've included that here if that might be related and this error appears immediately after the other was fixed. Fixed by using C_INCLUDE_PATH
I've recently upgraded to Ubuntu 13.04 and was using 11.04 before that.
Let me know if you need any more information. Any help would be greatly appreciated!
Thanks,
-Alan
I'm trying to compile some c code via make with gcc, but I keep getting:
Technically, this stage is called linking. That difference may seem subtle at first, but it's a really important one and can help frame the investigation when problems like this arise.
You should not reference /usr/include paths with -L. -L adds to the search path for libraries and generally only header files should show up under /usr/include.
libnl enables pkg-config, so you should use that.
For example (assuming you have libnl-3-dev installed):
gcc -o my_executable $(pkg-config --libs libnl-3.0) my_foo.o my_bar.o
In a Makefile, you could do the following to achieve that effect:
LDLIBS+=$(shell pkg-config --libs libnl-3.0)
CFLAGS+=$(shell pkg-config --cflags libnl-3.0)