3

我在 MinGW 和 C++ 编译器下使用 OpenSSL 编译和链接程序时遇到问题。这些是我的标题:

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <openssl/rsa.h>
#include <openssl/engine.h>
#include <openssl/pem.h>

更新(检查评论):

我想使用 MinGW 编译它,所以我首先尝试:

i686-w64-mingw32-g++ -o crypto_file_example base64.h en.cpp -lssl -lcrypto

但我得到了:

en.cpp:5:25: fatal error: openssl/rsa.h: No such file or directory
compilation terminated.

所以我尝试了:

i686-w64-mingw32-g++ -o crypto_file_example base64.h en.cpp -I/usr/local/openssl/include/ /usr/local/openssl/lib/libssl.a /usr/local/openssl/lib/libcrypto.a /usr/lib/x86_64-linux-gnu/libdl.a

这是另一个错误:

 /tmp/ccZGvNhw.o:en.cpp:(.text+0x5ec): undefined reference to `BIO_new_mem_buf'
/tmp/ccZGvNhw.o:en.cpp:(.text+0x602): undefined reference to `BIO_set_flags'
/tmp/ccZGvNhw.o:en.cpp:(.text+0x625): undefined reference to `PEM_read_bio_RSA_PUBKEY'
/tmp/ccZGvNhw.o:en.cpp:(.text+0x633): undefined reference to `ERR_get_error'
/tmp/ccZGvNhw.o:en.cpp:(.text+0x643): undefined reference to `ERR_error_string'
/tmp/ccZGvNhw.o:en.cpp:(.text+0x65e): undefined reference to `BIO_free'
/tmp/ccZGvNhw.o:en.cpp:(.text+0x67c): undefined reference to `BIO_new_mem_buf'
/tmp/ccZGvNhw.o:en.cpp:(.text+0x6a2): undefined reference to `PEM_read_bio_RSAPrivateKey'
/tmp/ccZGvNhw.o:en.cpp:(.text+0x6b0): undefined reference to `ERR_get_error'
/tmp/ccZGvNhw.o:en.cpp:(.text+0x6c0): undefined reference to `ERR_error_string'
/tmp/ccZGvNhw.o:en.cpp:(.text+0x6db): undefined reference to `BIO_free'
/tmp/ccZGvNhw.o:en.cpp:(.text+0x6f1): undefined reference to `RSA_size'
/tmp/ccZGvNhw.o:en.cpp:(.text+0x72a): undefined reference to `RSA_public_encrypt'
/tmp/ccZGvNhw.o:en.cpp:(.text+0x740): undefined reference to `ERR_get_error'
/tmp/ccZGvNhw.o:en.cpp:(.text+0x750): undefined reference to `ERR_error_string'
/tmp/ccZGvNhw.o:en.cpp:(.text+0x776): undefined reference to `RSA_size'
/tmp/ccZGvNhw.o:en.cpp:(.text+0x792): undefined reference to `RSA_size'
/tmp/ccZGvNhw.o:en.cpp:(.text+0x7b9): undefined reference to `RSA_private_decrypt'
/tmp/ccZGvNhw.o:en.cpp:(.text+0x7cf): undefined reference to `ERR_get_error'
/tmp/ccZGvNhw.o:en.cpp:(.text+0x7df): undefined reference to `ERR_error_string'
/tmp/ccZGvNhw.o:en.cpp:(.text+0x918): undefined reference to `OPENSSL_init_crypto'
/tmp/ccZGvNhw.o:en.cpp:(.text+0x9a4): undefined reference to `RSA_free'
/tmp/ccZGvNhw.o:en.cpp:(.text+0xa4c): undefined reference to `RSA_free'
collect2: error: ld returned 1 exit status

顺便说一句,我通过从 openssl 网站下载并编译它来安装 OpenSSL!

那么有什么帮助吗?或者尝试新的想法?

4

0 回答 0