🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

New to cmake+clang and getting linking errors

Started by
0 comments, last by cignox1 3 years, 4 months ago

Hello all,

I decided it was about time to create a new project to host my 10+ years old path tracer source files (have not worked on it for 10 years, the project was a mess) and thought it was a good idea to move to cmake, which I have never used before. I'm also using Clang.
I got all the external libraries (freeimage, assimp, sdl) via vcpkg and managed to create a very simple cmake project in Visual Studio, fixed the compilation errors (i.e got rid of the thread/shared_ptr dependency from boost) etc.

Unfortunately, the linker reports:

>>> CMakeFiles\QuarkLight.dir\src\quarklight.cpp.obj has value MDd_DynamicDebug

>>> assimp-vc142-mtd.lib(Importer.cpp.obj) has value MTd_StaticDebug

ninja: build stopped: subcommand failed.

I've spent a few hours trying to figure out how to set the static runtime using cmake+clang without success. AFAIK, that should be the default setting. This is my cmakelists.txt file:

# CMakeList.txt: progetto CMake per QuarkLight. Includere l'origine e definire
# qui la logica specifica del progetto.
#
cmake_minimum_required (VERSION 3.8)

set(CMAKE_TOOLCHAIN_FILE "C:/Users/Alessandro/Documents/workspace/vcpkg/scripts/buildsystems/vcpkg.cmake" CACHE STRING "")
set(VCPKG_TARGET_TRIPLET "x64-windows-static" CACHE STRING "")
set(TARGET_QUARKLIGHT "QuarkLight")

project (${TARGET_QUARKLIGHT})

# Add source files
file(GLOB_RECURSE SOURCE_FILES  
${CMAKE_SOURCE_DIR}/src/*.c
${CMAKE_SOURCE_DIR}/src/*.cpp)
 
# Add header files
file(GLOB_RECURSE HEADER_FILES  
${CMAKE_SOURCE_DIR}/src/inlcude/*.h
${CMAKE_SOURCE_DIR}/src/include/*.hpp)

# Add .lib files
link_directories(${CMAKE_SOURCE_DIR}/lib)

# Aggiungere l'origine all'eseguibile di questo progetto.
#add_executable (QuarkLight "QuarkLight.cpp" "QuarkLight.h"  "src/quarklight.cpp" "src/qltexture.cpp" "src/qlshape.cpp" "src/qlsampling.cpp" "src/qlrenderer.cpp" "src/qlprimitives.cpp" "src/qlmaterial.cpp" "src/qllight.cpp" "src/qlgeometry.cpp")
add_executable(${PROJECT_NAME} ${HEADER_FILES} ${SOURCE_FILES})

set_property(TARGET ${TARGET_QUARKLIGHT} PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
add_compile_options(/MT)

find_package(assimp CONFIG REQUIRED)
target_link_libraries(${TARGET_QUARKLIGHT} PRIVATE assimp::assimp)

find_package(SDL2 CONFIG REQUIRED)
target_link_libraries(${TARGET_QUARKLIGHT} PRIVATE SDL2::SDL2main SDL2::SDL2-static)

find_package(freeimage CONFIG REQUIRED)
target_link_libraries(${TARGET_QUARKLIGHT} PRIVATE freeimage::FreeImage freeimage::FreeImagePlus)

# Define the include DIRs
include_directories(
"${CMAKE_SOURCE_DIR}/src"
"${CMAKE_SOURCE_DIR}/include"
)

target_compile_features(${TARGET_QUARKLIGHT} PRIVATE cxx_std_17)

Please remember that this is my first attempt with cmake :D

Any idea? Thank you!

This topic is closed to new replies.

Advertisement