I have a program that I am writing and that needs to calculate some hashes. I need SHA, MD, HMAC algorithms. That is why I chose openssl
as solution.
My code is the following:
#include <openssl/md4.h>
void calc();
void calc(unsigned char* data, unsigned long len) {
unsigned char* h = new unsigned char[128];
MD4(data, len, h);
}
Compiler returns me the following:
myfile.cpp:(.text+0x3e): undefined reference to `MD4' collect2: ld returned 1 exit status
I compile simply using:
g++ myfile.cpp -o myapp.o
under Linux Fedora.
I downloaded openssl
libraries from here and compiled them cby using ./configure
and then make install
in the downloaded untarpalled directory. I also copied in /usr/local/include
directory the include
directory in the one I downloaded so that headers can be found by compiler because /usr/local/include
is in my $PATH
env var.
However the problem is that the linker cannot find the function. I understand that the reason might be two:
- The compiler can find headers but cannot find implementations.
- There are problems because
openssl
is written inC
not inC++
.
How should I proceeed? Thankyou
Edit1
I actually changed something in my openssl installation
.
I installed openssl
again and I could see that it places everything under /usr/local/ssl
where I can find /usr/local/ssl/include
and /usr/local/ssl/lib
directories. I change my compilation string in:
g++ -I/usr/local/ssl/include -L/usr/local/ssl/lib -lssl -lcrypto
In the directories that I mentioned before I can find, respectively, /usr/local/ssl/include/openssl
directory with all headers there and /usr/local/ssl/lib/libssl.a
and /usr/local/ssl/lib/libcrypto.a
libraries.
Before I did this change when I used the old compilation command, the compiler was telling me: Cannot find -lssl
. With these changes, now it can find libs and headers, but ld
always fails in the same way:
myfile.cpp:(.text+0x3e): undefined reference to `MD4' collect2: ld returned 1 exit status
A little disappointed. What do you think?