Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++: linker cannot find -lcrypto, but the library is in the path

I am compiling a C++ application using GNU g++. The project takes advantage of OpenSSL libraries.

Background

On my machine (a 64 bit CentOS quad core) I compile and link my files.

g++ -g -c -L/usr/local/lib/ -L/usr/lib64/ 
    -I/usr/local/include/ -I/usr/local/ssl/include/ 
    -lcrypto mysrc1.cpp mysrc2.cpp mysrc3.cpp

g++ -L/usr/local/lib/ -L/usr/lib64/ -lcrypto 
    *.o -o ./myapp.out

My application uses function MD5 which is contained in libcrypto.so. As you can see I specify to g++ the dirs where to search using the -L, -I options and which libraries to look for with the -l<lib-name> option. There are some trivial paths like /usr/local/lib which can be omitted of course, but I specified them because the makefile is parametric.

The problem

My problem is that I can successfully compile my stuff (first command), but linking fails (second command):

/usr/bin/ld: cannot find -lcrypto

collect2: ld returned 1 exit status

make: * [cppsims_par] Error 1

But I did check folders and everything... libcrypto.so is inside /usr/lib64/. What is going on?

like image 880
Andry Avatar asked Oct 16 '13 14:10

Andry


2 Answers

It may help if you try strace to find why it failed the file lookup

strace -f -e trace=file g++ -L/usr/local/lib/ -L/usr/lib64/ -lcrypto 
    *.o -o ./myapp.out
like image 161
tristan Avatar answered Nov 19 '22 12:11

tristan


I did find the problem and it is related to this question: ld cannot find an existing library

Actually I had no symlink libcrypto.so and the compiler was not able to find the library...

like image 45
Andry Avatar answered Nov 19 '22 12:11

Andry