I have been trying to link a test file (TestIntstantiator.cpp) to a library for a while, i’ve tried using add_subdirectories and multiple libraries but this just confused me (and the compiler). I am now trying to do it in the simplest way possible, but still coming across problems.
This is my CmakeLists file:
cmake_minimum_required(VERSION 3.9.1)
project(Icicle)
set(CMAKE_CXX_FLAGS "-Wall")
# check OS
# UNIX, WIN32, WINRT, CYGWIN, APPLE are environment variables as flags set by default system
if(UNIX)
message("This is a ${CMAKE_SYSTEM_NAME} system")
elseif(WIN32)
message("This is a Windows System")
endif()
if (NOT CMAKE_BUILD_TYPE)
# CMake defaults to leaving CMAKE_BUILD_TYPE empty. This screws up
# differentiation between debug and release builds.
set(CMAKE_BUILD_TYPE "None" CACHE STRING "Choose the type of build, options are: None (CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release" FORCE)
endif ()
# Specify build paths
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin")
#cmake_policy(SET CMP0079 NEW)
add_executable(TestInstantiator Tests/Main/TestInstantiator.cpp )
file(GLOB HEADER_FILES $(CMAKE_SOURCE_DIR)/Main/src/*.h)
list(APPEND HEADER_FILES
"${CMAKE_SOURCE_DIR}/Main/Math/IcicleMath.h"
"${CMAKE_SOURCE_DIR}/Main/Memory/Allocator.h"
"${CMAKE_SOURCE_DIR}/Main/Memory/StackAllocator.h"
"${CMAKE_SOURCE_DIR}/Main/Memory/MemoryManager.h"
"${CMAKE_SOURCE_DIR}/Main/Resources/Resource.h"
)
file(GLOB SOURCE_FILES $(CMAKE_SOURCE_DIR)/Main/src/*.cpp)
list(APPEND SOURCE_FILES
"${CMAKE_SOURCE_DIR}/Main/Math/IcicleMath.cpp"
"${CMAKE_SOURCE_DIR}/Main/Memory/Allocator.cpp"
"${CMAKE_SOURCE_DIR}/Main/Memory/StackAllocator.cpp"
"${CMAKE_SOURCE_DIR}/Main/Memory/MemoryManager.cpp"
)
add_library(IcicleMain SHARED ${HEADER_FILES} ${SOURCE_FILES})
install(FILES ${HEADER_FILES} DESTINATION include/Icicle)
add_executable(Test "Tests/Main/TestInstantiator.cpp")
target_include_directories(Test PRIVATE
"${CMAKE_SOURCE_DIR}/Main/src"
"${CMAKE_SOURCE_DIR}/Main/Math"
"${CMAKE_SOURCE_DIR}/Main/Memory"
"${CMAKE_SOURCE_DIR}/Main/Resources")
link_directories(Test)
target_link_libraries(Test IcicleMain)
# target_link_libraries(TestInstantiator vtkCommon)
add_test(NAME TestInstantiator
COMMAND TestInstantiator)
There is not enough information in this to help you. You need to figure out where StackAllocator::StackAllocator and Icicle::MemoryManager::~MemoryManager are defined in the source code. This could be a C++ issue and not a build system issue.