Boost.Asio: LNK2019: unresolved external symbol CONF_modules_unload referenced in function

· by 박승재

Windows에서 Boost.Asio를 쓰다보면 아래와 같은 오류를 마주할 때가 있다.

NMAKE : fatal error U1077: '"C:\Program Files\JetBrains\CLion 2020.1.3\bin\cmake\win\bin\cmake.exe"' : return code '0xffffffff'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\bin\HostX64\x64\nmake.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\bin\HostX64\x64\nmake.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\bin\HostX64\x64\nmake.exe"' : return code '0x2'
Stop.
LINK Pass 1: command "C:\PROGRA~2\MICROS~1\2019\COMMUN~1\VC\Tools\MSVC\1427~1.291\bin\Hostx64\x64\link.exe /nologo @CMakeFiles\project.dir\objects1.rsp /out:project.exe /implib:project.lib /pdb:C:\Users\Seungjae\GitHub\project\cmake-build-debug\project.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:CMakeFiles\project.dir/intermediate.manifest CMakeFiles\project.dir/manifest.res" failed (exit code 1120) with the following output:
main.cpp.obj : error LNK2019: unresolved external symbol CONF_modules_unload referenced in function "public: __cdecl boost::asio::ssl::detail::openssl_init_base::do_init::~do_init(void)" (??1do_init@openssl_init_base@detail@ssl@asio@boost@@QEAA@XZ)
main.cpp.obj : error LNK2019: unresolved external symbol ERR_reason_error_string referenced in function "public: virtual class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl boost::asio::error::detail::ssl_category::message(int)const " (?message@ssl_category@detail@error@asio@boost@@UEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@H@Z)
project.exe : fatal error LNK1120: 2 unresolved externals

#include <boost/asio/ssl/stream.hpp>과 같이 SSL과 관련된 헤더를 include하면 발생하는 오류이다.

해결방법은 아래와 같다.

find_package(OpenSSL REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE OpenSSL::SSL)

OpenSSL 의존성을 추가하고 링크하면 된다.

참고: CMake FindOpenSSL