Andry
Andry

Reputation: 16845

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?

Upvotes: 12

Views: 52554

Answers (3)

byrnesj1
byrnesj1

Reputation: 311

I had related issue, and resolved it after inspecting the trace.

I had

-L<my/path/to/lib> -llib_some_library

when it should have been

-L<my/path/to/lib> -lsome_library

Upvotes: 0

Andry
Andry

Reputation: 16845

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...

Upvotes: 3

tristan
tristan

Reputation: 4322

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

Upvotes: 6

Related Questions