2020년 1월 8일 수요일

ue4 Third Party (dll, lib, .h)

외부에서 가져온 라이브러리 적용 및 사용 방법 정리

1. 엔진에서 새 플러그인을 만든다. 이름은 BKPlugin
   (플러그인은 대표 module 을 갖춘 module 집합체 임, 엔진도 module 집합체)
   BKPlugin.h 와 BKPlugin.cpp 가 생김

   엔진을 켜고  Actor 를 상속받는 c++ 클래스를 만든다. 이름은 BKPluginActor
   만들때 항목을 방금 만든 BKPlugin 산하로 바꿔주는 것 중요 



2. 프로젝트의 build.cs 파일에

PublicDependencyModuleNames.AddRange(new string[] {
            ............(기존 여러가지 있을 수 있음)
            , "BKPlugin" //추가
        });



3. 프로젝트의 uproject 파일에 BKPlugin 추가
   ( 빌드시 오류가 나는 경우가 있는데 지우고 빌드 성공하면 다시 채워 놓으면 됨 )

"Modules": [
.......
         ],
"Plugins": [
    .................(기존 여러가지 있을 수 있음)
    ,
    {
      "Name": "BKPlugin",
      "Enabled": true
    }
  ]


4. BKPlugin 추가 코딩 및 세팅

BKPlugin 산하의 폴더 계층이 이렇게
 
BKPlugin
 - Source
    - BKPlugin
       - classes ( BKPluginActor.h )
       - private ( BKPlugin.cpp, BKPluginActor.cpp )
       - public  ( BKPluginr.h )
       - BKPlugin.Build.cs
    - ThirdParty
       - SomeSDK
         - include( .h )
         - lib( .dll, .lib )
         - SomeSDK.Build.cs

되게한다.( 윈도우 탐색기에서 작업하고 Generate VS project file 해주면 반영됨 )


BKPlugin.build.cs 에 아래와 같이 되도록

        PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs;

        PublicIncludePaths.AddRange(new string[] { "NetVios/Public" });
        PrivateIncludePaths.AddRange(new string[] { "NetVios/Private" });
        PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore" });
        PrivateDependencyModuleNames.AddRange(new string[] { "CoreUObject", "Engine", "Slate", "SlateCore" });
        DynamicallyLoadedModuleNames.AddRange(new string[] { });

        PublicDependencyModuleNames.Add("SomeSDK");// < 이것이 중요



BKPlugin.uplugin 의 Type 을 Developer 에서 Runtime 으로 바꿔준다.
(안바꾸면 엔진에서는 startupmodule() 이 호출되나 빌드시 안됨)


SomeSDK.build.cs 에 아래와 같이 되도록

        Type = ModuleType.External;

        string LibraryPath = ModuleDirectory + "/";

        PublicIncludePaths.Add(LibraryPath + "include");

        LibraryPath += "lib/";
        PublicLibraryPaths.Add(LibraryPath);

        PublicAdditionalLibraries.Add("~~~.lib");

        string DllName = "~~~.dll";
        PublicDelayLoadDLLs.Add(DllName);
        RuntimeDependencies.Add(LibraryPath + DllName);

        //brandon : Build 시 로그 남음
        //System.Console.WriteLine("SomeSDK ModuleDirectory: {0}", LibraryPath);



5. BKPluginActor 추가 코딩 및 세팅

thirdparty 의 .h 파일을 인클루드
필요한 로직 구현한다.
엔진에서 BKPluginActor 를 상송받는 BKPluginActorBP 만들어서 맵에 배치하여 사용


6. 1에서 생성된 BKPlugin.h 와 BKPlugin.cpp 수정 작업

BKPlugin.h 에
#include "Paths.h"
#include "PlatformProcess.h"
추가


BKPlugin.cpp 의 StartupModule() 에
FString LibraryPath = FPaths::ProjectPluginsDir() / TEXT("BKPlugin/Source/ThirdParty/SomeSDK/lib");

FString filePath = LibraryPath / TEXT("~~~.dll");
UE_LOG(LogTemp, Warning, TEXT("SomeSDK DLL: %s"), *filePath);

if (FPaths::FileExists(filePath))
{
DLLHandle = FPlatformProcess::GetDllHandle(*filePath);
}
추가

ShutdownModule() 에
FPlatformProcess::FreeDllHandle(DLLHandle);
추가

댓글 없음:

댓글 쓰기