본문 바로가기
UnrealEngine

[UE] 외부 라이브러리 사용하기

by 공작사 2023. 8. 20.

프로젝트를 만들다보면 외부 라이브러리를 사용할 때가 있다.

 

원하는 모듈의 .build.cs 파일을 다음과 같이 수정한다.

using System;
using System.IO;
using UnrealBuildTool;

public class MyThirdPartyLibrary : ModuleRules
{
    public MyThirdPartyLibrary(ReadOnlyTargetRules Target) : base(Target)
    {
        Type = ModuleType.External;
        
        //	해당 모듈에서 외부 라이브러리를 사용한다고 설정.
        PublicDefinitions.Add("WITH_MYTHIRDPARTYLIBRARY=1");
        
        //	사용할 외부 라이브러리의 .h .lib을 모아놓은 디렉터리 경로
	string thirdPartyPath = Path.Combine(ModuleDirectory, "../../ThirdParty");

	//	Include 할 해더 경로 추가.
        PublicIncludePaths.AddRange(
            new string[]
            {
                Path.Combine(thirdPartyPath, "include"),
            });
            
	//	Static 라이브러리 경로 추가.
        PublicAdditionalLibraries.AddRange(
            new string[]
            {
                Path.Combine(thirdPartyPath, "amd64", "release", "lib", "thirdParty.lib"),
            });
            
        //	Dynamic 라이브러리 경로 추가. dll 경로는 위의 thirdPartyPath에 넣어도 인식되지 않음.
        //	아래와 같이 모듈 바이너리 폴더에 넣어야 한다.
        RuntimeDependencies.Add("$(PluginDir)/Binaries/Win64/thirdParty.dll");
    }
}

 

끝.

댓글