碰到了OpenSSL加入到在Visual Studio 2019中编译返回LNK2019错误,添加了缺失的库文件,解决了问题。
错误有类似以下返回:
Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol _BUF_MEM_new referenced in function "public: static class std::basic_string,class std::allocator > __cdecl SimpleWeb::Crypto::Base64::encode(class std::basic_string,class std::allocator > const &)" (?encode@Base64@Crypto@SimpleWeb@@SA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@ABV45@@Z)
Error LNK2019 unresolved external symbol BIO_ctrl referenced in function "public: static class std::basic_string,class std::allocator > __cdecl SimpleWeb::Crypto::Base64::encode(class std::basic_string,class std::allocator > const &)" (?encode@Base64@Crypto@SimpleWeb@@SA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AEBV45@@Z)
在Visual Studio 2019中编译返回LNK2019错误这个问题比较难解决,根据网上经验,尝试了多种解决办法都没有用。
大体有三种解决思路,如下:
尝试了在工程属性–> C/C++ --> Code Generation --> Runtime Library进行更改:
参考:Visual Studio 2019配置OpenSSL 3.0开发环境
在工程属性–> Linker --> Input --> Additional Dependencies添加以下库文件:
Win64OpenSSL-3_0_5.msi,工程文件里都添加了包含目录和库目录,但是还是要在以上设置里添加这三个库。在工程属性–> C/C++ --> Code Generation --> Runtime Library进行更改的时候,会报LNK1104的错误。
LNK1104 cannot open file 'libboost_date_time-vc142-mt-sgd-x64-1_70.lib',实际在目录里是有libboost_date_time-vc142-mt-gd-x64-1_70.lib,少了个s, 运行库需要的库还不一样,如果拷贝一份,再进行改名,加上个s, 也是能编译的。
有关C4996警告,已经设置了project properties -> Configuration Properties -> C/C++ -> General -> SDL checks -> No,还是不行。
直接把#pragma warning(disable : 4996)放在代码前面进行了屏蔽。
最后,直接忽略了warning C4267: 'argument': conversion from 'size_t' to 'int', possible loss of data。
Visual Studio 2019配置OpenSSL 3.0开发环境
Stack Overflow: LNK1104 cannot open file ‘libboost_log-vc142-mt-gd-x64-1_72.lib’?
VS2012 error C2019, error link2019:无法解析的外部符号
【error LNK2019: unresolved external symbol】问题解决方案
Error LNK2019:Unresolved External Symbol 的解决方案
Unresolved external symbol in object files
Why does Visual Studio 2013 error on C4996?