I wrote a C function which calls a function defined in openssl/sha.h
, let's say the declaration is "helper.h"
and implementation is "helper.c
". Then I compiled that function using gcc and put it in a library:
gcc -std=c99 -lcrypto -lssl -c helper.c -o helper.o
ar -rc helper.a helper.o
Then I wrote a cpp function that calls the function declared in "helper.h"
. I added
extern "C" {
#include "helper.h"
}
stuff in that cpp file and then I used
g++ test.cpp helper.a -o cpp
Then the ld error occurs and says I encounter undefined reference for a function defined in openssl/sha.h
. I wonder how to resolve that?
Add ssl
and crypto
libs to your final command in order to link these libs to your program.
You must also respect the order: since sll
is using crypto
so you must put ssl
first and crypto
after.
g++ test.cpp helper.a -o cpp -lssl -lcrypto
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.