Unresolved external symbols when building project with Cmake fetched dependencies

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.

New contributor

Thomas is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật