openssl - 提示无法找到OpenSSL库



 cmake ..


-- Could NOT find Git (missing: GIT_EXECUTABLE) 


ZLib include dirs: /usr/include


ZLib libraries: /usr/lib/arm-linux-gnueabihf/libz.so


Compiling with SSL support


CMake Error at /usr/local/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:97 (message):


 Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the


 system variable OPENSSL_ROOT_DIR (missing: OPENSSL_LIBRARIES


 OPENSSL_INCLUDE_DIR)


Call Stack (most recent call first):


 /usr/local/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:291 (_FPHSA_FAILURE_MESSAGE)


 /usr/local/share/cmake-2.8/Modules/FindOpenSSL.cmake:313 (find_package_handle_standard_args)


 CMakeLists.txt:436 (find_package)




#


# OpenSSL


#


if (WITH_SSL)


 message("Compiling with SSL support")



 if (USE_CYASSL)


 # Use CyaSSL as OpenSSL replacement.


 # TODO: Add a find_package command for this also.


 message("CyaSSL include dir: ${CYASSL_INCLUDE_DIRS}")


 message("CyaSSL libraries: ${CYASSL_LIB}")



 # Additional to the root directory we need to include


 # the cyassl/ subdirectory which contains the OpenSSL


 # compatability layer headers.


 foreach(inc ${CYASSL_INCLUDE_DIRS})


 include_directories(${inc} ${inc}/cyassl)


 endforeach()



 list(APPEND LIB_LIST ${CYASSL_LIB})


 else()


 # TODO: Add support for STATIC also.


 find_package(OpenSSL REQUIRED)



 message("OpenSSL include dir: ${OPENSSL_INCLUDE_DIR}")


 message("OpenSSL libraries: ${OPENSSL_LIBRARIES}")



 include_directories(${OPENSSL_INCLUDE_DIR})


 list(APPEND LIB_LIST ${OPENSSL_LIBRARIES})


 endif()


endif(WITH_SSL)



http://www.opensource.apple.com/source/OpenSSL/OpenSSL-7.1/openssl/INSTALL?txt
现在我已经安装了Openssl,这里: ---


ssl header is here --> /usr/local/ssl/include/openssl/


ssl library is here --> /usr/local/ssl/lib/libssl.a


 /usr/local/ssl/lib/libcrypto.a


openssl is here --> /usr/local/ssl/bin




export LD_LIBRARY_PATH=/usr/local/ssl/include/openssl:/usr/lib:/usr/local/lib:/usr/lib/pkgconfig:/usr/local/include/wx-2.8/wx:$LD_LIBRARY_PATH


export PKG_CONFIG_PATH=/usr/lib/pkgconfig


export OPENSSL_ROOT_DIR=/usr/local/ssl


export OPENSSL_LIBRARIES=/usr/local/ssl/lib/



PATH = /usr/local/ssl/bin:$PATH



如何解决这个错误?


这个错误


/usr/local/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_globallookup':


dso_dlfcn.c:(.text+0x10): undefined reference to `dlopen'


dso_dlfcn.c:(.text+0x24): undefined reference to `dlsym'


dso_dlfcn.c:(.text+0x30): undefined reference to `dlclose'



时间:

这是一个常见的误解:CMake不需要环境变量即可知道库和包含目录的位置,只需CMake变量即可。

由于CMake找不到您的OpenSSL lib和include目录,因此您必须在调用它时使用其命令行手动告诉他它们在哪里。使用选项-D在CMake中从命令行设置常量,你需要设置常量OPENSSL_ROOT_DIROPENSSL_LIBRARIES,因为它们是触发错误的常量。


cmake -DOPENSSL_ROOT_DIR=/usr/local/ssl -DOPENSSL_LIBRARIES=/usr/local/ssl/lib



我也有同样的问题(openssl ),这对我在Ubuntu 14.04.1 LTS上工作


sudo apt-get install libssl-dev



在macOS上使用


brew install openssl


cmake -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl -DOPENSSL_LIBRARIES=/usr/local/opt/openssl/lib



请从下面的链接安装openssl:
https://code.google.com/p/openssl-for-windows/downloads/list
然后设置以下变量:


OPENSSL_ROOT_DIR=D:/softwares/visualStudio/openssl-0.9.8k_WIN32


OPENSSL_INCLUDE_DIR=D:/softwares/visualStudio/openssl-0.9.8k_WIN32/include


OPENSSL_LIBRARIES=D:/softwares/visualStudio/openssl-0.9.8k_WIN32/lib



如果可以使用pkg-config:pkg_search_module()可以找到OpenSSL。


# Search OpenSSL


find_package(PkgConfig REQUIRED)


pkg_search_module(OPENSSL REQUIRED openssl)



if( OPENSSL_FOUND )


 include_directories(${OPENSSL_INCLUDE_DIRS})


 message(STATUS"Using OpenSSL ${OPENSSL_VERSION}")


else()


 # Error; with REQUIRED, pkg_search_module() will throw an error by it's own


endif()



target_link_libraries(${YOUR_TARGET_HERE} ${OPENSSL_LIBRARIES})



同样的问题,使用下面的命令在centos 6.5上修复了它。


yum install openssl-devel



在cmake-MODULE (路径usr/shared.cmake-3.5/modules)#Search OpenSSL中有FindOpenSSL.cmake文件


 find_package(OpenSSL REQUIRED) 


if( OpenSSL_FOUND )


 include_directories(${OPENSSL_INCLUDE_DIRS})


 link_directories(${OPENSSL_LIBRARIES})


 message(STATUS"Using OpenSSL ${OPENSSL_VERSION}")



target_link_libraries(project_name /path/of/libssl.so /path/of/libcrypto.so)



Fedora 27用户注意事项:我必须安装openssl-devel软件包才能成功运行cmake

sudo dnf install openssl-devel


cmake -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl/ -DOPENSSL_CRYPTO_LIBRARY=/usr/local/opt/openssl/lib/



...