Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQLCipher doesn't work on windows #177

Open
elvinasn opened this issue Aug 18, 2023 · 14 comments
Open

SQLCipher doesn't work on windows #177

elvinasn opened this issue Aug 18, 2023 · 14 comments

Comments

@elvinasn
Copy link

When trying to use sqlcipher_flutter_libs package with sqlite3 and drift on windows, the build fails. Android, iOS and macOS are working. On windows I get the following errors:

libcrypto64MDd.lib(libcrypto-lib-e_capi.obj) : error LNK2019: unresolved external symbol __imp_CertOpenStore referenced in function capi_open_store [C:\Users\elviz\OneDrive\Desktop\New folder (2)\app\build\windows\plugins\sqlcipher_flutter_libs\sqlite3.vcxproj] libcrypto64MDd.lib(libcrypto-lib-e_capi.obj) : error LNK2019: unresolved external symbol __imp_CertCloseStore referenced in function capi_find_key [C:\Users\elviz\OneDrive\Desktop\New folder (2)\app\build\windows\plugins\sqlcipher_flutter_libs\sqlite3.vcxproj] libcrypto64MDd.lib(libcrypto-lib-e_capi.obj) : error LNK2019: unresolved external symbol __imp_CertEnumCertificatesInStore referenced in function capi_find_cert [C:\Users\elviz\OneDrive\Desktop\New folder (2)\app\build\windows\plugins\sqlcipher_flutter_libs\sqlite3.vcxproj] libcrypto64MDd.lib(libcrypto-lib-e_capi.obj) : error LNK2019: unresolved external symbol __imp_CertFindCertificateInStore referenced in function capi_find_cert [C:\Users\elviz\OneDrive\Desktop\New folder (2)\app\build\windows\plugins\sqlcipher_flutter_libs\sqlite3.vcxproj] libcrypto64MDd.lib(libcrypto-lib-e_capi.obj) : error LNK2019: unresolved external symbol __imp_CertDuplicateCertificateContext referenced in function capi_load_ssl_client_cert [C:\Users\elviz\OneDrive\Desktop\New folder (2)\app\build\windows\plugins\sqlcipher_flutter_libs\sqlite3.vcxproj] libcrypto64MDd.lib(libcrypto-lib-e_capi.obj) : error LNK2019: unresolved external symbol __imp_CertFreeCertificateContext referenced in function capi_find_key [C:\Users\elviz\OneDrive\Desktop\New folder (2)\app\build\windows\plugins\sqlcipher_flutter_libs\sqlite3.vcxproj] libcrypto64MDd.lib(libcrypto-lib-e_capi.obj) : error LNK2019: unresolved external symbol __imp_CertGetCertificateContextProperty referenced in function capi_cert_get_fname [C:\Users\elviz\OneDrive\Desktop\New folder (2)\app\build\windows\plugins\sqlcipher_flutter_libs\sqlite3.vcxproj] libcrypto64MDd.lib(libcrypto-lib-bio_sock.obj) : error LNK2019: unresolved external symbol __imp_ioctlsocket referenced in function BIO_socket_ioctl [C:\Users\elviz\OneDrive\Desktop\New folder (2)\app\build\windows\plugins\sqlcipher_flutter_libs\sqlite3.vcxproj] libcrypto64MDd.lib(libcrypto-lib-bio_sock.obj) : error LNK2019: unresolved external symbol __imp_getsockname referenced in function BIO_sock_info [C:\Users\elviz\OneDrive\Desktop\New folder (2)\app\build\windows\plugins\sqlcipher_flutter_libs\sqlite3.vcxproj] libcrypto64MDd.lib(libcrypto-lib-bio_sock.obj) : error LNK2019: unresolved external symbol __imp_getsockopt referenced in function BIO_sock_error [C:\Users\elviz\OneDrive\Desktop\New folder (2)\app\build\windows\plugins\sqlcipher_flutter_libs\sqlite3.vcxproj] libcrypto64MDd.lib(libcrypto-lib-bio_sock2.obj) : error LNK2001: unresolved external symbol __imp_getsockopt [C:\Users\elviz\OneDrive\Desktop\New folder (2)\app\build\windows\plugins\sqlcipher_flutter_libs\sqlite3.vcxproj] libcrypto64MDd.lib(libcrypto-lib-bio_sock.obj) : error LNK2019: unresolved external symbol __imp_ntohs referenced in function BIO_get_port [C:\Users\elviz\OneDrive\Desktop\New folder (2)\app\build\windows\plugins\sqlcipher_flutter_libs\sqlite3.vcxproj] libcrypto64MDd.lib(libcrypto-lib-bio_addr.obj) : error LNK2001: unresolved external symbol __imp_ntohs [C:\Users\elviz\OneDrive\Desktop\New folder (2)\app\build\windows\plugins\sqlcipher_flutter_libs\sqlite3.vcxproj] libcrypto64MDd.lib(libcrypto-lib-bio_sock.obj) : error LNK2019: unresolved external symbol __imp_select referenced in function BIO_socket_wait [C:\Users\elviz\OneDrive\Desktop\New folder (2)\app\build\windows\plugins\sqlcipher_flutter_libs\sqlite3.vcxproj] libcrypto64MDd.lib(libcrypto-lib-bio_sock.obj) : error LNK2019: unresolved external symbol __imp_gethostbyname referenced in function BIO_gethostbyname [C:\Users\elviz\OneDrive\Desktop\New folder (2)\app\build\windows\plugins\sqlcipher_flutter_libs\sqlite3.vcxproj] libcrypto64MDd.lib(libcrypto-lib-bio_addr.obj) : error LNK2001: unresolved external symbol __imp_gethostbyname [C:\Users\elviz\OneDrive\Desktop\New folder (2)\app\build\windows\plugins\sqlcipher_flutter_libs\sqlite3.vcxproj] libcrypto64MDd.lib(libcrypto-lib-bio_sock.obj) : error LNK2019: unresolved external symbol __imp_WSAStartup referenced in function BIO_sock_init [C:\Users\elviz\OneDrive\Desktop\New folder (2)\app\build\windows\plugins\sqlcipher_flutter_libs\sqlite3.vcxproj] libcrypto64MDd.lib(libcrypto-lib-bio_sock.obj) : error LNK2019: unresolved external symbol __imp_WSACleanup referenced in function bio_sock_cleanup_int [C:\Users\elviz\OneDrive\Desktop\New folder (2)\app\build\windows\plugins\sqlcipher_flutter_libs\sqlite3.vcxproj] libcrypto64MDd.lib(libcrypto-lib-bss_conn.obj) : error LNK2019: unresolved external symbol __imp_WSAGetLastError referenced in function conn_read [C:\Users\elviz\OneDrive\Desktop\New folder (2)\app\build\windows\plugins\sqlcipher_flutter_libs\sqlite3.vcxproj] libcrypto64MDd.lib(libcrypto-lib-bio_sock.obj) : error LNK2001: unresolved external symbol __imp_WSAGetLastError [C:\Users\elviz\OneDrive\Desktop\New folder (2)\app\build\windows\plugins\sqlcipher_flutter_libs\sqlite3.vcxproj] libcrypto64MDd.lib(libcrypto-lib-bio_addr.obj) : error LNK2001: unresolved external symbol __imp_WSAGetLastError [C:\Users\elviz\OneDrive\Desktop\New folder (2)\app\build\windows\plugins\sqlcipher_flutter_libs\sqlite3.vcxproj] libcrypto64MDd.lib(libcrypto-lib-bss_sock.obj) : error LNK2001: unresolved external symbol __imp_WSAGetLastError [C:\Users\elviz\OneDrive\Desktop\New folder (2)\app\build\windows\plugins\sqlcipher_flutter_libs\sqlite3.vcxproj] libcrypto64MDd.lib(libcrypto-lib-bio_sock2.obj) : error LNK2001: unresolved external symbol __imp_WSAGetLastError [C:\Users\elviz\OneDrive\Desktop\New folder (2)\app\build\windows\plugins\sqlcipher_flutter_libs\sqlite3.vcxproj] libcrypto64MDd.lib(libcrypto-lib-bio_addr.obj) : error LNK2019: unresolved external symbol __imp_htonl referenced in function WspiapiLegacyGetAddrInfo [C:\Users\elviz\OneDrive\Desktop\New folder (2)\app\build\windows\plugins\sqlcipher_flutter_libs\sqlite3.vcxproj] libcrypto64MDd.lib(libcrypto-lib-bio_addr.obj) : error LNK2019: unresolved external symbol __imp_htons referenced in function BIO_lookup_ex [C:\Users\elviz\OneDrive\Desktop\New folder (2)\app\build\windows\plugins\sqlcipher_flutter_libs\sqlite3.vcxproj] libcrypto64MDd.lib(libcrypto-lib-bio_addr.obj) : error LNK2019: unresolved external symbol __imp_inet_addr referenced in function WspiapiParseV4Address [C:\Users\elviz\OneDrive\Desktop\New folder (2)\app\build\windows\plugins\sqlcipher_flutter_libs\sqlite3.vcxproj] libcrypto64MDd.lib(libcrypto-lib-bio_addr.obj) : error LNK2019: unresolved external symbol __imp_inet_ntoa referenced in function WspiapiLegacyGetAddrInfo [C:\Users\elviz\OneDrive\Desktop\New folder (2)\app\build\windows\plugins\sqlcipher_flutter_libs\sqlite3.vcxproj] libcrypto64MDd.lib(libcrypto-lib-bio_addr.obj) : error LNK2019: unresolved external symbol __imp_gethostbyaddr referenced in function WspiapiLegacyGetNameInfo [C:\Users\elviz\OneDrive\Desktop\New folder (2)\app\build\windows\plugins\sqlcipher_flutter_libs\sqlite3.vcxproj] libcrypto64MDd.lib(libcrypto-lib-bio_addr.obj) : error LNK2019: unresolved external symbol __imp_getservbyport referenced in function WspiapiLegacyGetNameInfo [C:\Users\elviz\OneDrive\Desktop\New folder (2)\app\build\windows\plugins\sqlcipher_flutter_libs\sqlite3.vcxproj] libcrypto64MDd.lib(libcrypto-lib-bio_addr.obj) : error LNK2019: unresolved external symbol __imp_getservbyname referenced in function BIO_lookup_ex [C:\Users\elviz\OneDrive\Desktop\New folder (2)\app\build\windows\plugins\sqlcipher_flutter_libs\sqlite3.vcxproj] libcrypto64MDd.lib(libcrypto-lib-bio_addr.obj) : error LNK2019: unresolved external symbol __imp_WSASetLastError referenced in function WspiapiGetAddrInfo [C:\Users\elviz\OneDrive\Desktop\New folder (2)\app\build\windows\plugins\sqlcipher_flutter_libs\sqlite3.vcxproj] libcrypto64MDd.lib(libcrypto-lib-bss_sock.obj) : error LNK2001: unresolved external symbol __imp_WSASetLastError [C:\Users\elviz\OneDrive\Desktop\New folder (2)\app\build\windows\plugins\sqlcipher_flutter_libs\sqlite3.vcxproj] libcrypto64MDd.lib(libcrypto-lib-bss_conn.obj) : error LNK2001: unresolved external symbol __imp_WSASetLastError [C:\Users\elviz\OneDrive\Desktop\New folder (2)\app\build\windows\plugins\sqlcipher_flutter_libs\sqlite3.vcxproj] libcrypto64MDd.lib(libcrypto-lib-bss_sock.obj) : error LNK2019: unresolved external symbol __imp_recv referenced in function sock_read [C:\Users\elviz\OneDrive\Desktop\New folder (2)\app\build\windows\plugins\sqlcipher_flutter_libs\sqlite3.vcxproj] libcrypto64MDd.lib(libcrypto-lib-bss_conn.obj) : error LNK2001: unresolved external symbol __imp_recv [C:\Users\elviz\OneDrive\Desktop\New folder (2)\app\build\windows\plugins\sqlcipher_flutter_libs\sqlite3.vcxproj] libcrypto64MDd.lib(libcrypto-lib-bss_sock.obj) : error LNK2019: unresolved external symbol __imp_send referenced in function sock_write [C:\Users\elviz\OneDrive\Desktop\New folder (2)\app\build\windows\plugins\sqlcipher_flutter_libs\sqlite3.vcxproj] libcrypto64MDd.lib(libcrypto-lib-bss_conn.obj) : error LNK2001: unresolved external symbol __imp_send [C:\Users\elviz\OneDrive\Desktop\New folder (2)\app\build\windows\plugins\sqlcipher_flutter_libs\sqlite3.vcxproj] libcrypto64MDd.lib(libcrypto-lib-bio_sock2.obj) : error LNK2019: unresolved external symbol __imp_accept referenced in function BIO_accept_ex [C:\Users\elviz\OneDrive\Desktop\New folder (2)\app\build\windows\plugins\sqlcipher_flutter_libs\sqlite3.vcxproj] libcrypto64MDd.lib(libcrypto-lib-bio_sock2.obj) : error LNK2019: unresolved external symbol __imp_bind referenced in function BIO_bind [C:\Users\elviz\OneDrive\Desktop\New folder (2)\app\build\windows\plugins\sqlcipher_flutter_libs\sqlite3.vcxproj] libcrypto64MDd.lib(libcrypto-lib-bio_sock2.obj) : error LNK2019: unresolved external symbol __imp_closesocket referenced in function BIO_accept_ex [C:\Users\elviz\OneDrive\Desktop\New folder (2)\app\build\windows\plugins\sqlcipher_flutter_libs\sqlite3.vcxproj] libcrypto64MDd.lib(libcrypto-lib-bio_sock2.obj) : error LNK2019: unresolved external symbol __imp_connect referenced in function BIO_connect [C:\Users\elviz\OneDrive\Desktop\New folder (2)\app\build\windows\plugins\sqlcipher_flutter_libs\sqlite3.vcxproj] libcrypto64MDd.lib(libcrypto-lib-bio_sock2.obj) : error LNK2019: unresolved external symbol __imp_listen referenced in function BIO_listen [C:\Users\elviz\OneDrive\Desktop\New folder (2)\app\build\windows\plugins\sqlcipher_flutter_libs\sqlite3.vcxproj] libcrypto64MDd.lib(libcrypto-lib-bio_sock2.obj) : error LNK2019: unresolved external symbol __imp_setsockopt referenced in function BIO_connect [C:\Users\elviz\OneDrive\Desktop\New folder (2)\app\build\windows\plugins\sqlcipher_flutter_libs\sqlite3.vcxproj] libcrypto64MDd.lib(libcrypto-lib-bio_sock2.obj) : error LNK2019: unresolved external symbol __imp_socket referenced in function BIO_socket [C:\Users\elviz\OneDrive\Desktop\New folder (2)\app\build\windows\plugins\sqlcipher_flutter_libs\sqlite3.vcxproj] libcrypto64MDd.lib(libcrypto-lib-bss_conn.obj) : error LNK2019: unresolved external symbol __imp_shutdown referenced in function conn_close_socket [C:\Users\elviz\OneDrive\Desktop\New folder (2)\app\build\windows\plugins\sqlcipher_flutter_libs\sqlite3.vcxproj] C:\Users\elviz\OneDrive\Desktop\New folder (2)\app\build\windows\plugins\sqlcipher_flutter_libs\Debug\sqlite3.dll : fatal error LNK1120: 34 unresolved externals [C:\Users\elviz\OneDrive\Desktop\New folder (2)\app\build\windows\plugins\sqlcipher_flutter_libs\sqlite3.vcxproj] Exception: Build process failed.

@simolus3
Copy link
Owner

It looks like statically linking OpenSSL fails. Did you install OpenSSL development libraries on your Windows build machine? I'll also take another look at this, but it will take a few days until I have access to a Windows VM again.

@elvinasn
Copy link
Author

Yes, I did.

openssl version
OpenSSL 3.1.1 30 May 2023 (Library: OpenSSL 3.1.1 30 May 2023)

@elvinasn
Copy link
Author

elvinasn commented Aug 21, 2023

I fixed this by adding following lines into ./windows/CMakeLists.txt

include_directories("C:\\Program Files\\OpenSSL-Win64\\include")
link_directories("C:\\Program Files\\OpenSSL-Win64\\lib")
link_libraries(libssl libcrypto)

@simolus3
Copy link
Owner

Did you install OpenSSL manually or through a package manager like Chocolatey? I think there's a way to add OpenSSL to PATH so that it gets found by CMake by default.

@elvinasn
Copy link
Author

I installed it through choco, and it was added to PATH automatically.

@vannakmini
Copy link

vannakmini commented Feb 28, 2024

CMake Error at C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.25/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the
system variable OPENSSL_ROOT_DIR (missing: OPENSSL_CRYPTO_LIBRARY
OPENSSL_INCLUDE_DIR)
Call Stack (most recent call first):
C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.25/Modules/FindPackageHandleStandardArgs.cmake:600 (_FPHSA_FAILURE_MESSAGE)
C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.25/Modules/FindOpenSSL.cmake:613 (find_package_handle_standard_args)
flutter/ephemeral/.plugin_symlinks/sqlcipher_flutter_libs/windows/CMakeLists.txt:27 (find_package)

Error: Unable to generate build files

may i know how to fix it i have ready install openssl

@saadinstitute
Copy link

I have the same issue, it keep tell me the following:

CMake Error at C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.28/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
  Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the
  system variable OPENSSL_ROOT_DIR (missing: OPENSSL_CRYPTO_LIBRARY) (found
  version "3.3.0")
Call Stack (most recent call first):
  C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.28/Modules/FindPackageHandleStandardArgs.cmake:600 (_FPHSA_FAILURE_MESSAGE)     
  C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.28/Modules/FindOpenSSL.cmake:668 (find_package_handle_standard_args)
  flutter/ephemeral/.plugin_symlinks/sqlcipher_flutter_libs/windows/CMakeLists.txt:27 (find_package)

I have openssl already been installed.

How can I resolve this issue?

@velten-dev
Copy link

@simolus3 I am seeing the same issue as @saadinstitute with a fresh install of Windows 10. I used chocolatey to install the SSL libs, but it seems that CMAKE can't find it. I tried setting an environment variable for the OPENSSL_ROOT_DIR in the user env, the system env, and setting a variable with that name in the windows CMAKE file. I also tried uninstalling VS2022 for VS2019 as I remember seeing a warning about VS2022 not being supported.

I am unfortunately not that familiar with how to resolve an issue like this, especially from windows. Most of the help you find online assume Linux for a CMAKE issue. I verified a non-encrypted Drift project does compile on the system. Any suggestions on other tests to make or configuration to change to let if find the SSL libraries?

@awaters-meltin
Copy link

awaters-meltin commented Jun 3, 2024

I had the same problem (Windows 11) - after some digging it appears to be an issue with latest Chocolatey OpenSSL versions (from 3.2+).

If you install version 3.1.1 that works:

choco install openssl --version 3.1.1 -y

@anisalibegic
Copy link

anisalibegic commented Jun 16, 2024

I managed it to work by adding what @elvinasn said AND by adding sqlcipher_library_windows package.

@simolus3 Is this some weird workaround or it's intended to work this way? I feel like I'm "cheating" but @elvinasn's comment fixed those linking errors and sqlcipher_library_windows fixed an error where sqlcipher.dll was not found. I'm also using OpenSSL 3.3.1 installed via Chocolatey.

@simolus3
Copy link
Owner

Sorry, I'm not very familiar with Windows development. I think that CMake should be able to find OpenSSL when installed through Chocolatey, at least it behaved like that in my VM. But I also don't know what could cause that to break.

Obviously the solution isn't great, but if it works and the compiled app also runs on other Windows machines without the workaround, I don't see any potential for this to go wrong or be compiled/linked in a broken way.

@anisalibegic
Copy link

Sorry, I'm not very familiar with Windows development. I think that CMake should be able to find OpenSSL when installed through Chocolatey, at least it behaved like that in my VM. But I also don't know what could cause that to break.

Obviously the solution isn't great, but if it works and the compiled app also runs on other Windows machines without the workaround, I don't see any potential for this to go wrong or be compiled/linked in a broken way.

I went through sqlcipher_library_windows and I see that it's keeping required DLLs in it's assets folder, and it copies them manually to the same place where executable is generated.

Do you think it would be better to create a separated plugin for Windows platform only, where we can write a POST BUILD script that will copy all DLLs where binary is generated? With this approach we don't need to copy DLLs on other platforms since they don't need them. I can definitely do that since it's more lightweight than the mentioned package, which helps in this case.

@Unbreathable
Copy link

Hello, I just ran into the exact same issue and I keep getting this error:

[ +864 ms] CMake Error at flutter/ephemeral/.plugin_symlinks/sqlcipher_flutter_libs/windows/CMakeLists.txt:36 (target_link_libraries):
[        ]   Target "sqlite3" links to:
[        ]     OpenSSL::Crypto
[        ]   but the target was not found.  Possible reasons include:
[        ]     * There is a typo in the target name.
[        ]     * A find_package call is missing for an IMPORTED target.
[        ]     * An ALIAS target is missing.

I installed OpenSSL just normally using chocolatey and have the newest version currently available on there (3.3.1). I've tried the fixes people suggested in here and nothing seemed to be working. Are there other things you guys did to fix this? I would really appreciate some help. Thanks!

@zhanchen18
Copy link

Is there any progress on this issue? This will affect whether I continue to use.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants