I have a simple c++ program with following structure. I use cmake in visual studio to build it.
Project Description:
- There is a root level which has main file named module.cpp along with module.h.
- Root has a subfolder src which has two other folders iMath and utils.
- utils folder has a myprint.h as well as myprint.cpp
- iMath is built as library. it has 2 folders inside it, include folder has a header file addition.h while src folder has a addition.cpp.
Problem detail:
When iMath is build as a static library, it builds well. However, when it is built as shared library, it results in LNK1104 cannot open file src\iMath\MathLib.lib error.
CMakeLists.txt at Root level:
cmake_minimum_required (VERSION 3.8)
project (module4)
set(UTILS_SOURCE_DIR ${CMAKE_SOURCE_DIR}/src/utils)
# add subdirectory
add_subdirectory(src)
# Add source to this project's executable.
add_executable (
calculator
module.cpp
${UTILS_SOURCE_DIR}/myprint.cpp
)
target_include_directories(calculator PUBLIC ${UTILS_SOURCE_DIR})
target_link_libraries(calculator PUBLIC iMathLib)
CmakeLists.txt at src level:
cmake_minimum_required (VERSION 3.8)
add_subdirectory(iMath)
CMakeLists.txt at iMath level:
cmake_minimum_required (VERSION 3.8)
project(iMath)
set(SRC_FILES src/addition.cpp )
add_library(iMathLib SHARED ${SRC_FILES})
target_include_directories(iMathLib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
module.h at ROOT level
#pragma once
#include <iostream>
#include <string>
#include "addition.h"
#include "myprint.h"
In the last CMakeLists.txt at iMATH level, if i switch SHARED TO STATIC, everything works well.
Can someone please point me in the right direction as to what should i change so that it builds with iMath as shared as well?