无法使用mingw构建sqlcipher

时间:2013-08-12 01:15:26

标签: linker openssl mingw sqlcipher

我在将OpenSSL链接到SqlCipher时遇到问题,在编译简单的OpenSSL演示时,看起来每个东西都设置正确:

gcc  -Wall -o ssl-demo testssl.c -lssl -lcrypto -lwsock32 -lgdi32

但是当谈到sqlcipher时,我收到了这条消息:

configure: Release set to 3.7.17
configure: Version number set to 3007017
checking whether to support threadsafe operation... yes
checking for library containing pthread_create... -lpthread
checking for crypto library to use... openssl
checking for HMAC_Init_ex in -lcrypto... no
configure: error: Library crypto not found. Install openssl!"

查看configure.log

configure:10593: checking for crypto library to use
configure:10660: result: openssl
configure:10662: checking for HMAC_Init_ex in -lcrypto
configure:10687: gcc -o conftest.exe -DSQLITE_HAS_CODEC -DSQLCIPHER_CRYPTO_OPENSSL  -lgdi32 -lssl -lcrypto conftest.c -lcrypto  -lpthread  >&5
k:/qt/qt4.8.3/mingw/bin/../lib/gcc/mingw32/4.4.0/../../../libcrypto.a(rand_win.o):rand_win.c:(.text+0xa0c): undefined reference to `CreateDCA@16'
k:/qt/qt4.8.3/mingw/bin/../lib/gcc/mingw32/4.4.0/../../../libcrypto.a(rand_win.o):rand_win.c:(.text+0xa19): undefined reference to `CreateCompatibleDC@4'
k:/qt/qt4.8.3/mingw/bin/../lib/gcc/mingw32/4.4.0/../../../libcrypto.a(rand_win.o):rand_win.c:(.text+0xa2a): undefined reference to `GetDeviceCaps@8'
k:/qt/qt4.8.3/mingw/bin/../lib/gcc/mingw32/4.4.0/../../../libcrypto.a(rand_win.o):rand_win.c:(.text+0xa3a): undefined reference to `GetDeviceCaps@8'
k:/qt/qt4.8.3/mingw/bin/../lib/gcc/mingw32/4.4.0/../../../libcrypto.a(rand_win.o):rand_win.c:(.text+0xa50): undefined reference to `CreateCompatibleBitmap@12'
k:/qt/qt4.8.3/mingw/bin/../lib/gcc/mingw32/4.4.0/../../../libcrypto.a(rand_win.o):rand_win.c:(.text+0xa5e): undefined reference to `SelectObject@8'
k:/qt/qt4.8.3/mingw/bin/../lib/gcc/mingw32/4.4.0/../../../libcrypto.a(rand_win.o):rand_win.c:(.text+0xa70): undefined reference to `GetObjectA@12'
k:/qt/qt4.8.3/mingw/bin/../lib/gcc/mingw32/4.4.0/../../../libcrypto.a(rand_win.o):rand_win.c:(.text+0xae1): undefined reference to `BitBlt@36'
k:/qt/qt4.8.3/mingw/bin/../lib/gcc/mingw32/4.4.0/../../../libcrypto.a(rand_win.o):rand_win.c:(.text+0xaeb): undefined reference to `GetBitmapBits@12'
k:/qt/qt4.8.3/mingw/bin/../lib/gcc/mingw32/4.4.0/../../../libcrypto.a(rand_win.o):rand_win.c:(.text+0xb42): undefined reference to `SelectObject@8'
k:/qt/qt4.8.3/mingw/bin/../lib/gcc/mingw32/4.4.0/../../../libcrypto.a(rand_win.o):rand_win.c:(.text+0xb49): undefined reference to `DeleteObject@4'
k:/qt/qt4.8.3/mingw/bin/../lib/gcc/mingw32/4.4.0/../../../libcrypto.a(rand_win.o):rand_win.c:(.text+0xb53): undefined reference to `DeleteDC@4'
k:/qt/qt4.8.3/mingw/bin/../lib/gcc/mingw32/4.4.0/../../../libcrypto.a(rand_win.o):rand_win.c:(.text+0xb5d): undefined reference to `DeleteDC@4'
collect2: ld returned 1 exit status
configure:10687: $? = 1
configure: failed program was:
| /* confdefs.h */
| #define PACKAGE_NAME "sqlcipher"
| #define PACKAGE_TARNAME "sqlcipher"
| #define PACKAGE_VERSION "3.7.17"
| #define PACKAGE_STRING "sqlcipher 3.7.17"
| #define PACKAGE_BUGREPORT ""
| #define PACKAGE_URL ""
| /* end confdefs.h.  */
| #ifdef __cplusplus
| extern "C"
| #endif
| char HMAC_Init_ex ();
| int
| main ()
| {
| return HMAC_Init_ex ();
|   ;
|   return 0;
| }
configure:10696: result: no
configure:10706: error: Library crypto not found. Install openssl!"

用于编译SqlCipher的命令:

$ ./configure --enable-static=no --enable-tempstore=yes CFLAGS="-DSQLITE_HAS_CODEC" LDFLAGS="-lgdi32 -lssl -lcrypto"

我也试图改变链接的顺序,但这没有帮助。

2 个答案:

答案 0 :(得分:0)

看来configure无法找到您的libcrypto版本。您可以尝试调整配置中的LDFLAGS以包含-L/some/path/to/your/library

答案 1 :(得分:0)

  

configure:10687:gcc -o conftest.exe -DSQLITE_HAS_CODEC -DSQLCIPHER_CRYPTO_OPENSSL -lgdi32 -lssl -lcrypto conftest.c -lcrypto -lpthread>& 5

正如您所看到的,-lgdi32在第二个-lcrypto之前发现,它需要追踪。要强制执行此操作,您必须在配置中添加LIBS="-lgdi32"

如果您想深入了解,请参阅./configure第10668行(3.7.17版)。