xeodou / go-sqlcipher

Golang SQLCipher driver conforming to the built-in database/sql interface and using the latest sqlite3 code.
MIT License
224 stars 52 forks source link

windows10 error #27

Closed sayyoume closed 3 years ago

sayyoume commented 4 years ago

image I set the environment variable. but when i use go install show the error: image How to solve???

sayyoume commented 4 years ago

image the environment variable is the openssl lib and include

xeodou commented 4 years ago

@sayyoume plz take a look at this page https://github.com/xeodou/go-sqlcipher/wiki/Building#issues , it's because of the OpenSSL installed in MingW with different lib name.

navono commented 3 years ago

Followed the actions in the issue and still got the same error.

xeodou commented 3 years ago

Followed the actions in the issue and still got the same error.

What error do you get? Did you follow the instruction here https://github.com/xeodou/go-sqlcipher/wiki/Building#issues

navono commented 3 years ago

Thank you for your response.

Here is my Env:

$ gcc --version
gcc.exe (MinGW-W64 x86_64-posix-seh, built by Brecht Sanders) 10.2.0
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

OS: Win 10(2004) 64bit

Here is the errors:

$ go get github.com/xeodou/go-sqlcipher
# github.com/xeodou/go-sqlcipher
d:/devenv/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible d:/devenv/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../
../../../x86_64-w64-mingw32/lib/../lib/libcrypto.a when searching for -lcrypto
d:/devenv/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible d:/devenv/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../
../../../x86_64-w64-mingw32/lib/../lib\libcrypto.a when searching for -lcrypto
d:/devenv/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible d:/devenv/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../
../../../lib/libcrypto.dll.a when searching for -lcrypto
d:/devenv/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible d:/devenv/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../
../../../x86_64-w64-mingw32/lib/libcrypto.a when searching for -lcrypto
d:/devenv/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible d:/devenv/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../
../../../x86_64-w64-mingw32/lib\libcrypto.a when searching for -lcrypto
d:/devenv/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible d:/devenv/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../
../../libcrypto.dll.a when searching for -lcrypto
d:/devenv/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible d:/devenv/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../
../../../x86_64-w64-mingw32/lib/../lib/libcrypto.a when searching for -lcrypto
d:/devenv/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible d:/devenv/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../
../../../lib/libcrypto.dll.a when searching for -lcrypto
d:/devenv/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible d:/devenv/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../
../../../x86_64-w64-mingw32/lib/libcrypto.a when searching for -lcrypto
d:/devenv/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible d:/devenv/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../
../../libcrypto.dll.a when searching for -lcrypto
d:/devenv/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lcrypto
d:/devenv/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible d:/devenv/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../
../../../x86_64-w64-mingw32/lib/../lib/libcrypto.a when searching for -lcrypto
d:/devenv/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible d:/devenv/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../
../../../lib/libcrypto.dll.a when searching for -lcrypto
d:/devenv/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible d:/devenv/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../
../../../x86_64-w64-mingw32/lib/libcrypto.a when searching for -lcrypto
d:/devenv/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible d:/devenv/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../
../../libcrypto.dll.a when searching for -lcrypto
collect2.exe: error: ld returned 1 exit status
# github.com/xeodou/go-sqlcipher
sqlite3-binding.c: In function 'sqlite3SelectNew':
sqlite3-binding.c:130284:10: warning: function may return address of local variable [-Wreturn-local-addr]
130284 |   return pNew;
       |          ^~~~
sqlite3-binding.c:130244:10: note: declared here
130244 |   Select standin;
       |          ^~~~~~~

It basically follows that steps, but is slightly different because of the OpenSSL version change. I installed the 1.1.1h (x86)version. And I copied lib\MinGW\libcrypto.def and lib\MinGW\libcrypto.dll.a from the OpenSSL installation directory to the mingw64\x86_64-w64-mingw32\lib directory, and renamed libcrypto.dll.a to libcrypto.a; copied the include under OpenSSL to mingw64\x86_64-w64-mingw32\include.

lib

include

Did any of the steps go wrong?

navono commented 3 years ago

The reason for using OpenSSL 32-bit is that there is no lib file for MingW under OpenSSL 64-bit.

navono commented 3 years ago

After put OpenSSL(64 bit)\lib\libcrypto.def and OpenSSL(64 bit)\lib\libcrypto.lib(rename to libcrypto.a) and include\openssl to mingw64 directory, everything works fine.

navono commented 3 years ago

I'm having a strange problem. I was able to get it installed and running on one PC, but on another PC I was experiencing the following error:

# github.com/xeodou/go-sqlcipher
C:\Users\PINGQI~1\AppData\Local\Temp\go-build372864814\b056\_x012.o: In function `sqlcipher_openssl_deactivate':
E:\data\Go\pkg\mod\github.com\xeodou\go-sqlcipher@v0.0.0-20200727080346-d681773ef093/sqlite3-binding.c:24452: undefined reference to `EVP_cleanup'
C:\Users\PINGQI~1\AppData\Local\Temp\go-build372864814\b056\_x012.o: In function `sqlcipher_openssl_activate':
E:\data\Go\pkg\mod\github.com\xeodou\go-sqlcipher@v0.0.0-20200727080346-d681773ef093/sqlite3-binding.c:24423: undefined reference to `OPENSSL_add_all_algorithms_noconf'
C:\Users\PINGQI~1\AppData\Local\Temp\go-build372864814\b056\_x012.o: In function `HMAC_CTX_new':
E:\data\Go\pkg\mod\github.com\xeodou\go-sqlcipher@v0.0.0-20200727080346-d681773ef093/sqlite3-binding.c:24346: undefined reference to `HMAC_CTX_init'
C:\Users\PINGQI~1\AppData\Local\Temp\go-build372864814\b056\_x012.o: In function `HMAC_CTX_free':
E:\data\Go\pkg\mod\github.com\xeodou\go-sqlcipher@v0.0.0-20200727080346-d681773ef093/sqlite3-binding.c:24358: undefined reference to `HMAC_CTX_cleanup'
E:\data\Go\pkg\mod\github.com\xeodou\go-sqlcipher@v0.0.0-20200727080346-d681773ef093/sqlite3-binding.c:24358: undefined reference to `HMAC_CTX_cleanup'
E:\data\Go\pkg\mod\github.com\xeodou\go-sqlcipher@v0.0.0-20200727080346-d681773ef093/sqlite3-binding.c:24358: undefined reference to `HMAC_CTX_cleanup'
collect2.exe: error: ld returned 1 exit status

The installation of OpenSSL version and the system environment variables have been checked on both machines and they are consistent.

mingw64\include\openssl\opensslv.h and mingw64\x86_64-w64-mingw32\include\openssl\opensslv.h

# define OPENSSL_VERSION_NUMBER  0x1010108fL
# define OPENSSL_VERSION_TEXT    "OpenSSL 1.1.1h  22 Sep 2020"

any clue?

xeodou commented 3 years ago

I'm having a strange problem. I was able to get it installed and running on one PC, but on another PC I was experiencing the following error:

# github.com/xeodou/go-sqlcipher
C:\Users\PINGQI~1\AppData\Local\Temp\go-build372864814\b056\_x012.o: In function `sqlcipher_openssl_deactivate':
E:\data\Go\pkg\mod\github.com\xeodou\go-sqlcipher@v0.0.0-20200727080346-d681773ef093/sqlite3-binding.c:24452: undefined reference to `EVP_cleanup'
C:\Users\PINGQI~1\AppData\Local\Temp\go-build372864814\b056\_x012.o: In function `sqlcipher_openssl_activate':
E:\data\Go\pkg\mod\github.com\xeodou\go-sqlcipher@v0.0.0-20200727080346-d681773ef093/sqlite3-binding.c:24423: undefined reference to `OPENSSL_add_all_algorithms_noconf'
C:\Users\PINGQI~1\AppData\Local\Temp\go-build372864814\b056\_x012.o: In function `HMAC_CTX_new':
E:\data\Go\pkg\mod\github.com\xeodou\go-sqlcipher@v0.0.0-20200727080346-d681773ef093/sqlite3-binding.c:24346: undefined reference to `HMAC_CTX_init'
C:\Users\PINGQI~1\AppData\Local\Temp\go-build372864814\b056\_x012.o: In function `HMAC_CTX_free':
E:\data\Go\pkg\mod\github.com\xeodou\go-sqlcipher@v0.0.0-20200727080346-d681773ef093/sqlite3-binding.c:24358: undefined reference to `HMAC_CTX_cleanup'
E:\data\Go\pkg\mod\github.com\xeodou\go-sqlcipher@v0.0.0-20200727080346-d681773ef093/sqlite3-binding.c:24358: undefined reference to `HMAC_CTX_cleanup'
E:\data\Go\pkg\mod\github.com\xeodou\go-sqlcipher@v0.0.0-20200727080346-d681773ef093/sqlite3-binding.c:24358: undefined reference to `HMAC_CTX_cleanup'
collect2.exe: error: ld returned 1 exit status

The installation of OpenSSL version and the system environment variables have been checked on both machines and they are consistent.

mingw64\include\openssl\opensslv.h and mingw64\x86_64-w64-mingw32\include\openssl\opensslv.h

# define OPENSSL_VERSION_NUMBER  0x1010108fL
# define OPENSSL_VERSION_TEXT    "OpenSSL 1.1.1h  22 Sep 2020"

any clue?

This looks like the libcrypto is undefined for the library. Can you double you have the files in the right place? Or you can build the library with the specific OpenSSL library for example,

CGO_ENABLE=1 CGO_LDFLAGS="-L/usr/local/opt/openssl/lib" CGO_CPPFLAGS="-I/usr/local/opt/openssl/include" go build _example/encrypto/encrypto.go

I don't own a Windows laptop anymore. I probably can make a test at the weekend using a virtual machine.

navono commented 3 years ago

@xeodou After going over the OpenSSL headers several times, found several OpenSSL headers in the x86 folder that were not replaced with the x64 version. After replacing them, it works fine. Thanks again!