CMake在64位Ubuntu 14.04上找不到32位开放SSL

时间:2017-06-27 15:24:07

标签: c++ ubuntu cmake openssl

我有一个64位的Ubuntu 14.04虚拟机,我正在尝试编译依赖于openssl的32位应用程序,并且我不断收到以下错误:

-- The C compiler identification is GNU 4.8.4
-- The CXX compiler identification is GNU 4.8.4
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/g++
-- Check for working CXX compiler: /usr/bin/g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
CMake Error at /usr/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:108 (message):
  Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the
  system variable OPENSSL_ROOT_DIR (missing: OPENSSL_LIBRARIES) (found
  version "1.0.1f")

我创建了以下测试用例来重现错误。

DockerFile

FROM ubuntu:trusty

LABEL maintainer="Diarra_Bakary@test.com"
LABEL version="1.0"

RUN dpkg --add-architecture i386 && \
    apt-get update && \
    apt-get install -y \
    git\
    cmake\
    curl:i386\
    libcurl4-openssl-dev:i386\
    libssl-dev:i386\
    uuid-dev:i386
RUN apt-get install -y \
    gcc-multilib\
    g++-multilib

的CMakeLists.txt

cmake_minimum_required(VERSION 2.8)

find_package(OpenSSL REQUIRED)

x86_32.cmake

SET(CMAKE_SYSTEM_NAME Linux)

# which compilers to use for C and C++
set(CMAKE_C_COMPILER gcc)
set(CMAKE_C_FLAGS -m32)
set(CMAKE_CXX_COMPILER g++)
set(CMAKE_CXX_FLAGS -m32)

运行以下命令

mkdir cmake
cd cmake
cmake -DCMAKE_TOOLCHAIN_FILE=x86_32.cmake ..

提前致谢

2 个答案:

答案 0 :(得分:1)

我能够通过在工具链中添加以下行来解决我的问题:

# Specify Openssl Path
SET(CMAKE_LIBRARY_PATH "/usr/lib/i386-linux-gnu")
include_directories(BEFORE /usr/include/i386-linux-gnu)

感谢@Tsyvarev的推荐!

答案 1 :(得分:0)

CMake建议try to set the path to OpenSSL root folder in the system variable OPENSSL_ROOT_DIR

实际上,FindOpenSSL.cmake提供了一个选项OPENSSL_ROOT_DIR,可以提供该选项以指定OpenSSL的安装目录的位置。

你能在CMakeList.txt中尝试类似的东西:

cmake_minimum_required(VERSION 2.8)

set(OPENSSL_ROOT_DIR /usr/local/ssl)
message("OPENSSL_ROOT_DIR is "  ${OPENSSL_ROOT_DIR})
find_package(OpenSSL REQUIRED)

message("OPENSSL_FOUND is "  ${OPENSSL_FOUND})
message("OPENSSL_INCLUDE_DIR is "  ${OPENSSL_INCLUDE_DIR})
message("OPENSSL_CRYPTO_LIBRARY is "  ${OPENSSL_CRYPTO_LIBRARY})
message("OPENSSL_SSL_LIBRARY is "  ${OPENSSL_SSL_LIBRARY})
message("OPENSSL_LIBRARIES is "  ${OPENSSL_LIBRARIES})
message("OPENSSL_VERSION is "  ${OPENSSL_VERSION})

当然,必须调整文件夹/usr/local/ssl以指定安装目录,您可以在其中找到文件夹libinclude。在文件夹lib中,您会找到库libcrypto.alibssl.a,您会在include/openssl中找到大量标题(.h)文件。

编辑:如果安装不是标准的,那么必须将环境变量设置为正确的值而不调用find_package()。例如,我的是:

OPENSSL_ROOT_DIR is /usr/local/ssl
OPENSSL_FOUND is TRUE
OPENSSL_INCLUDE_DIR is /usr/local/ssl/include
OPENSSL_CRYPTO_LIBRARY is /usr/local/ssl/lib/libcrypto.a
OPENSSL_SSL_LIBRARY is /usr/local/ssl/lib/libssl.a
OPENSSL_LIBRARIES is /usr/local/ssl/lib/libssl.a/usr/local/ssl/lib/libcrypto.a
OPENSSL_VERSION is 1.0.2d

然后,可以使用target_include_directories()link_directories()target_link_libraries()