Boost 1_65_1无法使用OpenSSL 1.1.0g"未定义的引用"进行编译。但找到" nm"

时间:2017-11-06 14:01:06

标签: c++ boost openssl boost-asio

我正在尝试使用boost ASIO进行SSL工作。我在Windows上使用MingW 6.3。

当我尝试将它们链接到项目时,我使用MingW构建了OpenSSL 1.1,1.0和0.8我总是得到不同的错误(取决于缺少的内容)。 现在我正在努力使OpenSSL 1.1.0g工作,但我有这些错误,即使我手动给CMAKE的libs路径:

如果我使用OpenSSL 1.1.0g构建我的项目,这就是错误:

"C:\Program Files\JetBrains\CLion 2017.2.3\bin\cmake\bin\cmake.exe" --build C:\Users\myuser\Documents\MagesBattleAuthServerCPP\AuthServer\cmake-build-debug --target AuthServer -- -j 2
"C:\Program Files\JetBrains\CLion 2017.2.3\bin\cmake\bin\cmake.exe" -HC:\Users\myuser\Documents\MagesBattleAuthServerCPP\AuthServer -BC:\Users\myuser\Documents\MagesBattleAuthServerCPP\AuthServer\cmake-build-debug --check-build-system CMakeFiles\Makefile.cmake 0
C:/MinGW/bin/mingw32-make.exe -f CMakeFiles\Makefile2 AuthServer
mingw32-make.exe[1]: Entering directory 'C:/Users/myuser/Documents/MagesBattleAuthServerCPP/AuthServer/cmake-build-debug'
"C:\Program Files\JetBrains\CLion 2017.2.3\bin\cmake\bin\cmake.exe" -HC:\Users\myuser\Documents\MagesBattleAuthServerCPP\AuthServer -BC:\Users\myuser\Documents\MagesBattleAuthServerCPP\AuthServer\cmake-build-debug --check-build-system CMakeFiles\Makefile.cmake 0
"C:\Program Files\JetBrains\CLion 2017.2.3\bin\cmake\bin\cmake.exe" -E cmake_progress_start C:\Users\myuser\Documents\MagesBattleAuthServerCPP\AuthServer\cmake-build-debug\CMakeFiles 6
C:/MinGW/bin/mingw32-make.exe -f CMakeFiles\Makefile2 CMakeFiles/AuthServer.dir/all
mingw32-make.exe[2]: Entering directory 'C:/Users/myuser/Documents/MagesBattleAuthServerCPP/AuthServer/cmake-build-debug'
C:/MinGW/bin/mingw32-make.exe -f CMakeFiles\AuthServer.dir\build.make CMakeFiles/AuthServer.dir/depend
mingw32-make.exe[3]: Entering directory 'C:/Users/myuser/Documents/MagesBattleAuthServerCPP/AuthServer/cmake-build-debug'
"C:\Program Files\JetBrains\CLion 2017.2.3\bin\cmake\bin\cmake.exe" -E cmake_depends "MinGW Makefiles" C:\Users\myuser\Documents\MagesBattleAuthServerCPP\AuthServer C:\Users\myuser\Documents\MagesBattleAuthServerCPP\AuthServer C:\Users\myuser\Documents\MagesBattleAuthServerCPP\AuthServer\cmake-build-debug C:\Users\myuser\Documents\MagesBattleAuthServerCPP\AuthServer\cmake-build-debug C:\Users\myuser\Documents\MagesBattleAuthServerCPP\AuthServer\cmake-build-debug\CMakeFiles\AuthServer.dir\DependInfo.cmake --color=
mingw32-make.exe[3]: Leaving directory 'C:/Users/myuser/Documents/MagesBattleAuthServerCPP/AuthServer/cmake-build-debug'
C:/MinGW/bin/mingw32-make.exe -f CMakeFiles\AuthServer.dir\build.make CMakeFiles/AuthServer.dir/build
mingw32-make.exe[3]: Entering directory 'C:/Users/myuser/Documents/MagesBattleAuthServerCPP/AuthServer/cmake-build-debug'
[ 16%] Linking CXX executable bin\Windows\AuthServer.exe
"C:\Program Files\JetBrains\CLion 2017.2.3\bin\cmake\bin\cmake.exe" -E cmake_link_script CMakeFiles\AuthServer.dir\link.txt --verbose=1
"C:\Program Files\JetBrains\CLion 2017.2.3\bin\cmake\bin\cmake.exe" -E remove -f CMakeFiles\AuthServer.dir/objects.a
C:\MinGW\bin\ar.exe cr CMakeFiles\AuthServer.dir/objects.a @CMakeFiles\AuthServer.dir\objects1.rsp
C:\MinGW\bin\g++.exe -g   -Wl,--whole-archive CMakeFiles\AuthServer.dir/objects.a -Wl,--no-whole-archive  -o bin\Windows\AuthServer.exe -Wl,--out-implib,lib\libAuthServer.dll.a -Wl,--major-image-version,0,--minor-image-version,0 @CMakeFiles\AuthServer.dir\linklibs.rsp
CMakeFiles\AuthServer.dir/objects.a(main.cpp.obj): In function `ZN5boost4asio3ssl6detail17openssl_init_base7do_initD1Ev':
c:/users/myuser/documents/magesbattleauthservercpp/include/boost/asio/ssl/detail/impl/openssl_init.ipp:89: undefined reference to `CONF_modules_unload'
CMakeFiles\AuthServer.dir/objects.a(main.cpp.obj): In function `ZNK5boost4asio5error6detail12ssl_category7messageB5cxx11Ei':
c:/users/myuser/documents/magesbattleauthservercpp/include/boost/asio/ssl/impl/error.ipp:39: undefined reference to `ERR_reason_error_string'
collect2.exe: error: ld returned 1 exit status
CMakeFiles\AuthServer.dir\build.make:217: recipe for target 'bin/Windows/AuthServer.exe' failed
mingw32-make.exe[3]: Leaving directory 'C:/Users/myuser/Documents/MagesBattleAuthServerCPP/AuthServer/cmake-build-debug'
CMakeFiles\Makefile2:69: recipe for target 'CMakeFiles/AuthServer.dir/all' failed
mingw32-make.exe[2]: Leaving directory 'C:/Users/myuser/Documents/MagesBattleAuthServerCPP/AuthServer/cmake-build-debug'
mingw32-make.exe[3]: *** [bin/Windows/AuthServer.exe] Error 1
mingw32-make.exe[2]: *** [CMakeFiles/AuthServer.dir/all] Error 2
CMakeFiles\Makefile2:81: recipe for target 'CMakeFiles/AuthServer.dir/rule' failed
mingw32-make.exe[1]: Leaving directory 'C:/Users/myuser/Documents/MagesBattleAuthServerCPP/AuthServer/cmake-build-debug'
Makefile:120: recipe for target 'AuthServer' failed
mingw32-make.exe[1]: *** [CMakeFiles/AuthServer.dir/rule] Error 2
mingw32-make.exe: *** [AuthServer] Error 2

CMAKE:

cmake_minimum_required(VERSION 3.8)
project(AuthServer)

#----------------- MACROS -----------------------------
#FIND THE CORRECT VERSION OF WINNT
macro(get_WIN32_WINNT version)
    if (CMAKE_SYSTEM_VERSION)
        set(ver ${CMAKE_SYSTEM_VERSION})
        string(REGEX MATCH "^([0-9]+).([0-9])" ver ${ver})
        string(REGEX MATCH "^([0-9]+)" verMajor ${ver})
        # Check for Windows 10, b/c we'll need to convert to hex 'A'.
        if ("${verMajor}" MATCHES "10")
            set(verMajor "A")
            string(REGEX REPLACE "^([0-9]+)" ${verMajor} ver ${ver})
        endif ("${verMajor}" MATCHES "10")
        # Remove all remaining '.' characters.
        string(REPLACE "." "" ver ${ver})
        # Prepend each digit with a zero.
        string(REGEX REPLACE "([0-9A-Z])" "0\\1" ver ${ver})
        set(${version} "0x${ver}")
    endif(CMAKE_SYSTEM_VERSION)
endmacro(get_WIN32_WINNT)
#----------------- MACROS -----------------------------

set(CMAKE_VERBOSE_MAKEFILE ON)

set(CMAKE_CXX_STANDARD 14)

SET(CMAKE_FIND_LIBRARY_PREFIXES "lib")

add_definitions(-DBOOST_NETWORK_ENABLE_HTTPS)

set(SOURCE_FILES
        AuthServer/Client.cpp
        AuthServer/Client.h
        AuthServer/main.cpp
        AuthServer/NetworkManager.cpp
        AuthServer/NetworkManager.h
        AuthServer/Message.cpp
        AuthServer/Message.h
        AuthServer/JsonSerializable.h
        AuthServer/JsonDeserializerFactory.cpp
        AuthServer/JsonDeserializerFactory.h)

if (WIN32) #windows

    #set the correct WINNET version
    get_WIN32_WINNT(ver)
    add_definitions(-D_WIN32_WINNT=${ver})

    set(CMAKE_CXX_STANDARD_LIBRARIES "${CMAKE_CXX_STANDARD_LIBRARIES} -lws2_32 -lwsock32 -lmswsock")

    #set the correct lib build type .a because we are using mingw
    if(${CMAKE_BUILD_TYPE} MATCHES "debug")
        SET(CMAKE_FIND_LIBRARY_SUFFIXES "-mgw63-mt-d-1_65_1.a" ".a")
    ELSEIF(${CMAKE_BUILD_TYPE} MATCHES "release")
        SET(CMAKE_FIND_LIBRARY_SUFFIXES "-mgw63-mt-1_65_1.a" ".a")
    ENDIF()

    #find all the libs
    find_library(BOOST_LIBRARY_atomic
            NAMES boost_atomic
            PATHS ${CMAKE_SOURCE_DIR}/../Lib/win/x64/${CMAKE_BUILD_TYPE}
            NO_DEFAULT_PATH)

    find_library(BOOST_LIBRARY_chrono
            NAMES boost_chrono
            PATHS ${CMAKE_SOURCE_DIR}/../Lib/win/x64/${CMAKE_BUILD_TYPE}
            NO_DEFAULT_PATH)

    find_library(BOOST_LIBRARY_date_time
            NAMES boost_date_time
            PATHS ${CMAKE_SOURCE_DIR}/../Lib/win/x64/${CMAKE_BUILD_TYPE}
            NO_DEFAULT_PATH)

    find_library(BOOST_LIBRARY_regex
            NAMES boost_regex
            PATHS ${CMAKE_SOURCE_DIR}/../Lib/win/x64/${CMAKE_BUILD_TYPE}
            NO_DEFAULT_PATH)

    find_library(BOOST_LIBRARY_thread
            NAMES boost_thread
            PATHS ${CMAKE_SOURCE_DIR}/../Lib/win/x64/${CMAKE_BUILD_TYPE}
            NO_DEFAULT_PATH)

    find_library(BOOST_LIBRARY_system
            NAMES boost_system
            PATHS ${CMAKE_SOURCE_DIR}/../Lib/win/x64/${CMAKE_BUILD_TYPE}
            NO_DEFAULT_PATH)

    find_library(BOOST_LIBRARY_iostreams
            NAMES boost_iostreams
            PATHS ${CMAKE_SOURCE_DIR}/../Lib/win/x64/${CMAKE_BUILD_TYPE}
            NO_DEFAULT_PATH)

    find_library(BOOST_LIBRARY_zlib
            NAMES boost_zlib
            PATHS ${CMAKE_SOURCE_DIR}/../Lib/win/x64/${CMAKE_BUILD_TYPE}
            NO_DEFAULT_PATH)

    find_library(LIBRARY_ossl_ssl
            NAMES ssl
            PATHS ${CMAKE_SOURCE_DIR}/../Lib/win/x64/${CMAKE_BUILD_TYPE}
            NO_DEFAULT_PATH)

    find_library(LIBRARY_ossl_crypto
            NAMES crypto
            PATHS ${CMAKE_SOURCE_DIR}/../Lib/win/x64/${CMAKE_BUILD_TYPE}
            NO_DEFAULT_PATH)

    add_executable(AuthServer ${SOURCE_FILES})
ELSEif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") #osx

    SET(CMAKE_OSX_ARCHITECTURES x86_64)
    SET(CMAKE_FIND_LIBRARY_SUFFIXES ".a" ".dylib")

    find_library(BOOST_LIBRARY_atomic
            NAMES boost_atomic
            PATHS ${CMAKE_SOURCE_DIR}/../Lib/osx/x64/${CMAKE_BUILD_TYPE}
            NO_DEFAULT_PATH)

    find_library(BOOST_LIBRARY_chrono
            NAMES boost_chrono
            PATHS ${CMAKE_SOURCE_DIR}/../Lib/osx/x64/${CMAKE_BUILD_TYPE}
            NO_DEFAULT_PATH)

    find_library(BOOST_LIBRARY_date_time
            NAMES boost_date_time
            PATHS ${CMAKE_SOURCE_DIR}/../Lib/osx/x64/${CMAKE_BUILD_TYPE}
            NO_DEFAULT_PATH)

    find_library(BOOST_LIBRARY_regex
            NAMES boost_regex
            PATHS ${CMAKE_SOURCE_DIR}/../Lib/osx/x64/${CMAKE_BUILD_TYPE}
            NO_DEFAULT_PATH)

    find_library(BOOST_LIBRARY_thread
            NAMES boost_thread
            PATHS ${CMAKE_SOURCE_DIR}/../Lib/osx/x64/${CMAKE_BUILD_TYPE}
            NO_DEFAULT_PATH)

    find_library(BOOST_LIBRARY_system
            NAMES boost_system
            PATHS ${CMAKE_SOURCE_DIR}/../Lib/osx/x64/${CMAKE_BUILD_TYPE}
            NO_DEFAULT_PATH)

    find_library(BOOST_LIBRARY_iostreams
            NAMES boost_iostreams
            PATHS ${CMAKE_SOURCE_DIR}/../Lib/osx/x64/${CMAKE_BUILD_TYPE}
            NO_DEFAULT_PATH)

    find_library(BOOST_LIBRARY_zlib
            NAMES boost_zlib
            PATHS ${CMAKE_SOURCE_DIR}/../Lib/osx/x64/${CMAKE_BUILD_TYPE}
            NO_DEFAULT_PATH)

    add_executable(AuthServer ${SOURCE_FILES})
endif()

target_include_directories(AuthServer PUBLIC ${CMAKE_SOURCE_DIR}/../Include)


target_link_libraries(AuthServer
        PUBLIC
        ${BOOST_LIBRARY_chrono}
        ${BOOST_LIBRARY_atomic}
        ${BOOST_LIBRARY_date_time}
        ${BOOST_LIBRARY_regex}
        ${BOOST_LIBRARY_thread}
        ${BOOST_LIBRARY_system}
        ${BOOST_LIBRARY_iostreams}
        ${BOOST_LIBRARY_zlib}
        ${LIBRARY_ossl_ssl}
        ${LIBRARY_ossl_crypto}
        )


set_target_properties(AuthServer
        PROPERTIES
        ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
        LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
        RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/${CMAKE_SYSTEM_NAME}"
        )

构建OpenSSL的命令(mingw msys2)

$ ./Configure mingw64 no-shared no-asm --prefix=/C/OpenSSL-x64
$ make && make install

linklibs.rsp

C:/Users/myuser/Documents/MagesBattleAuthServerCPP/Lib/win/x64/debug/libboost_chrono-mgw63-mt-d-1_65_1.a
 C:/Users/myuser/Documents/MagesBattleAuthServerCPP/Lib/win/x64/debug/libboost_atomic-mgw63-mt-d-1_65_1.a
 C:/Users/myuser/Documents/MagesBattleAuthServerCPP/Lib/win/x64/debug/libboost_date_time-mgw63-mt-d-1_65_1.a
 C:/Users/myuser/Documents/MagesBattleAuthServerCPP/Lib/win/x64/debug/libboost_regex-mgw63-mt-d-1_65_1.a
 C:/Users/myuser/Documents/MagesBattleAuthServerCPP/Lib/win/x64/debug/libboost_thread-mgw63-mt-d-1_65_1.a
 C:/Users/myuser/Documents/MagesBattleAuthServerCPP/Lib/win/x64/debug/libboost_system-mgw63-mt-d-1_65_1.a
 C:/Users/myuser/Documents/MagesBattleAuthServerCPP/Lib/win/x64/debug/libboost_iostreams-mgw63-mt-d-1_65_1.a
 C:/Users/myuser/Documents/MagesBattleAuthServerCPP/Lib/win/x64/debug/libboost_zlib-mgw63-mt-d-1_65_1.a
 C:/Users/myuser/Documents/MagesBattleAuthServerCPP/Lib/win/x64/debug/libssl.a
 C:/Users/myuser/Documents/MagesBattleAuthServerCPP/Lib/win/x64/debug/libcrypto.a
 -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid
 -lcomdlg32 -ladvapi32 -lws2_32 -lwsock32 -lmswsock -ldl -lpthread 

nm我编译的OpenSSL库:

myuser@LHCFB203 MINGW64 ~
$ nm /C/Users/myuser/Documents/MagesBattleAuthServerCPP/Lib/win/x64/debug/libcrypto.a | grep 'CONF_modules_unload'
00000000000005c0 T CONF_modules_unload

myuser@LHCFB203 MINGW64 ~
$ nm /C/Users/myuser/Documents/MagesBattleAuthServerCPP/Lib/win/x64/debug/libcrypto.a | grep 'ERR_reason_error_string'
0000000000004de0 T ERR_reason_error_string

我使用的是错误的OpenSSL版本吗?我不应该使用OpenSSL吗?我错了吗?

编辑: 添加了-ldl和-lpthread,但没有帮助。

1 个答案:

答案 0 :(得分:0)

我遇到了这个问题,因为我不小心使用了opensl的​​x86(32位)版本 (来自https://www.nuget.org/packages/openssl-vc141/,但未说明计算机) 并使用x64 boost asio将其链接到我的x64项目中。

VS2017已编译,并且仅在链接期间抱怨缺少两个符号:

LNK2001 unresolved external symbol CONF_modules_unload  
LNK2001 unresolved external symbol ERR_reason_error_string

Dumpbin显示了这些符号的存在,但随后我看到该符号(和整个库)是针对x86编译的... facepalm ;很奇怪,链接程序不会抱怨不同的机器...

我切换到此版本,并且所有编译/链接均正确:

https://www.nuget.org/packages/openssl-vc140-vc141-x86_64/