나는 지난 며칠 동안이 문제에 대해 머리를 두들겨 왔습니다 (내 repo는 아래에 링크되어 있습니다). CMake가 Engine 프로젝트가 Demo 프로젝트에 연결된 MSVC 솔루션을 생성하기를 원합니다. .lib 및 .dll 파일이 올바르게 생성되어 MSVC의 프로젝트에 추가되었지만 Engine 프로젝트의 기호를 참조하는 데모 프로젝트에서 여전히 해결되지 않은 링커 기호 오류가 발생합니다. Engine.lib 파일이 Demo의 종속성에 올바르게 추가되었으며 헤더도 마찬가지입니다. 생성 된 내 보낸 헤더를 사용해야하는 전역이 없습니다. 여기서 문제는 무엇입니까?
루트 CMakeLists.txt :
cmake_minimum_required(VERSION 3.12)
project(P_SentryAll)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
include(GenerateExportHeader)
# glob source and header files
file(GLOB_RECURSE EngineSources SENTRY.Engine/*.cpp SENTRY.Engine/*.hpp)
file(GLOB_RECURSE CoreSources SENTRY.Core/*.cpp SENTRY.Core/*.hpp)
file(GLOB_RECURSE RenderSources SENTRY.Render/*.cpp SENTRY.Render/*.hpp)
file(GLOB_RECURSE DemoSources SENTRY.Demo/*.cpp SENTRY.Demo/*.hpp)
file(GLOB_RECURSE EngineHeaders SENTRY.Engine/*.hpp)
file(GLOB_RECURSE CoreHeaders SENTRY.Core/*.hpp)
add_subdirectory(SENTRY.Core)
add_subdirectory(SENTRY.Engine)
add_subdirectory(SENTRY.Render)
add_subdirectory(SENTRY.Demo)
Root / Sentry.Core / CMakeLists.txt :
cmake_minimum_required(VERSION 3.12)
# define project
project(P_SentryCore)
add_library(SentryCore SHARED ${CoreSources})
target_include_directories(SentryCore PUBLIC src/module)
generate_export_header(SentryCore)
install(TARGETS SentryCore DESTINATION lib)
install(FILES ${CoreHeaders} DESTINATION include/SentryCore)
Root / Sentry.Engine / CMakeLists.txt :
cmake_minimum_required(VERSION 3.12)
project(P_SentryEngine)
add_library(SentryEngine SHARED ${EngineSources})
target_link_libraries(SentryEngine PUBLIC SentryCore)
target_include_directories(SentryEngine PUBLIC src/engine)
generate_export_header(SentryEngine)
install(TARGETS SentryEngine DESTINATION lib)
install(FILES ${EngineHeaders} DESTINATION include/SentryEngine)
Root / Sentry.Demo / CMakeLists.txt :
cmake_minimum_required(VERSION 3.12)
# define project
project(P_SentryDemo)
add_executable(SentryDemo ${DemoSources})
target_link_libraries(SentryDemo PUBLIC SentryEngine)
include_directories(SENTRY.Engine/src/engine SENTRY.Core/src/module)
# packaging
install(TARGETS SentryDemo DESTINATION build)
오류:
1>------ Build started: Project: ZERO_CHECK, Configuration: Debug x64 ------
2>------ Build started: Project: SentryEngine, Configuration: Debug x64 ------
2>Engine.cpp
2>Auto build dll exports
2> Creating library C:/Users/main/Desktop/Projects/SENTRY/Build/SENTRY.Engine/Debug/SentryEngine.lib and object C:/Users/main/Desktop/Projects/SENTRY/Build/SENTRY.Engine/Debug/SentryEngine.exp
2>SentryEngine.vcxproj -> C:\Users\main\Desktop\Projects\SENTRY\Build\SENTRY.Engine\Debug\SentryEngine.dll
3>------ Build started: Project: SentryDemo, Configuration: Debug x64 ------
3>SENTRY.Demo.obj : error LNK2019: unresolved external symbol "public: void __cdecl Engine<__int64,struct std::ratio<1,1000000> >::Init(void)" (?Init@?$Engine@_JU?$ratio@$00$0PECEA@@std@@@@QEAAXXZ) referenced in function main
3>SENTRY.Demo.obj : error LNK2019: unresolved external symbol "public: void __cdecl Engine<__int64,struct std::ratio<1,1000000> >::Run(void)" (?Run@?$Engine@_JU?$ratio@$00$0PECEA@@std@@@@QEAAXXZ) referenced in function main
3>SENTRY.Demo.obj : error LNK2019: unresolved external symbol "public: void __cdecl Engine<__int64,struct std::ratio<1,1000000> >::RegisterModule(class Module<__int64,struct std::ratio<1,1000000> > *)" (?RegisterModule@?$Engine@_JU?$ratio@$00$0PECEA@@std@@@@QEAAXPEAV?$Module@_JU?$ratio@$00$0PECEA@@std@@@@@Z) referenced in function main
3>C:\Users\main\Desktop\Projects\SENTRY\Build\SENTRY.Demo\Debug\SentryDemo.exe : fatal error LNK1120: 3 unresolved externals
3>Done building project "SentryDemo.vcxproj" -- FAILED.
4>------ Skipped Build: Project: INSTALL, Configuration: Debug x64 ------
4>Project not selected to build for this solution configuration
========== Build: 2 succeeded, 1 failed, 2 up-to-date, 1 skipped ==========
라인 Root/Sentry.Demo/CMakeLists.txt
:
include_directories(SENTRY.Engine/src/engine SENTRY.Core/src/module)
잘못된 것 같습니다. 상대 경로를 사용하므로 프로젝트에서 유효한 경로라고 생각하지 않습니다.
Root/Sentry.Demo/SENTRY.Engine/src/engine
Root/Sentry.Demo/SENTRY.Core/src/module
가능한 경우 변수 를 사용하여 절대 경로를 사용하는 것이 CMAKE_SOURCE_DIR
좋습니다. 이 변수는 최상위 소스 디렉토리의 경로를 제공합니다. 따라서 대신 다음과 같이 시도하십시오.
include_directories(
${CMAKE_SOURCE_DIR}/SENTRY.Engine/src/engine
${CMAKE_SOURCE_DIR}/SENTRY.Core/src/module
)
리포지토리를 다시 살펴 봤는데 더 중요한 것은 소스 파일이 아닌 헤더 파일 에 템플릿 함수 의 전체 정의가 있어야한다는 것 입니다.Engine
따라서 이러한 함수 정의를 Engine
클래스 정의 내에서 헤더 파일로 이동하십시오 .
template<typename T_rep, typename T_ratio>
void Engine<T_rep, T_ratio>::Init()
{
for (auto& module_ : Modules)
{
module_->Init();
}
}
template<typename T_rep, typename T_ratio>
void Engine<T_rep, T_ratio>::Run()
{
RunUpdateLoop = true;
auto TPStart = std::chrono::steady_clock::now();
auto TPEnd = TPStart;
while (RunUpdateLoop)
{
auto deltaT = TPEnd - TPStart;
TPStart = std::chrono::steady_clock::now();
for (auto& module_ : Modules)
{
module_->Run((deltaT));
}
TPEnd = std::chrono::steady_clock::now();
}
}
template<typename T_rep, typename T_ratio>
void Engine<T_rep, T_ratio>::RegisterModule(Module<T_rep, T_ratio>* ToRegister)
{
Modules.push_back(ToRegister);
}
이것은 당신이 올바른 길로 나아가는 데 도움이 될 것입니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다