UE4中使用Boost库

 
 

适用于header-only的库。

由于ProxyLODPlugin中已经包含了大部分的Boost库,因此只需要把相关路径加进去就行了。如果所需要的库没有,那么手动加入到项目路径中也可以。

Include Path

在项目的Build.cs中添加如下内容

PublicIncludePaths.AddRange(
	new string[] {
		System.IO.Path.Combine(EngineDirectory, "Plugins/Experimental/ProxyLODPlugin/Source/ThirdParty")
		// ... add public include paths required here ...
	}
	);

如果上面文件夹中的库缺失,将缺失的库拷贝到项目文件夹中,比如Source文件夹下面建个ThirdParty,然后这个目录添加到IncludePath中。

System.IO.Path.Combine(ModuleDirectory,"../ThirdParty")

头文件

THIRD_PARTY_INCLUDES_START
#define BOOST_DISABLE_ABI_HEADERS
#include "boost/graph/graph_traits.hpp"
#include "boost/graph/adjacency_list.hpp"
#include "boost/graph/dijkstra_shortest_paths.hpp"
#include "boost/property_map/property_map.hpp"
THIRD_PARTY_INCLUDES_END

THIRD_PARTY_INCLUDES_START和END宏解决下面的错误

Source\ThirdParty\boost/type_traits/detail/config.hpp(85): error C4668: '__clang_major___WORKAROUND_GUARD' is not defined as a preprocessor macro, replacing with '0' for '#if/#elif'
Source\ThirdParty\boost/type_traits/detail/config.hpp(85): error C4668: '__clang_major__' is not defined as a preprocessor macro, replacing with '0' for '#if/#elif'
1>C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shared\ntverp.h(119): error C4668: 'DBG' is not defined as a preprocessor macro, replacing with '0' for '#if/#elif'
1>C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shared\ntverp.h(126): error C4668: 'BETA' is not defined as a preprocessor macro, replacing with '0' for '#if/#elif'
Source\ThirdParty\boost/smart_ptr/shared_ptr.hpp(833): error C4668: '__GNUC__' is not defined as a preprocessor macro, replacing with '0' for '#if/#elif'
Source\ThirdParty\boost/mpl/aux_/config/operators.hpp(27): error C4668: '__NVCC___WORKAROUND_GUARD' is not defined as a preprocessor macro, replacing with '0' for '#if/#elif'
Source\ThirdParty\boost/mpl/aux_/config/operators.hpp(27): error C4668: '__NVCC__' is not defined as a preprocessor macro, replacing with '0' for '#if/#elif'

BOOST_DISABLE_ABI_HEADERS解决下面的错误

Source\ThirdParty\boost/config/abi_prefix.hpp(19): error C4103: alignment changed after including header, may be due to missing #pragma pack(pop)
Source\ThirdParty\boost/archive/detail/abi_prefix.hpp(11): error C4103: alignment changed after including header, may be due to missing #pragma pack(pop)
Source\ThirdParty\boost/archive/archive_exception.hpp(34): error C4103: alignment changed after including header, may be due to missing #pragma pack(pop)
Source\ThirdParty\boost/config/abi_suffix.hpp(20): error C4103: alignment changed after including header, may be due to missing #pragma pack(pop)
Source\ThirdParty\boost/archive/detail/abi_suffix.hpp(14): error C4103: alignment changed after including header, may be due to missing #pragma pack(pop)
Source\ThirdParty\boost/archive/archive_exception.hpp(98): error C4103: alignment changed after including header, may be due to missing #pragma pack(pop)

由于UE4默认禁用C++ exception,所以可能需要加上下面的代码

namespace boost
{
#ifdef BOOST_NO_EXCEPTIONS

	void throw_exception(std::exception const& e) {} // user defined

#else

#endif
} // namespace boost

否则可能会得到下面的错误

error LNK2019: unresolved external symbol "void __cdecl boost::throw_exception(class stdext::exception const &)" (?throw_exception@boost@@YAXAEBVexception@stdext@@@Z)

  • 个人测试,1.69版本的和UE4.22,4.23编译通过,1.71版本的编译有问题,VS2019环境。
  • Boost有条件的还是不要用了,一个是代码写得像天书,不够友好,另一个是有时候只用到一个库却要引入Boost全家桶套餐。

转载于:https://www.cnblogs.com/haisong1991/p/11496406.html

  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值