编译的CGAL版本为4.11.3,Boost版本为boost_1_60_0,Cmake版本为cmake-3.5.2-win32-x86,
Boost可只生成(system,thread模块)(运行b2.exe --With-system --With-thread)
版本对不上运行cmake会遇到各种问题。
编译CGAL参考的教程很多不赘述。
https://blog.csdn.net/u013451076/article/details/80728924 除版本冲突外,VS环境变量会导致cmake认不到编译器
编译完成后,创建一个第三方空白插件,将库导入UE4
在build.cs如下
using System.IO;
using UnrealBuildTool;
public class CGALDLLLibrary : ModuleRules
{
public CGALDLLLibrary(ReadOnlyTargetRules Target) : base(Target)
{
Type = ModuleType.External;
if (Target.Platform == UnrealTargetPlatform.Win64)
{
//静态库目录
PublicLibraryPaths.Add(Path.Combine(ModuleDirectory, "x64", "Release"));
// Add the import library
PublicLibraryPaths.Add(Path.Combine(ModuleDirectory, "Boost", "stage","lib"));
PublicLibraryPaths.Add(Path.Combine(ModuleDirectory, "CGAL", "lib", "Release"));
PublicLibraryPaths.Add(Path.Combine(ModuleDirectory, "CGAL", "auxiliary", "gmp", "lib"));
PublicAdditionalLibraries.Add("ExampleLibrary.lib");//插件默认项
//添加lib
PublicAdditionalLibraries.Add("libboost_system-vc140-mt-1_60.lib");
PublicAdditionalLibraries.Add("libboost_thread-vc140-mt-1_60.lib");
PublicAdditionalLibraries.Add("CGAL_Core-vc140-mt-4.11.3.lib");
PublicAdditionalLibraries.Add("CGAL_ImageIO-vc140-mt-4.11.3.lib");
PublicAdditionalLibraries.Add("CGAL-vc140-mt-4.11.3.lib");
PublicAdditionalLibraries.Add("libgmp-10.lib");
PublicAdditionalLibraries.Add("libmpfr-4.lib");
// Delay-load the DLL, so we can load it from the right place first
PublicDelayLoadDLLs.Add("ExampleLibrary.dll");//插件默认项
//添加dll
PublicDelayLoadDLLs.Add("CGAL-vc140-mt-4.11.3.dll");
PublicDelayLoadDLLs.Add("libgmp-10.dll");
PublicDelayLoadDLLs.Add("libmpfr-4.dll");
//包含头文件目录
PublicIncludePaths.Add(Path.Combine(ModuleDirectory, "Boost"));
PublicIncludePaths.Add(Path.Combine(ModuleDirectory, "CGAL", "auxiliary", "gmp", "include"));
PublicIncludePaths.Add(Path.Combine(ModuleDirectory, "CGAL", "include"));
}
else if (Target.Platform == UnrealTargetPlatform.Mac)
{
PublicDelayLoadDLLs.Add(Path.Combine(ModuleDirectory, "Mac", "Release", "libExampleLibrary.dylib"));
}
}
}
无非就是把编译完后的CGAL库,Boost库都写进.cs文件
写完之后编译发现失败,报了
mp_defer.hpp(28):错误C2988
查阅发现UE4源码中也有插件使用了boost,
在 Engine\Plugins\Experimental\ProxyLODPlugin\Source\ThirdParty 目录下
对比两者mp_defer.hpp发现只是将原boost中check改写为check_s,所以估计是boost中代码与UE4自带的宏重名(check,PI等)。
我直接将上面目录下的boost覆盖了自己插件中的boost目录,但之后还是会遇到类似情况,我都是在冲突名后加“_s”(仿照源码)
包含#include <CGAL/Nef_polyhedron_3.h>后出现Error:4503:
D:\Epic\Epic Games\UE_4.18\Engine\Source\Runtime\Core\Public\Windows\WindowsPlatformCompilerSetup.h中将4503剔除
剔除后编译通过但发现无法打开UE4项目,目测UE4不支持过长的修饰名,只能放弃
过程文件:https://download.csdn.net/download/qq_29019373/11838019
只能另辟蹊径调用exe实现了:https://blog.csdn.net/qq_29019373/article/details/102487363