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

OpenSSL x86-windows-static not working with find_package(OpenSSL REQUIRED) #12001

Closed
67-al-ahad opened this issue Jun 18, 2020 · 18 comments
Closed
Assignees
Labels
category:community-triplet A PR or issue related to community triplets not officially validated by the vcpkg team. category:port-bug The issue is with a library, which is something the port should already support

Comments

@67-al-ahad
Copy link

67-al-ahad commented Jun 18, 2020

Describe the bug
A basic openssl project is not able to be generated and compiled due to the lack of vcpkg to find the library paths.

Environment

  • OS: Win 10
  • Compiler: MSVC++ 2019

To Reproduce
Steps to reproduce the behavior:

  1. ./vcpkg install openssl:x86-windows-static-md
  2. OPENSSL_ROOT_DIR is not detected automatically

Expected behavior
The generation should be without any problem

Failure logs

Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the
 system variable OPENSSL_ROOT_DIR (missing: OPENSSL_LIBRARIES)

Additional context
It is working well when we are installing openssl:x86-windows version of the library. But as soon as we don't want to use the DLL version instead openssl:x86-windows-static-md then nothing works anymore.

helloworld.zip

@67-al-ahad 67-al-ahad changed the title OpenSSL x86-windows-static-md not working find_package(OpenSSL REQUIRED) OpenSSL x86-windows-static-md not working with find_package(OpenSSL REQUIRED) Jun 18, 2020
@JackBoosY
Copy link
Contributor

See documentation.

@67-al-ahad
Copy link
Author

67-al-ahad commented Jun 18, 2020

Ok although I set the correct triplets in CMakeSettings.json

{
  "configurations": [
    {
      "name": "x86-Debug",
      "generator": "Ninja",
      "configurationType": "Debug",
      "buildRoot": "${projectDir}\\out\\build\\${name}",
      "installRoot": "${projectDir}\\out\\install\\${name}",
      "cmakeCommandArgs": "-DVCPKG_TARGET_TRIPLET=x86-windows-static",
      "buildCommandArgs": "",
      "ctestCommandArgs": "",
      "inheritEnvironments": [ "msvc_x86" ],
      "variables": [],
      "cmakeToolchain": "C:\\vcpkg\\scripts\\buildsystems\\vcpkg.cmake"
    },
    {
      "name": "x86-Release",
      "generator": "Ninja",
      "configurationType": "RelWithDebInfo",
      "buildRoot": "${projectDir}\\out\\build\\${name}",
      "installRoot": "${projectDir}\\out\\install\\${name}",
      "cmakeCommandArgs": "-DVCPKG_TARGET_TRIPLET=x86-windows-static",
      "buildCommandArgs": "",
      "ctestCommandArgs": "",
      "inheritEnvironments": [ "msvc_x86" ],
      "variables": [],
      "cmakeToolchain": "C:\\vcpkg\\scripts\\buildsystems\\vcpkg.cmake"
    }
  ]
}

I still get this error

[1/1] Linking CXX executable MonaTiny\MonaTiny.exe
  FAILED: MonaTiny/MonaTiny.exe 
  cmd.exe /C "cd . && "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E vs_link_exe --intdir=MonaTiny\CMakeFiles\MonaTiny.dir --rc=C:\PROGRA~2\WI3CF2~1\10\bin\100183~1.0\x86\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\10\bin\100183~1.0\x86\mt.exe --manifests  -- C:\PROGRA~2\MICROS~1\2019\COMMUN~1\VC\Tools\MSVC\1426~1.288\bin\Hostx86\x86\link.exe /nologo MonaTiny\CMakeFiles\MonaTiny.dir\sources\MonaTiny.cpp.obj MonaTiny\CMakeFiles\MonaTiny.dir\sources\main.cpp.obj  /out:MonaTiny\MonaTiny.exe /implib:MonaTiny\MonaTiny.lib /pdb:MonaTiny\MonaTiny.pdb /version:0.0  /machine:X86 /debug /INCREMENTAL /subsystem:console  MonaBase\MonaBased.lib  MonaCore\MonaCored.lib  C:\vcpkg\installed\x86-windows-static\debug\lib\libssl.lib  C:\vcpkg\installed\x86-windows-static\debug\lib\libcrypto.lib  MonaBase\MonaBased.lib  C:\vcpkg\installed\x86-windows-static\debug\lib\libssl.lib  C:\vcpkg\installed\x86-windows-static\debug\lib\libcrypto.lib  C:\vcpkg\installed\x86-windows-static\debug\lib\libssl.lib  C:\vcpkg\installed\x86-windows-static\debug\lib\libcrypto.lib  kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib && cmd.exe /C "cd /D G:\programming\c++\Mona\67-al-ahad\out\build\x86-Debug\MonaTiny && powershell -noprofile -executionpolicy Bypass -file C:/vcpkg/scripts/buildsystems/msbuild/applocal.ps1 -targetBinary G:/programming/c++/Mona/67-al-ahad/out/build/x86-Debug/MonaTiny/MonaTiny.exe -installedDir C:/vcpkg/installed/x86-windows-static/debug/bin -OutVariable out""
  LINK Pass 1: command "C:\PROGRA~2\MICROS~1\2019\COMMUN~1\VC\Tools\MSVC\1426~1.288\bin\Hostx86\x86\link.exe /nologo MonaTiny\CMakeFiles\MonaTiny.dir\sources\MonaTiny.cpp.obj MonaTiny\CMakeFiles\MonaTiny.dir\sources\main.cpp.obj /out:MonaTiny\MonaTiny.exe /implib:MonaTiny\MonaTiny.lib /pdb:MonaTiny\MonaTiny.pdb /version:0.0 /machine:X86 /debug /INCREMENTAL /subsystem:console MonaBase\MonaBased.lib MonaCore\MonaCored.lib C:\vcpkg\installed\x86-windows-static\debug\lib\libssl.lib C:\vcpkg\installed\x86-windows-static\debug\lib\libcrypto.lib MonaBase\MonaBased.lib C:\vcpkg\installed\x86-windows-static\debug\lib\libssl.lib C:\vcpkg\installed\x86-windows-static\debug\lib\libcrypto.lib C:\vcpkg\installed\x86-windows-static\debug\lib\libssl.lib C:\vcpkg\installed\x86-windows-static\debug\lib\libcrypto.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:MonaTiny\CMakeFiles\MonaTiny.dir/intermediate.manifest MonaTiny\CMakeFiles\MonaTiny.dir/manifest.res" failed (exit code 1104) with the following output:
C:\c++\Mona\67-al-ahad\out\build\x86-Debug\LINK : fatal error LNK1104: cannot open file 'libcryptod.lib'
  ninja: build stopped: subcommand failed.

image

The error is here the file name installed by vcpkg is C:\vcpkg\installed\x86-windows-static\debug\lib\libcrypto.lib and not libcryptod.lib

To me it seems that whom ever built this package forgot to set set(CMAKE_DEBUG_POSTFIX d)

@67-al-ahad
Copy link
Author

What is this error linked to? My code or the OpenSSL port?

@67-al-ahad
Copy link
Author

Any idea what is the problem here ?

@JackBoosY
Copy link
Contributor

@67-al-ahad Can you confirm your vcpkg is latest?
Openssl should generated libeay32.lib and ssleay32.lib.
And the triplet is community rather than official, so we do not provide maintenance for it.

Thanks.

@67-al-ahad
Copy link
Author

67-al-ahad commented Jun 23, 2020

cpkg package management program version 2020.02.04-nohash

See LICENSE.txt for license information.

vcpkg list
openssl-windows:x86-windows-static                 1.1.1d-2         OpenSSL is an open source project that provides ...

You can also see that I added the extra parameter for Visual Studio:

image

Also the debug setting the correct library cannot be found by Visual Studio and vcpkg although it is installed.

image

In the release it seems that it is found but the file name taken into consideration is ending with d which is non-existent.

image

As you can see the library version for debug which is installed is not correct there is the d letter missing in the files name.

image

For the release version everything seems to be fine.

image

@67-al-ahad 67-al-ahad changed the title OpenSSL x86-windows-static-md not working with find_package(OpenSSL REQUIRED) OpenSSL x86-windows-static not working with find_package(OpenSSL REQUIRED) Jun 23, 2020
@67-al-ahad
Copy link
Author

When I copy the 2 files and add the d letter at the end and click the Save and generate CMake cache to load variables, Visual Studio seems to be able to now recognize the correct files.

image

@67-al-ahad
Copy link
Author

67-al-ahad commented Jun 23, 2020

I added the explanation for this bug and the workaround here:

https://github.com/67-al-ahad/MonaServer2#openssl-library-bug-with-vcpkg-and-visual-studio

@Septarius
Copy link
Contributor

Septarius commented Jun 26, 2020

The old OpenSSL packages for < 1.1.0 (ssleay32 and libeay32) might have had a "d" suffix or at least I could find hints at that. It appears that they removed that for 1.1+ when the name was changed to libcrypto and libssl. I would suggest removing the _DEBUG pragma in your header file. That should clear your problem up.

Release

Directory: C:\Users\packages\vcpkg\installed\x86-windows\lib

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----         6/25/2020   8:27 PM        1014802 libcrypto.lib
-a----         6/25/2020   8:27 PM         122290 libssl.lib

 Directory: C:\Users\packages\vcpkg\installed\x86-windows-static\lib


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----         6/26/2020  12:44 AM       17505988 libcrypto.lib
-a----         6/26/2020  12:44 AM        3570946 libssl.lib
-a----         6/26/2020  12:44 AM        1069056 ossl_static.pdb

Debug

Directory: C:\Users\packages\vcpkg\installed\x86-windows\debug\lib

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----         6/25/2020   8:28 PM        1014802 libcrypto.lib
-a----         6/25/2020   8:28 PM         122290 libssl.lib

Directory: C:\Users\packages\vcpkg\installed\x86-windows-static\debug\lib

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----         6/26/2020  12:45 AM       14386074 libcrypto.lib
-a----         6/26/2020  12:45 AM        2916922 libssl.lib
-a----         6/26/2020  12:45 AM        1069056 ossl_static.pdb

@67-al-ahad
Copy link
Author

67-al-ahad commented Jun 27, 2020

I am using vcpkg, CMake and Visual Studio 2019 are you talking about this : https://stackoverflow.com/questions/4604283/automatic-defines-according-to-debug-release-config-in-visual-studio

or are you talking about this:

#if defined(_MSC_VER)
// disable the "throw noexception" warning because Mona has its own exception and can use everywhere std throw on FATAL problem (unexpected behavior)
#pragma warning(disable: 4297)
#pragma warning(disable: 4267)
#pragma warning(disable: 4244)
#pragma warning(disable: 4800)

#pragma comment(lib, "crypt32.lib")
#if defined(_DEBUG)
#pragma comment(lib, "libcryptod.lib")
#pragma comment(lib, "libssld.lib")
#else
#pragma comment(lib, "libcrypto.lib")
#pragma comment(lib, "libssl.lib")
#endif

#endif

@Septarius
Copy link
Contributor

Yeah the last one

#if defined(_DEBUG)
#pragma comment(lib, "libcryptod.lib")
#pragma comment(lib, "libssld.lib")

I noticed that there was a reference to libcryptod.lib in the header file but it wasn't cooperating at the time to quote it.

@JackBoosY JackBoosY added the category:port-bug The issue is with a library, which is something the port should already support label Jun 28, 2020
@JackBoosY
Copy link
Contributor

JackBoosY commented Jun 28, 2020

@cenit Could you please take a look?
Now, we didn't add the suffix d under debug mode.

Thanks.

@67-al-ahad
Copy link
Author

Yeah the last one

#if defined(_DEBUG)
#pragma comment(lib, "libcryptod.lib")
#pragma comment(lib, "libssld.lib")

I noticed that there was a reference to libcryptod.lib in the header file but it wasn't cooperating at the time to quote it.

Even after removing the d from header I still get this error.

@cenit
Copy link
Contributor

cenit commented Jun 28, 2020

@JackBoosY @67-al-ahad there is a problem with the openssl port on vcpkg, which is independent from 1.1 update. The only culprit of that PR is not having fixed this problem and not even highlighted that.
On windows, as can be seen here
https://github.com/Kitware/CMake/blob/45542049563f0ee8358ead563a4e4cc7d7270110/Modules/FindOpenSSL.cmake#L209-L221
LIB_EAY_DEBUG should have a trailing d. The same is valid for SSL_EAY_DEBUG. Unfortunately, our port does not deal with it. A wrapper might be required, in order to help cmake module finding it properly

another note on #8566 pr: it left many orphaned patches in the OpenSSL port folder...

@JackBoosY JackBoosY self-assigned this Jul 3, 2020
@JackBoosY JackBoosY added the category:community-triplet A PR or issue related to community triplets not officially validated by the vcpkg team. label Nov 3, 2020
@christophe-calmejane
Copy link
Contributor

I'm facing a more critical issue regarding the OpenSSL port:
When generating a cmake solution, only the debug path is found and configured, resulting in the debug version of openSSL being linked then the openSSL DLL being used, which require the debug vc runtime which we are not allowed to distribute.

See the cmake log:

-- Found OpenSSL: D:/dev/vcpkg/installed/x86-windows/debug/lib/libcrypto.lib (found suitable version "1.1.1k", minimum required is "1")

ZLIB for example, correctly sets debug and optimized paths, so cmake knows which one to take based on the current config:

-- Found ZLIB: optimized;D:/dev/vcpkg/installed/x86-windows/lib/zlib.lib;debug;D:/dev/vcpkg/installed/x86-windows/debug/lib/zlibd.lib (found suitable version "1.2.11", minimum required is "1")

Not sure if #21641 is trying to fix this specific issue.

@dg0yt
Copy link
Contributor

dg0yt commented Nov 30, 2021

@christophe-calmejane #21641 is an extension of a test port that I created to verify vcpkg's interaction with CMake's find modules.
An earlier revision of that PR confirmed that something is wrong with OpenSSL when consumed in CMake 3.4.3 (but not in CMake 3.21): https://dev.azure.com/vcpkg/public/_build/results?buildId=63856&view=logs&j=3859ca13-59fe-57bd-13f9-449df7d191a6&t=03b21fcd-db83-5643-e95b-35d3afaab803

I decided to move this to a separate PR (WIP) where I will also update port openssl to hopefully fix the issues.

Related: #21415

Disclaimer: I test MSVC only in vcpkg CI.

@JackBoosY
Copy link
Contributor

Is this issue fixed now?

@Cheney-W
Copy link
Contributor

Thanks for posting this issue. Please reopen this issue if this is still a problem for you.

@Cheney-W Cheney-W closed this as not planned Won't fix, can't repro, duplicate, stale Nov 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category:community-triplet A PR or issue related to community triplets not officially validated by the vcpkg team. category:port-bug The issue is with a library, which is something the port should already support
Projects
None yet
Development

No branches or pull requests

7 participants