I am implementing a OpenSSL code and have already included required header files but still I am getting errors like *
undefined reference to SSL_library_init
I guess it's a linking error rather than a compilation error.
I am implementing it in Linux box using slickeditor.
Link against libssl and libcrypto. Your LDFLAGS and LDLIBS would be as follows. Order matters for LDLIBS:
LDFLAGS = -L/usr/local/ssl/lib
LDLIBS = -lssl -lcrypto
Don't worry about adding the "lib" in front of library name, or the "so" or "a" suffix. The linker will do it for you.
If you are building from the command line, then you would use the following. Again, order matters.
gcc foo.c -o foo.exe -L/usr/local/ssl/lib -lssl -lcrypto
If you are using the system's OpenSSL, then you can omit -L/usr/local/ssl/lib.
For me this meant to install
apt install libssl1.0-dev
These methods are deprecated in OpenSSL 1.1. You don't need to use it more. You can just remove it. More info in OpenSSL manual.
ldd libssl.so -> libcrypto.so.1.1 => not found
sudo ln -s /usr/local/lib64/libcrypto.so.1.1 /usr/lib64/libcrypto.so.1.1
libcrypto.so.1.1 => /lib64/libcrypto.so.1.1 (0x00007f17d46c7000)
Simply add -lssl -lcrypto to your Makefile and it should work.
Example of Makefile:
foo: foo.o
g++ -std=c++17 -o foo foo.cpp -lcrypto -lssl
Related
I try to compile a library on linux. this libary uses <openssl/sha.h> library. I have included this library in source file. After that, i use flag -lssl and flag -lcrypto to compile this project. So here is my command :
gcc -g -Wall -lssl -lcrypto -o bt_client file_a.c file_b.c
But I meet error :
undefined reference to `SHA1' at line 130
Code at line 130 is :
SHA1((unsigned char *) null_padded_name, 20, (unsigned char *)name_sha1);
Do I miss something ? Please correct me. Thanks :)
Try this:
gcc -g -Wall -o bt_client file_a.c file_b.c -lssl -lcrypto
If you are sure that symbol SHA1 exists in libssl.so or libcrypto.so.
When you link your application, the linker looks for dependencies in the order you give them on the command line.
So if you add a library (like -lssl) before the source/object file that depends on that library, the linker will not find any dependencies and ignore the library.
This means that you must always put libraries last on the command line.
You need to provide -lssl and -lcrypto at the end of the command line:
gcc -g -Wall -o bt_client file_a.c file_b.c -lssl -lcrypto
This question already has an answer here:
Errors that refer to a bunch of unresolved OpenSSL symbols that clearly exist?
(1 answer)
Closed 6 years ago.
I'm attempting to use OpenSSL's EVP interface to do some encryption. I'm pretty sure my code is right, but I can't seem to get it to compile. I'm using GCC, and Ubuntu 32-bit precise with libssl-dev installed and at the latest version.
The project currently consists of one file, program.c.
#include <openssl/evp.h>
...
i = EVP_BytesToKey(EVP_aes_256_cbc(), EVP_sha1() ... );
...
EVP_CIPHER_CTX_init(e_ctx);
among other various calls.
Here is how I invoke gcc:
gcc -Wall -g -lssl -lcrypto -o program program.c
Then I get output like this
/home/andy/program/program.c:31: undefined reference to `EVP_sha1'
/home/andy/program/program.c:31: undefined reference to `EVP_aes_256_cbc'
/home/andy/program/program.c:31: undefined reference to `EVP_BytesToKey'
/home/andy/program/program.c:44: undefined reference to `EVP_CIPHER_CTX_init'
So the include is clearly working:
andy#ProgStation2:/usr/include$ find . | grep evp.h
./openssl/evp.h
Here is the output of locate libcrypto. My best guess is that this is a stupid location for it and is why my link is failing, so I tried -L/usr/lib/i386-linux-gnu before -lcrypto with no luck as well.
/lib/i386-linux-gnu/libcrypto.so.1.0.0
I'm kind of stumped. If anyone wants to make me feel like a fool, I'd be very excited to figure out what i'm doing wrong!
It turns out it was something stupid. In the linker step, I was using gcc -Wall -g -lssl -lcrypto -o program program.o. I needed to move the library links to after the object file I was linking, and put libssl before libcrypto:
gcc -Wall -g -o program program.o -lssl -lcrypto
Try including headers using -I option, Look into directory for library using -L and finally specifying the library name with -l
Just making guess here, please specify path based on actual location.
gcc -g -Wall -L/usr/lib -I/usr/include -lssl -lcrypto -o program program.c
Hope it may help.
I am trying to create an C application on Debian GNU/Linux which uses the PortAudio interface. To do this I must compile my program with gcc -lrt -lasound -ljack -lpthread -o YOUR_BINARY main.c libportaudio.a from this docs.
For this I installed libasound2-dev, and I checked where the files are using apt-file search libasound.so, this is the output:
lib32asound2: /usr/lib32/libasound.so.2
lib32asound2: /usr/lib32/libasound.so.2.0.0
lib32asound2-dev: /usr/lib32/libasound.so
libasound2: /usr/lib/x86_64-linux-gnu/libasound.so.2
libasound2: /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0
libasound2-dev: /usr/lib/x86_64-linux-gnu/libasound.so
So the libasound should be installed correctly, but when I compile my program with this makefile:
DMXTest: main.c libdmx.a
gcc -static -Wall main.c -L. -ldmx -lusb -lrt -lasound -ljack -lfftw3 -g -o main libportaudio.a
I get the following error: /usr/bin/ld: cannot find -lasound.
How can I link this library correctly?
You don't have libasound.a for -static, you will need that, or you can almost certainly just remove -static from the Makefile (likely in LDFLAGS or CFLAGS).
There's is a related Debian bug 522544, and a related Ubuntu bug #993959.
You may be able to build your own libasound from source, though as it also uses other libraries (notably libpthread.so, librt.so and libdl.so) I suspect it may remove some functionality when you build it statically, though it's supported with ./configure --enable-static at build time
(or try --enable-shared=no --enable-static=yes).
FWIW, the use of static binaries is "discouraged" by the glibc maintainers, though I don't agree...
To compile my code i used the following command
gcc -o rec_mic rec_mic.c -lasound
and it works perfectly, without create my own static library.
i use rrd (graphic programming ) under rrdtool, i have installed; and i rund gcc
gcc -I/usr/include -I/usr/local/include -L/usr/lib -L/usr/local/lib -lrrd -o myprog test.c
myprog is execute file
and test.c ist testprogram who i use function rrd_create from libary but gcc put out error like this:
/usr/bin/ld: cannot find -lrrd
why!!!!
This error message indicates that the linker cannot locate librrd.a or librrd.so* in /usr/lib/ or /usr/local/lib. You should make sure that you have librrd installed, and not just some other binary rrd package.
I know that LD_LIBRARY_PATH is evil and it's a good habit to avoid using it.
I have a program called server.c on a remote Solaris 9 server that holds two versions of openssl library (0.9.8 and 1.0.0) and I'm using gcc 3.4.6. My program need to link to 1.0.0a version. Because it's work environment, I don't have the right to modify anything in the openssl library directory. I figured out to compile my program with both -L and -R options without setting LD_LIBRARY_PATH and it worked fine. (I noticed it won't work without setting -R option) But the compiled program kept linking to /usr/local/ssl/lib/libssl.so.0.9.8 instead of /.../libssl.so.1.0.0. Is there a work-around for this?
BTW, please correct me if I'm wrong: is it the -R option that actually "link" the shared libraries at runtime and -L option only "load" shared libraries at compile time?
Any help will be much appreciated!
Z.Zen
//////////////////////////////////////////////
Here is my Makefile:
CC = gcc
OPENSSLDIR = /usr/local/ssl
CFLAGS = -g -Wall -W -I${OPENSSLDIR}/include -O2 -D_REENTRANT -D__EXTENSIONS__
RPATH = -R${OPENSSLDIR}/lib
LD = ${RPATH} -L${OPENSSLDIR}/lib -lssl -lcrypto -lsocket -lnsl -lpthread
OBJS = common.o
PROGS = server
all: ${PROGS}
server: server.o ${OBJS}
${CC} server.o ${OBJS} -o server ${LD}
clean:;
${RM} ${PROGS} *.ln *.BAK *.bak *.o
I figured out that I can include the absolute path of the specific library that I want to link to and it worked fine for me:
LD = ${RPATH} -lsocket -lnsl -lpthread ${OPENSSLDIR}/lib/libssl.so.1.0.0 \
${OPENSSLDIR}/lib/libcrypto.so.1.0.0
If you are using g++, Piotr Lesnicki pointed out that -l:libssl.so.1.0.0 also works. See more at the original post.
Do you have any links to the SSL lib?
If not, can you create a link to the the desired SSL lib like
ln -s libssl.so.1.0.0 libssl.so
in the ssl directory and try it