neoben
neoben

Reputation: 773

Compile C++ and OpenSSL on Ubuntu 11.10

I got a serious problem compiling my C++ and OpenSSL project on my Ubuntu 11.10. The compiling command is:

g++ -Wall -lssl -lm -lcrypto -I ./src ./src/server.cpp -o ./bin/server

I receive these errors:

server.cpp:(.text+0x8ff): undefined reference to `RSA_new'
server.cpp:(.text+0x92d): undefined reference to `PEM_read_RSAPrivateKey'
server.cpp:(.text+0xa85): undefined reference to `RSA_size'
server.cpp:(.text+0xaa1): undefined reference to `RSA_size'
server.cpp:(.text+0xae7): undefined reference to `RSA_private_decrypt'
server.cpp:(.text+0xd84): undefined reference to `BF_set_key'
server.cpp:(.text+0xf1d): undefined reference to `BF_ecb_encrypt'
server.cpp:(.text+0x13c6): undefined reference to `BF_ecb_encrypt'
collect2: ld returned 1 exit status
make: *** [server] Error 1

I successfully installed openssl and libssl-dev but the problem persists. I tried to compile the project on Linux Mint 12 with the kernel 3.0 and I had the same problem. On my old Linux OS with the kernel 2.6 the project compiled and worked fine (using the same Makefile and the same sources). Please help me!

Upvotes: 4

Views: 5285

Answers (3)

Navin
Navin

Reputation: 534

Those error are from crypto library, check whether ssl and crypto libraries are available in /usr/lib or where ever u installed if not install them and have u set the library search path for libssl and libcrypto in your compiling command?

Upvotes: 0

Joachim Isaksson
Joachim Isaksson

Reputation: 180857

As the comment to this answer states, the linker only looks for undefined symbols to include in the order the parameters are listed.

That is, if your cpp file uses the libraries, the libraries have to be listed after the cpp file.

Upvotes: 2

smparkes
smparkes

Reputation: 14053

Generally you need to have the -l link flags after the code that references them. Try

g++ -Wall  -I ./src ./src/server.cpp -o ./bin/server -lssl -lm -lcrypto

Upvotes: 9

Related Questions