I am trying to compile a C code on Ubuntu 22.04.2 LTS, targeting Windows, using the MinGW-w64
cross-compilation toolchain. However, I'm encountering an error related to the OpenSSL headers not being found during the compilation process.
I have already installed the libssl-dev
package, which should provide the necessary headers.
snave@1080gems:~/Izoh$ ls /usr/include/openssl |grep ssl
opensslv.h
ossl_typ.h
prov_ssl.h
ssl.h
ssl2.h
ssl3.h
sslerr.h
sslerr_legacy.h
I even added openssl location when running it:
x86_64-w64-mingw32-gcc -o crypto.exe crypto.c -lssl -lcrypto -I/usr/include/openssl -L/usr/lib -lws2_32
--I Searched online how to do that.
But I'm still getting the error:
fatal error: openssl/rsa.h: No such file or directory
Am I missing something in the compilation process?
I will appreciate any help. Thank you!
You added
I/usr/include/openssl
and one of your error messages is
fatal error: openssl/rsa.h: No such file or directory
When you added I/usr/include/openssl
, files will be searched from that point. The #include <openssl/rsa.h>
line will cause the compiler to look for the file
/usr/include/openssl/openssl/rsa.h
which doesn't exist. You need to
-I/usr/include
path and not -I/usr/include/openssl
#include <openssl/rsa.h>
and not #include <rsa.h>
For example, see this OpenSSL documentation for RSA_free()
:
SYNOPSIS
#include <openssl/rsa.h> RSA *RSA_new(void); void RSA_free(RSA *rsa);
Note it's #include <openssl/rsa.h>
.