Raymond Raymond

CMake Build Error - Could not Find OpenSSL on Windows 10

event 2020-07-31 visibility 14,541 comment 19 insights toc
more_vert
insights Stats

Background

When I was building Hadoop 3.3.0 on Windows 10, I hit one error about OpenSSL:

CMake Error at C:/Program Files/CMake/share/cmake-3.18/Modules/FindPackageHandleStandardArgs.cmake:165 (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)

This error was raised by the following line in CMakeLists.txt:

find_package(OpenSSL REQUIRED)

The following is my environment setup:

-- Building for: Visual Studio 16 2019
-- Selecting Windows SDK version 10.0.18362.0 to target Windows 10.0.18363.
-- The C compiler identification is MSVC 19.26.28806.0
-- The CXX compiler identification is MSVC 19.26.28806.0

CMake version

CMake version is 3.18.0.

C:\hdp\cmaketest>cmake --version
cmake version 3.18.0

CMake suite maintained and supported by Kitware (kitware.com/cmake).

Microsoft Visual C++ version

MSVC 19.26.28806.0

OpenSSL version

OpenSSL is installed on Windows using Microsoft vcpkg (a package manager for C++). The version installed in OpenSSL 1.1.18.

C:\hdp\cmaketest>openssl version
OpenSSL 1.1.1g  21 Apr 2020

Reproduce the issue

Follow the steps below can reproduce this issue.

  1. Create project folder C:\hdp\cmaketest
  2. Create file CMakeLists.txt in the project folder with the following content:
    cmake_minimum_required(VERSION 3.10)
    
    # set the project name
    project(Test)
    
    # Find package
    find_package(OpenSSL REQUIRED)
  3. Run CMake command:
    cmake .
    The error will occur as the following screenshot shows:
    2020073102239-image.png

Fix this issue

In my system, OpenSSL is installed via vcpkg and installation folder is: C:/vcpkg/installed/x64-windows-static.

2020073102610-image.png

Thus to fix this issue, I just need to change the command line to the following:

cmake . -DOPENSSL_ROOT_DIR="C:/vcpkg/installed/x64-windows-static"

The above command line tells CMake that OpenSSL root folder is in the above directory. If you OpenSSL is installed with different triplet or location, please update the command line accordingly. 

Reference

CMake: Could NOT find OpenSSL

More from Kontext
comment Comments
Raymond Raymond #1764 access_time 2 years ago more_vert

The command was generated by the following line in the pom.xml file:

https://github.com/apache/hadoop/blob/a3b9c37a397ad4188041dd80621bdeefc46885f2/hadoop-hdfs-project/hadoop-hdfs-native-client/pom.xml#L150

Can you try adding the following argument into your Maven build tool too?

-Dnative_cmake_args="-DOPENSSL_ROOT_DIR=C:/vcpkg/installed/x64-windows-static"

Please change the path to the location where those C++ packages installed in your computer. Under that path, there should include sub folders like bin, lib, shared, etc. 

BTW did you run vcpkg integrate install command?

format_quote

person ziyu access_time 2 years ago

I download vcpkg,and install openssl.but it still got error. And I build with -X,here is the error message:

Execute:Java13CommandLauncher: Executing 'cmake' with arguments:
'C:\code\hadoop-compile\hadoop-hdfs-project\hadoop-hdfs-native-client/src/'
'-DGENERATED_JAVAH=C:\code\hadoop-compile\hadoop-hdfs-project\hadoop-hdfs-native-client\target/native/javah'
'-DJVM_ARCH_DATA_MODEL=64'
'-DHADOOP_BUILD=1'
'-DREQUIRE_FUSE=false'
'-DREQUIRE_VALGRIND=false'
'-A'
'x64'
The ' characters around the executable and arguments are
not part of the command.
     [exec] CMake Warning (dev) in CMakeLists.txt:
     [exec]   No project() command is present.  The top-level CMakeLists.txt file must
     [exec]   contain a li-- Selecting Windows SDK version 10.0.22621.0 to target Windows 10.0.19043.
     [exec] teral, direct call to the project() command.  Add a line of
     [exec]   code such as
     [exec] 
     [exec]     project(ProjectName)
Z ziyu bai #1763 access_time 2 years ago more_vert

I download vcpkg,and install openssl.but it still got error. And I build with -X,here is the error message:

Execute:Java13CommandLauncher: Executing 'cmake' with arguments:
'C:\code\hadoop-compile\hadoop-hdfs-project\hadoop-hdfs-native-client/src/'
'-DGENERATED_JAVAH=C:\code\hadoop-compile\hadoop-hdfs-project\hadoop-hdfs-native-client\target/native/javah'
'-DJVM_ARCH_DATA_MODEL=64'
'-DHADOOP_BUILD=1'
'-DREQUIRE_FUSE=false'
'-DREQUIRE_VALGRIND=false'
'-A'
'x64'
The ' characters around the executable and arguments are
not part of the command.
     [exec] CMake Warning (dev) in CMakeLists.txt:
     [exec]   No project() command is present.  The top-level CMakeLists.txt file must
     [exec]   contain a li-- Selecting Windows SDK version 10.0.22621.0 to target Windows 10.0.19043.
     [exec] teral, direct call to the project() command.  Add a line of
     [exec]   code such as
     [exec] 
     [exec]     project(ProjectName)
format_quote

person Raymond access_time 2 years ago

Try install vcpkg and use it to install the dependent lib like OpenSSL. 

https://kontext.tech/article/594/microsoft-vcpkg-c-library-manager

If it still doesn’t work, you need use maven debug mode (-X) to see if your maven command has parameters about cmake prefix path or OpenSSL path. 

Raymond Raymond #1762 access_time 2 years ago more_vert

Try install vcpkg and use it to install the dependent lib like OpenSSL. 

https://kontext.tech/article/594/microsoft-vcpkg-c-library-manager

If it still doesn’t work, you need use maven debug mode (-X) to see if your maven command has parameters about cmake prefix path or OpenSSL path. 

format_quote

person ziyu access_time 2 years ago

No I install it directly

Z ziyu bai #1761 access_time 2 years ago more_vert

No I install it directly

format_quote

person Raymond access_time 2 years ago

Did you use vcpkg to install openssl and other required libs?

Raymond Raymond #1760 access_time 2 years ago more_vert

Did you use vcpkg to install openssl and other required libs?

format_quote

person ziyu access_time 2 years ago

I Builing Hadoop-3.3.1,I can't use docker in company. So i try to build with native win.

Z ziyu bai #1759 access_time 2 years ago more_vert

I Builing Hadoop-3.3.1,I can't use docker in company. So i try to build with native win.

format_quote

person Raymond access_time 2 years ago

Which Hadoop version are you building? I recommend using Docker to build the latest Hadoop: Build Latest Hadoop on Windows 10 natively via Docker (kontext.tech)

It usually means there is no CMAKE_PREFIX_PATH set for your cmake command when building HDFS native client. 

Raymond Raymond #1758 access_time 2 years ago more_vert

Which Hadoop version are you building? I recommend using Docker to build the latest Hadoop: Build Latest Hadoop on Windows 10 natively via Docker (kontext.tech)

It usually means there is no CMAKE_PREFIX_PATH set for your cmake command when building HDFS native client. 

format_quote

person ziyu access_time 2 years ago

I use Reproduce the issue

it could build with openssl

2022121290012-image.png

but when i build in hadoop,I can't find openssl.

2022121290205-image.png

Z ziyu bai #1757 access_time 2 years ago more_vert

I use Reproduce the issue

it could build with openssl

2022121290012-image.png

but when i build in hadoop,I can't find openssl.

2022121290205-image.png

Raymond Raymond #395 access_time 4 years ago more_vert

You are welcome, Hitendra. I'm glad it is working!

In the past, there were also quite a few users that could not built correctly because they didn't follow exactly about the steps in my articles. For all the installation guides I published, I've tested them on a sandbox to ensure it works. So usually if you keep following the steps, it should work.

Cheers,

Raymond

format_quote

person Hitendra access_time 4 years ago

Thanks for your reply. And big thanks to guide me through my journey.

I uninstalled all, started from scratch with instructions from your page, and the issues you have mentioned I faced exactly same. After fixing those, able to build. Now I am ready to deploy and run.

Thanks once again, and have a great day.

H Hitendra Behera #394 access_time 4 years ago more_vert

Thanks for your reply. And big thanks to guide me through my journey.

I uninstalled all, started from scratch with instructions from your page, and the issues you have mentioned I faced exactly same. After fixing those, able to build. Now I am ready to deploy and run.

Thanks once again, and have a great day.

format_quote

person Raymond access_time 4 years ago

I am glad you have come to this step.

The error is probably because of some of the C/C++ code are not compatible with Visual C++ unfortunately (differences between VC++ and GNU C/C++). You need to manually make some adjustments.

Refer to section II Issues Fix on the build article where I shared one example of fixing some of the errors:

Compile and Build Hadoop 3.2.1 on Windows 10 Guide

Hopefully it will resolve your problem. As your build environment might not be the same as mine, for example your VC++ compiler version might be different from mine, you may encounter some other issues. If that happens, you will need to resolve them one by one. But if you've followed exact setup in my article, you should only encounter that code error I mentioned. 

Please log in or register to comment.

account_circle Log in person_add Register

Log in with external accounts