当项目中使用asio作为通讯库时,编译打包时总是报如下错误:

error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl std::bad_cast::bad_cast(char const *)" (__imp_??0bad_cast@std@@QEAA@PEBD@Z) referenced in function "public: __cdecl asio::ip::bad_address_cast::bad_address_cast(void)" (??0bad_address_cast@ip@asio@@QEAA@XZ)
error LNK2001: unresolved external symbol "__declspec(dllimport) public: __cdecl std::bad_cast::bad_cast(char const *)" (__imp_??0bad_cast@std@@QEAA@PEBD@Z)
error LNK2001: unresolved external symbol "protected: virtual void __cdecl std::bad_cast::_Doraise(void)const " (?_Doraise@bad_cast@std@@MEBAXXZ)
error LNK2001: unresolved external symbol "protected: virtual void __cdecl std::bad_cast::_Doraise(void)const " (?_Doraise@bad_cast@std@@MEBAXXZ)

查看asio::ip::bad_address_cast的源代码,发现bad_address_cast继承了<typeinfo>中定义的std::bad_cast,代码如下:

//
// ip/bad_address_cast.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//#ifndef ASIO_IP_BAD_ADDRESS_CAST_HPP
#define ASIO_IP_BAD_ADDRESS_CAST_HPP#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)#include "asio/detail/config.hpp"
#include <typeinfo>#include "asio/detail/push_options.hpp"namespace asio {
namespace ip {/// Thrown to indicate a failed address conversion.
class bad_address_cast : public std::bad_cast
{
public:/// Default constructor.bad_address_cast() {}/// Destructor.virtual ~bad_address_cast() ASIO_NOEXCEPT_OR_NOTHROW {}/// Get the message associated with the exception.virtual const char* what() const ASIO_NOEXCEPT_OR_NOTHROW{return "bad address cast";}
};} // namespace ip
} // namespace asio#include "asio/detail/pop_options.hpp"#endif // ASIO_IP_ADDRESS_HPP

从代码中看到#include <typeinfo>,应该没有理由找不到std::bad_cast。再查看VC++中提供的typeinfo的源代码:

// typeinfo standard header/***
*typeinfo - Defines the type_info structure and exceptions used for RTTI
*
*    Copyright (c) Microsoft Corporation. All rights reserved.
*    Modified January 1996 by P.J. Plauger
*
*Purpose:
*       Defines the type_info structure and exceptions used for
*       Runtime Type Identification.
*
*       [Public]
*
****/#pragma once#ifndef _TYPEINFO_
#define _TYPEINFO_
#ifndef RC_INVOKED
#include <exception>#pragma pack(push,_CRT_PACKING)
#pragma warning(push,_STL_WARNING_LEVEL)
#pragma warning(disable: _STL_DISABLED_WARNINGS)
_STL_DISABLE_CLANG_WARNINGS
#pragma push_macro("new")
#undef new#pragma warning(disable: 4275)    // non dll-interface class 'X' used as base for dll-interface class 'Y'#include <vcruntime_typeinfo.h>_STD_BEGIN// size in pointers of std::function and std::any (roughly 3 pointers larger than std::string when building debug)
constexpr int _Small_object_num_ptrs = 6 + 16 / sizeof (void *);#if !(_HAS_EXCEPTIONS)// CLASS bad_cast
class _CRTIMP2_IMPORT bad_cast: public exception{    // base of all bad cast exceptions
public:bad_cast(const char *_Message = "bad cast") noexcept: exception(_Message){    // construct from message string}virtual ~bad_cast() noexcept{    // destroy the object}protected:virtual void _Doraise() const{    // perform class-specific exception handling_RAISE(*this);}};// CLASS bad_typeid
class _CRTIMP2_IMPORT bad_typeid: public exception{    // base of all bad typeid exceptions
public:bad_typeid(const char *_Message = "bad typeid") noexcept: exception(_Message){    // construct from message string}virtual ~bad_typeid() noexcept{    // destroy the object}protected:virtual void _Doraise() const{    // perform class-specific exception handling_RAISE(*this);}};class _CRTIMP2_IMPORT __non_rtti_object: public bad_typeid{    // report a non RTTI object
public:__non_rtti_object(const char *_Message): bad_typeid(_Message){    // construct from message string}};#endif /* _HAS_EXCEPTIONS */_STD_END#pragma pop_macro("new")
_STL_RESTORE_CLANG_WARNINGS
#pragma pack(pop)
#pragma warning(pop)
#endif /* RC_INVOKED */
#endif // _TYPEINFO_/** Copyright (c) Microsoft Corporation.  ALL RIGHTS RESERVED.* Modified January 1996 by P.J. Plauger* Modified November 1998 by P.J. Plauger* Consult your license regarding permissions and restrictions.
V6.50:0009 */

是class bad_cast定义前有这么一行:  #if !(_HAS_EXCEPTIONS)
当在.Build.cs中添加bEnableExceptions = true后,编译时会添加参数:/EHsc,这将导致_HAS_EXCEPTIONS=1,#if !(_HAS_EXCEPTIONS)为false,从而最终class bad_cast不被包含。于是就导致unresolved external symbol。

修改方法也很简单,修改asio::ip::bad_address_cast的源代码,将std::bad_cast替换成std::exception即可:

//
// ip/bad_address_cast.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//#ifndef ASIO_IP_BAD_ADDRESS_CAST_HPP
#define ASIO_IP_BAD_ADDRESS_CAST_HPP#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)#include "asio/detail/config.hpp"
#include <exception>#include "asio/detail/push_options.hpp"namespace asio {
namespace ip {/// Thrown to indicate a failed address conversion.
class bad_address_cast : public std::exception
{
public:/// Default constructor.bad_address_cast() {}/// Destructor.virtual ~bad_address_cast() ASIO_NOEXCEPT_OR_NOTHROW {}/// Get the message associated with the exception.virtual const char* what() const ASIO_NOEXCEPT_OR_NOTHROW{return "bad address cast";}
};} // namespace ip
} // namespace asio#include "asio/detail/pop_options.hpp"#endif // ASIO_IP_ADDRESS_HPP

Unreal Engine 4 问题:使用asio后编译打包报错:unresolved external symbol相关推荐

  1. 鼎捷T100 以客制批次作业为例,画面规格生成后编译程式报错问题

    问题阐述: 今日在客制批次作业的时候遇到一个问题.在此做一个记录 由于批次作业规格生成后部分程式代码不会自动生成(如开窗等),直接进行编译上传则会报错的问题. 步骤 客制批次作业 步骤与其他作业一致, ...

  2. Android编译打包报错Invalid keystore format

    问题描述 运行一个开源老项目,编译出现以下错误. java.io.IOException: Invalid keystore format Execution failed for task ':ap ...

  3. IDEA 修改JDK版本后,没有效果,编译还是报错。

    idea配置的jdk为1.7,但是项目要求为1.8,修改了项目的jdk后,还是编译错误,jdk版本过低. 1.File-->Project Structre 配置Project Structre ...

  4. Uboot 编译问题-“xxx aliased to external symbol xxx”

    Uboot 编译问题- "xxx aliased to external symbol xxx" 编译器 arm-linux-gnueabi-gcc 7.4 (ubuntu1804 ...

  5. Unity集成穿山甲后打包报错android:networkSecurityConfig , Picked up JAVA_TOOL_OPTIONS:-Dfile.encoding=UTF-8

    Unity集成穿山甲4.0SDK后打包报错 , /Users/-/Temp/gradleOut/unityLibrary/src/main/AndroidManifest.xml:31:3-138:1 ...

  6. HBuilderX 安装 scss/sass编译 插件报错 binding.node 解决方案windows版

    HBuilderX 安装 scss/sass编译 插件报错 binding.node 解决方案windows版 官方给出的解决方案 让我们在命令行执行下面三行代码 [0;31m--> LibSa ...

  7. IDEA编译项目报错Error:OutOfMemoryError: insufficient memory解决方法

    tomcat启动时设置 -DEWAY_HOME=G:\东华\workspace\idea\SOAR\dhcc-home -Xms128m -Xmx2048m -XX:PermSize=128M -XX ...

  8. AndroidStudio 编译项目报错 Android resource linking failed解决方案

    AndroidStudio编译项目报错:Execution failde for task ':app:processDebugResources'. > Android resource li ...

  9. tornado创建项目后build vxworks报错unable to allocate heap, heap_chunk_size 587202560, Win32 error 0

    tornado创建项目后build vxworks报错unable to allocate heap, heap_chunk_size 587202560, Win32 error 0 build报错 ...

最新文章

  1. 90后清华女校友范楚楚获ACM 2020唯一博士论文奖!出任MIT助理教授后再摘桂冠
  2. Huawei交换机配置两台交换机堆叠示例
  3. 皮一皮:没想到被小龙虾套路了...
  4. pl/sql developer执行光标所在行
  5. Eclipse中安装freemarker插件
  6. 开启SAP CDS view DCL前后的读取性能对比
  7. 一、Vue基础语法学习笔记系列——插值操作(Mustache语法、v-once、v-html、v-text、v-pre、v-cloak)、绑定属性v-bind(绑定class、style)、计算属性
  8. css技巧中placeholder的颜色
  9. Linux脚本Shell命令
  10. [原创]如何从数据库层面检测两表内容的一致性
  11. Vue ---- 指令
  12. 人脸数据库使用授权求助帖
  13. html 半框添加,配眼镜全框好还是半框的好?
  14. 使用手册 煤矿风险管控系统_煤矿风险分级管控手册.doc
  15. Android material design 之 BottomSheet基础入门
  16. tarjan算法与无向图的连通性(割点,桥,双连通分量,缩点)
  17. ui标注android ios,IOS+ANDROID的UI切图与标注方法
  18. MySql 根据身份证号判断年龄所属省份与性别男女
  19. 你一定要用好的实用外贸工具(内附清单)
  20. 基本知识:block/sleep/hang/宕机/hook/stub/offload/overhead/watermark

热门文章

  1. 【diannaoxitong】支付宝余额宝是什么?阿里巴巴余额宝功能介绍
  2. Android8.0安装apk报错:Package xxx is currently frozen
  3. 人力资源机器下载方法
  4. java键盘mac_XQuartz,Mac和Tourette键盘问题
  5. 计算机设计原理教学反思,教学反思——我是电脑小医生
  6. 2021浙江理工大学新生赛被毒打记录
  7. u盘分区合并 问题 U盘格式化问题 以及U盘作为启动盘安装系统之后,提示U盘需要格式化的问题
  8. 快来给你个人微信公众号认个证吧
  9. android类加载
  10. ?xml version=1.0 encoding=utf-8?appcommand time=1494385110doa