Context
I am trying to set an environnement where I can get all my dependencies easily as I could do using something like Gradle. I wanted to stick with CMake though.
It led me to this Cmake dependencies manager on GitHub. It works perfectly fine for some things like json for modern c++ (See CMakeList.txt bellow)
I am trying to create an application receiving binary data which I will parse. After that, I must use the Open CASCADE library (OCCT github) to generate a geometric shape out of it. The shapes’ vertices and indices will be sent back afterwards.
I had a first version of the application working. I first built Open CASCADE on my computer and linked in manually in Visual Studio using hard coded paths. Since this application will be used in a micro-services docker environnement, I needed to find a more modular solution.
The problem
CPM seemed to work out perfectly fine with OpenCascade using this code :
CPMAddPackage(
NAME OpenCASCADE
VERSION 7.8.1
URL https://github.com/Open-Cascade-SAS/OCCT/releases/download/V7_8_0/occt-vc143-64.zip
)
if (OpenCASCADE_ADDED)
add_library(OpenCASCADE INTERFACE IMPORTED)
target_include_directories(OpenCASCADE INTERFACE ${OpenCASCADE_SOURCE_DIR}/inc)
target_link_libraries(${APP_NAME} PRIVATE OpenCASCADE)
message(STATUS "OpenCASCADE added : ${OpenCASCADE_SOURCE_DIR}/inc")
endif()
Open Cascade includes works fine as long as I stay in my code editor. No errors. But when I try to build the project …
10:18:14:710 2> Creating library C:/[root]/workspaces/GLTF_GENERATOR/GLTF_APP/build/Debug/GLTF_APP.lib and object C:/[root]/workspaces/GLTF_GENERATOR/GLTF_APP/build/Debug/GLTF_APP.exp
10:18:14:783 2>FileExporter.obj : error LNK2001: unresolved external symbol "public: __cdecl Standard_OutOfMemory::Standard_OutOfMemory(char const * const)" (??0Standard_OutOfMemory@@QEAA@QEBD@Z)
10:18:14:783 2>Node.obj : error LNK2001: unresolved external symbol "public: __cdecl Standard_OutOfMemory::Standard_OutOfMemory(char const * const)" (??0Standard_OutOfMemory@@QEAA@QEBD@Z)
10:18:14:783 2>NodeManager.obj : error LNK2001: unresolved external symbol "public: __cdecl Standard_OutOfMemory::Standard_OutOfMemory(char const * const)" (??0Standard_OutOfMemory@@QEAA@QEBD@Z)
I only posted a few but the error list is really long.
Here’s the whole CMakeList.txt
cmake_minimum_required (VERSION 3.28.0 FATAL_ERROR)
set(APP_NAME "GLTF_APP")
project (${APP_NAME} CXX)
set(CMAKE_CXX_STANDARD 20)
# --- C++ Preprocessor Definitions --------------------------------------
add_compile_definitions($<$<CONFIG:DEBUG>:_DEBUG> $<$<NOT:$<CONFIG:DEBUG>>:NDEBUG>)
# -----------------------------------------------------------------------
# --- Add source files & Executable -------------------------------------
set (SRC src/main.cpp src/Coordinator.cpp
src/Data/JsonInterpreter.cpp
src/Render/Viewer.cpp src/Render/ViewerInteractor.cpp
src/FileManagement/FileExporter.cpp
src/Nodes/Node.cpp src/Nodes/NodeManager.cpp)
set (HDR src/Coordinator.h src/Utility.h
src/Data/JsonInterpreter.h
src/Render/Viewer.h src/Render/ViewerInteractor.h
src/FileManagement/FileExporter.h
src/Nodes/Node.h src/Nodes/NodeManager.h)
add_executable (${APP_NAME} ${SRC} ${HDR})
# -----------------------------------------------------------------------
# ==== Add dependencies via CPM ==========================================
# see https://github.com/TheLartians/CPM.cmake for more info
include(cmake/CPM.cmake)
# --- CPM: Add nlohmann_json --------------------------------------------
# the git repo is incredibly large, so we download the archived include directory
CPMAddPackage(
NAME nlohmann_json
VERSION 3.7.3
URL https://github.com/nlohmann/json/releases/download/v3.7.3/include.zip
URL_HASH SHA256=87b5884741427220d3a33df1363ae0e8b898099fbc59f1c451113f6732891014
)
if (nlohmann_json_ADDED)
add_library(nlohmann_json INTERFACE IMPORTED)
target_include_directories(nlohmann_json INTERFACE ${nlohmann_json_SOURCE_DIR}/include)
target_link_libraries(${APP_NAME} PRIVATE nlohmann_json)
message(STATUS "nlohmann_json added : ${nlohmann_json_SOURCE_DIR}/include")
endif()
# -----------------------------------------------------------------------
# --- CPM : Add Open CASCADE --------------------------------------------
CPMAddPackage(
NAME OpenCASCADE
VERSION 7.8.1
URL https://github.com/Open-Cascade-SAS/OCCT/releases/download/V7_8_0/occt-vc143-64.zip
)
if (OpenCASCADE_ADDED)
add_library(OpenCASCADE INTERFACE IMPORTED)
target_include_directories(OpenCASCADE INTERFACE ${OpenCASCADE_SOURCE_DIR}/inc)
target_link_libraries(${APP_NAME} PRIVATE OpenCASCADE)
message(STATUS "OpenCASCADE added : ${OpenCASCADE_SOURCE_DIR}/inc")
endif()
# -----------------------------------------------------------------------
# --- Add include directories -------------------------------------------
target_include_directories(${APP_NAME} PRIVATE src)
# -----------------------------------------------------------------------
From what I was able to investigate, it might come from the fact that the ‘Additional Dependencies’ property wasn’t populated by all OpenCascade dlls. I tried to use the method used in this tutorial (the foreach loop). The tutorial guy was also building Open CASCADE manually .. But the OpenCASCADE_LIBRARIES
variable is empty using the CPM method.
I actually wonder if it can come from the way I import the library (maybe a misconception in the PUBLIC|PRIVATE|INTERFACE
keywords
Summary of the problem
How can I correctly import the Open CASCADE library using the CPM depencies manager ?
Let me know if you need more informations.
Thomas is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.