I am compiling my code with
gcc -o ./sample/createUsageXMLd ./obj/createUsageXML.o -L../../../third_party/lib/openssl-fips/2.0/LSBGCC64 -L../../../third_party/lib/curl/7.45.0/LSBGCC64 -lssl -lcrypto
But I get error
/
usr/bin/ld: warning: libssl.so.1.0.0, needed by ../../../third_party/lib/curl/7.45.0/LSBGCC64/libcurl.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: libcrypto.so.1.0.0, needed by ../../../third_party/lib/curl/7.45.0/LSBGCC64/libcurl.so, not found (try using -rpath or -rpath-link)
../../../third_party/lib/curl/7.45.0/LSBGCC64/libcurl.so: undefined reference to `SSL_CTX_set_srp_username'
../../../third_party/lib/curl/7.45.0/LSBGCC64/libcurl.so: undefined reference to `SSL_CTX_set_srp_password'
collect2: error: ld returned 1 exit status
I have the following in my
libraries third party folder
$ cd third_party/lib/openssl-fips/2.0/LSBGCC64/
$ ls
libcrypto.a libcrypto.so libcrypto.so.1.0.0 libssl.a libssl.so libssl.so.1.0.0
You also need to provide the name of the library that you wish to link,
gcc file.c -o file -L/path/to/libs -llibname
In your case, try providing -lssl after including the path to your libraries (which you've done using -L). Note that the prefix "lib" and suffix ".so" are not required.
I tried installing curl with yum install. I checked the version of installed curl.It was 7.29.0. My compilation was successful. Later I degraded the version of curl from 7.45.0 to 7.29.0 in third_party folder. Now it compiles fine
Related
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 have static library lib.a and in all tutorials using:
gcc -o main main.o -L. -lib
But I cant, I have errors:
/usr/bin/ld: cannot find -lib
collect2: error: ld returned 1 exit status
I need to use:
gcc -o main main.o -L. -lib.a
Why? What should I do to repair it ?
From the documentation of gcc -l:
-llibrary:
The linker searches a standard list of directories for the library, which is actually a file named liblibrary.a. The linker then uses this file as if it had been specified precisely by name.
...
The only difference between using an -l option and specifying a file name is that -l surrounds library with ‘lib’ and ‘.a’ and searches several directories.
So you cannot use -l with a library named 'lib.a'. Use 'lib.a' without the -l to include it. Of course, you cannot use -L then to set the directories to be searched for this particular library.
Do you have the error with this line ?
gcc -o main main.o -L. -llib
As MicroVirus found in the documentation, you will have to rename your library in liblib.a to use my previous line or just pass your library to gcc like a simple file.
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 am working with c++ code for a physics simulation, which uses a lot of external libraries (like GSL and cern`s ROOT). Trying to recompile project I encountered problems with linking. When running compilation of final file via:
g++ -fno-inline -O2 -fpic -o main.out ${ROOTINCS} main.o ext.o ${ROOTLIBS} $(objects2)
with :
objects2= many .o files made by us
ROOTLIBS=-L/usr/local/lib/root -lTree -lRIO -lNet -lHist -lMathCore -lCore -lGraf -lGraf3d -lGpad -lMatrix -lThread -lCint -lPhysics -lPostscript -lRint -lSpectrum -lg
ROOTINCS=-pthread -m64
I get annoying error:
/usr/bin/ld: /usr/local/lib/root/libHist.so: undefined reference to symbol 'gRandom'
/usr/local/lib/root/libMathCore.so: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
The problem is nm -C run on libMathCore states 'gRandom' is declared there. Also -lMathCore is present in my command line.
When I run ld to check if it understands the flag:
ld -L/usr/local/lib/root -lMathCore --verbose 2>/dev/null
it does not complain and tries to link properly.
According to https://stackoverflow.com/a/24675715/3602168 order of libraries is correct in my linking (libHist uses libMathCOre and therefore is stated first).
Compilation runs under g++ 4.8.2 on ubuntu 14.04, 64 bit
Converting comment to answer:
Have you tried moving $(objects2) before ${ROOTLIBS}? I think the issue may be that you have libraries specified before the object files that use them.
I have the openssl folder here:
C:\Dev-Cpp\include\openssl
In dev c++ I gave the following to the linker command line:
-lssl -lcrypto -l<C:\Dev-Cpp\include\openssl>
and the following to when it calls the compiler:
-L<C:\Dev-Cpp\include\openssl>
After compilation the dev c++ shows this error:
cannot find -l<C:\Dev-Cpp\include\openssl>
ld returned 1 exit status
remove the -l<C:\Dev-Cpp\include\openssl> from you link line command.
-lssl -lcrypto
you have already linked to the openssl library with -lssl -lcrypto
If you want to specify the path where the library are saved. you have to use only
-L<C:\Dev-Cpp\include\openssl>