我在C ++上完成了一些项目,我需要为Windows XP及更高版本编译它。
这是我的RsaEncryptor
课程的标题文件(我认为在此处发布消息来源无关紧要,因为我确信100%它可以正常使用,但如果需要,我可以做到这一点):
#ifndef RSAENCRYPTOR_H_
#define RSAENCRYPTOR_H_
#include <stdexcept>
#include <openssl/rsa.h>
#include <openssl/engine.h>
#include <openssl/pem.h>
// One of this paddings can be used
//#define PADDING RSA_PKCS1_OAEP_PADDING
#define PADDING RSA_PKCS1_PADDING
//#define PADDING RSA_NO_PADDING
class RsaEncryptor {
private:
RSA* publicKey;
RSA* privateKey;
public:
RsaEncryptor() {
publicKey = nullptr;
privateKey = nullptr;
}
~RsaEncryptor() {
if ( this->publicKey )
RSA_free( this->publicKey );
if ( this->privateKey )
RSA_free( this->privateKey );
}
size_t GetCipherBytesCount() {
return 172; //is default for 1024 bit key length
}
void SetPublicKeyFromString(const std::string& content);
void SetPrivateKeyFromString(const std::string& content);
std::string Encrypt(const std::string& plainData);
std::string Decrypt(const std::string& cipherData);
};
#endif /* RSAENCRYPTOR_H_ */
我在Eclipse Neon
计算机上使用最新版本的Windows 10 x64
进行C ++开发。
此外,我已阅读this:
(...)在为Windows XP或Vista构建OpenSSL 1.1.0及更高版本时,您需要配置
no-async
我受到following指示的指导。
我做了什么:
在Ubuntu 17.04 x64
下的Virtual Box中安装Windows 10 x64
。
从Ubuntu
安装mxe以及所有要求(但无法使用它进行编译,我决定使用mingw32
)
通过mingw32
root@user-pc:/home/user# apt-get install gcc-mingw-w64-i686
在/home/user/openssl-x32
转到/home/user/openssl-x32
运行./Configure mingw --cross-compile-prefix=i686-w64-mingw32 --prefix=/home/user/builds/openssl-x32-static no-shared no-async
运行make
运行make install
将libssl.a
和libcrypto.a
从/home/user/builds/openssl-x32-static/lib
复制到主机(Windows 10 x64
)到文件夹E:\MyProjects\my-app\libraries\
将include
目录从Ubuntu
复制到文件夹E:\MyProjects\my-app\include
中的主机
将libraries
文件夹添加到链接器配置
将include
文件夹添加到编译器配置
然后,我构建了我的项目,得到了以下答案:
11:58:09 ****重建配置Debug for project app **** 信息:配置&#34;调试&#34;使用工具链&#34; MinGW GCC&#34;那是 在这个系统上不支持,无论如何都试图构建。信息:内部 Builder用于构建g ++ &#34; -IC:\ MyProjects下\我的应用内\包括&#34; -O0 -g3 -Wall -c -std = c ++ 11 -m32 -o RsaEncryptor.o&#34; .. \ RsaEncryptor.cpp&#34; g ++&#34; -IC:\ MyProjects \ my-app \ include&#34; -O0 -g3 -Wall -c -std = c ++ 11 -m32 -o main.o&#34; .. \ main.cpp&#34;在.. \ main.cpp中包含的文件中:5:0:.. \ FilesFinder.h:在成员函数&#39; void FilesFinder :: FindRecursively(const string&amp;,const FilesFilter&amp;)&#39;: .. \ FilesFinder.h:90:56:警告:签名和之间的比较 无符号整数表达式[-Wsign-compare] while(destinationContainer.GetElementsCount()&gt; = MAX_ELEMENTS_COUNT){ ^ g ++&#34; -IC:\ MyProjects \ my-app \ include&#34; -O0 -g3 -Wall -c -std = c ++ 11 -m32 -o aes256.o&#34; .. \ aes256.cpp&#34; g ++&#34; -LC:\ MyProjects \ my-app \ libraries&#34; -static-libgcc -static-libstdc ++ -static -lpthread -m32 -o C:/ MyProjects / my-app / bin / Debug / app RsaEncryptor.o aes256.o main.o -lssl -lcrypto -lgdi32 C:\ MyProjects下\我的应用程序内\库\ libcrypto.a(b_addr.o):b_addr.c :(文字+和0xAA): 未明确引用
_imp__getnameinfo@28' C:\MyProjects\my-app\libraries\libcrypto.a(b_addr.o):b_addr.c:(.text+0xe0): undefined reference to
_ imp__ntohs @ 4&#39; C:\ MyProjects下\我的应用程序内\库\ libcrypto.a(b_addr.o):b_addr.c :(文字+ 0x242): 未明确引用gai_strerrorW' C:\MyProjects\my-app\libraries\libcrypto.a(b_addr.o):b_addr.c:(.text+0x820): undefined reference to
_ imp__freeaddrinfo @ 4&#39; C:\ MyProjects下\我的应用程序内\库\ libcrypto.a(b_addr.o):b_addr.c :(文字+ 0xb5d): 未明确引用_imp__getaddrinfo@16' C:\MyProjects\my-app\libraries\libcrypto.a(b_addr.o):b_addr.c:(.text+0xba2): undefined reference to
gai_strerrorW&#39; C:\ MyProjects下\我的应用程序内\库\ libcrypto.a(b_sock.o):b_sock.c :(文字+ 0xd7): 未定义引用_imp__WSAStartup@8' C:\MyProjects\my-app\libraries\libcrypto.a(b_sock.o):b_sock.c:(.text+0xe8): undefined reference to
_ imp__WSAGetLastError @ 0&#39; C:\ MyProjects下\我的应用程序内\库\ libcrypto.a(b_sock.o):b_sock.c :(文字+ 0x2c7): 未定义引用_imp__WSAStartup@8' C:\MyProjects\my-app\libraries\libcrypto.a(b_sock.o):b_sock.c:(.text+0x2d8): undefined reference to
_ imp__WSAGetLastError @ 0&#39; C:\ MyProjects下\我的应用程序内\库\ libcrypto.a(b_sock.o):b_sock.c :(文字+ 0x3b1): 未明确引用_imp__ntohs@4' C:\MyProjects\my-app\libraries\libcrypto.a(b_sock.o):b_sock.c:(.text+0x40c): undefined reference to
_ imp__getsockopt @ 20&#39; C:\ MyProjects下\我的应用程序内\库\ libcrypto.a(b_sock.o):b_sock.c :(文字+ 0x423): 未明确引用_imp__WSAGetLastError@0' C:\MyProjects\my-app\libraries\libcrypto.a(b_sock.o):b_sock.c:(.text+0x43c): undefined reference to
_ imp__gethostbyname @ 4&#39; C:\ MyProjects下\我的应用程序内\库\ libcrypto.a(b_sock.o):b_sock.c :(文字+ 0x48b): 未定义引用_imp__WSAStartup@8' C:\MyProjects\my-app\libraries\libcrypto.a(b_sock.o):b_sock.c:(.text+0x4a2): undefined reference to
_ imp__WSAGetLastError @ 0&#39; C:\ MyProjects下\我的应用程序内\库\ libcrypto.a(b_sock.o):b_sock.c :(文字+ 0x52c): 未明确引用_imp__WSACleanup@0' C:\MyProjects\my-app\libraries\libcrypto.a(b_sock.o):b_sock.c:(.text+0x54d): undefined reference to
_ imp__ioctlsocket @ 12&#39; C:\ MyProjects下\我的应用程序内\库\ libcrypto.a(b_sock.o):b_sock.c :(文字+ 0x563): 未明确引用_imp__WSAGetLastError@0' C:\MyProjects\my-app\libraries\libcrypto.a(b_sock.o):b_sock.c:(.text+0x6b7): undefined reference to
_ imp__WSAStartup @ 8&#39; C:\ MyProjects下\我的应用程序内\库\ libcrypto.a(b_sock.o):b_sock.c :(文字+ 0x6c8): 未定义引用_imp__WSAGetLastError@0' C:\MyProjects\my-app\libraries\libcrypto.a(b_sock.o):b_sock.c:(.text+0x942): undefined reference to
_ imp__WSAGetLastError @ 0&#39; C:\ MyProjects下\我的应用程序内\库\ libcrypto.a(b_sock.o):b_sock.c :(文字+ 0x9dc): 未明确引用_imp__setsockopt@20' C:\MyProjects\my-app\libraries\libcrypto.a(b_sock.o):b_sock.c:(.text+0xa15): undefined reference to
_ imp__ioctlsocket @ 12&#39; C:\ MyProjects下\我的应用程序内\库\ libcrypto.a(b_sock.o):b_sock.c :(文字+ 0xa32): 未明确引用_imp__WSAGetLastError@0' C:\MyProjects\my-app\libraries\libcrypto.a(b_sock.o):b_sock.c:(.text+0xaa6): undefined reference to
_ imp__getsockname @ 12&#39; C:\ MyProjects下\我的应用程序内\库\ libcrypto.a(b_sock.o):b_sock.c :(文字+ 0xb22): 未明确引用_imp__WSAGetLastError@0' C:\MyProjects\my-app\libraries\libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x27): undefined reference to
_ imp__socket @ 12&#39; C:\ MyProjects下\我的应用程序内\库\ libcrypto.a(b_sock2.o):b_sock2.c :(文字+ 0x4e): 未明确引用_imp__WSAGetLastError@0' C:\MyProjects\my-app\libraries\libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x120): undefined reference to
_ imp__setsockopt @ 20&#39; C:\ MyProjects下\我的应用程序内\库\ libcrypto.a(b_sock2.o):b_sock2.c :(文字+ 0x15b): 未明确引用_imp__connect@12' C:\MyProjects\my-app\libraries\libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x1f5): undefined reference to
_ imp__setsockopt @ 20&#39; C:\ MyProjects下\我的应用程序内\库\ libcrypto.a(b_sock2.o):b_sock2.c :(文字+ 0x206): 未定义引用_imp__WSAGetLastError@0' C:\MyProjects\my-app\libraries\libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x265): undefined reference to
_ imp__WSAGetLastError @ 0&#39; C:\ MyProjects下\我的应用程序内\库\ libcrypto.a(b_sock2.o):b_sock2.c :(文字+ 0x2c6): 未明确引用_imp__WSAGetLastError@0' C:\MyProjects\my-app\libraries\libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x377): undefined reference to
_ imp__getsockopt @ 20&#39; C:\ MyProjects下\我的应用程序内\库\ libcrypto.a(b_sock2.o):b_sock2.c :(文字+ 0x38f): 未明确引用_imp__WSAGetLastError@0' C:\MyProjects\my-app\libraries\libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x4a7): undefined reference to
_ imp__setsockopt @ 20&#39; C:\ MyProjects下\我的应用程序内\库\ libcrypto.a(b_sock2.o):b_sock2.c :(文字+ 0x4b4): 未明确引用_imp__WSAGetLastError@0' C:\MyProjects\my-app\libraries\libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x53a): undefined reference to
_ imp__bind @ 12&#39; C:\ MyProjects下\我的应用程序内\库\ libcrypto.a(b_sock2.o):b_sock2.c :(文字+ 0x55f): 未明确引用_imp__listen@8' C:\MyProjects\my-app\libraries\libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x5a5): undefined reference to
_ imp__setsockopt @ 20&#39; C:\ MyProjects下\我的应用程序内\库\ libcrypto.a(b_sock2.o):b_sock2.c :(文字+ 0x5b6): 未明确引用_imp__WSAGetLastError@0' C:\MyProjects\my-app\libraries\libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x63a): undefined reference to
_ imp__setsockopt @ 20&#39; C:\ MyProjects下\我的应用程序内\库\ libcrypto.a(b_sock2.o):b_sock2.c :(文字+ 0x64b): 未定义引用_imp__WSAGetLastError@0' C:\MyProjects\my-app\libraries\libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x6b2): undefined reference to
_ imp__WSAGetLastError @ 0&#39; C:\ MyProjects下\我的应用程序内\库\ libcrypto.a(b_sock2.o):b_sock2.c :(文字+ 0x713): 未明确引用_imp__WSAGetLastError@0' C:\MyProjects\my-app\libraries\libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x7a6): undefined reference to
_ imp__accept @ 12&#39; C:\ MyProjects下\我的应用程序内\库\ libcrypto.a(b_sock2.o):b_sock2.c :(文字+ 0x7e7): 未明确引用_imp__WSAGetLastError@0' C:\MyProjects\my-app\libraries\libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x84b): undefined reference to
_ imp__closesocket @ 4&#39; C:\ MyProjects下\我的应用程序内\库\ libcrypto.a(b_sock2.o):b_sock2.c :(文字+ 0x86c): 对_imp__closesocket@4' C:\MyProjects\my-app\libraries\libcrypto.a(bss_sock.o):bss_sock.c:(.text+0x1b1): undefined reference to
_ imp__WSASetLastError @ 4&#39;的未定义引用 C:\ MyProjects下\我的应用程序内\库\ libcrypto.a(bss_sock.o):bss_sock.c :(文字+ 0x1d0): 未定义引用_imp__send@16' C:\MyProjects\my-app\libraries\libcrypto.a(bss_sock.o):bss_sock.c:(.text+0x20a): undefined reference to
_ imp__WSAGetLastError @ 0&#39; C:\ MyProjects下\我的应用程序内\库\ libcrypto.a(bss_sock.o):bss_sock.c :(文字+ 0x272): 未明确引用_imp__WSASetLastError@4' C:\MyProjects\my-app\libraries\libcrypto.a(bss_sock.o):bss_sock.c:(.text+0x299): undefined reference to
_ imp__send @ 16&#39; C:\ MyProjects下\我的应用程序内\库\ libcrypto.a(bss_sock.o):bss_sock.c :(文字+ 0x2ca): 对_imp__WSAGetLastError@0' C:\MyProjects\my-app\libraries\libcrypto.a(bss_sock.o):bss_sock.c:(.text+0x33d): undefined reference to
_ imp__WSASetLastError @ 4&#39;的未定义引用 C:\ MyProjects下\我的应用程序内\库\ libcrypto.a(bss_sock.o):bss_sock.c :(文字+ 0x360的): 未定义引用_imp__recv@16' C:\MyProjects\my-app\libraries\libcrypto.a(bss_sock.o):bss_sock.c:(.text+0x39a): undefined reference to
_ imp__WSAGetLastError @ 0&#39; C:\ MyProjects下\我的应用程序内\库\ libcrypto.a(bss_sock.o):bss_sock.c :(文字+ 0x457): 未明确引用_imp__WSAGetLastError@0' c:/programs/mingw_w64_mingw32_gcc_stdthread_win32/bin/../lib/gcc/i686-w64-mingw32/4.8.1/../../../../i686-w64-mingw32/bin/ld.exe: C:\MyProjects\my-app\libraries\libcrypto.a(bss_sock.o): bad reloc address 0x24 in section
。rdata&#39; C:/程序/ mingw_w64_mingw32_gcc_stdthread_win32 / bin中/../ lib中/ GCC / i686的-W64-的mingw32 / 4.8.1 /../../../../的i686-W64-mingw32的/ bin中/ ld.exe: 最后一个链接失败:无效的操作collect2.exe:错误:ld返回 1退出状态11:58:21建成(耗时11s.567ms)
我只需要将已完成的C ++项目与正确编译的(带有标记no-async
)OpenSSL库链接起来,让它在旧版本的Windows下运行。
我很乐意在这个问题上得到任何帮助。
答案 0 :(得分:1)
错误日志中的大多数(如果不是全部)未定义的符号都来自Winsock。尝试与-lws2_32
进行关联。