I am trying to develop a basic C++ application with multifile programming. I use Cmake to help build a Header file's implementation in the .cpp as a shared library (.dll) in a folder to contain it. and the exe resides in the parent folder of the build. How do I setup my program on Windows to have the exe know to search in the folder for the dll to run the application. I see many professional software have the exe in the parent folder and the dlls stored away in organized folders and the exe can find them. How do they accomplish this?
cmake_minimum_required(VERSION 3.26)
project(mathlearning)
#Compiler options for better debugging
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -g")
add_subdirectory(math_lib)
add_subdirectory(print_lib)
add_executable(mathlearning main.cpp)
target_link_libraries(mathlearning math_lib print_lib)
My main cmake file looks like that. I have two more folders, math_lib (static linked) and print_lib (dynamic linked). The dynamic linked can only be found when I place it in the same folder as the exe. But I want it to be organized in its own folder like much of the professional software I use.
My file/folder structure Inside the math_lib folder
Cmake code inside math_lib:
add_library(math_lib STATIC math_lib.cpp)
Cmake code inside the print_lib:
add_library(print_lib SHARED print_lib.cpp)
target_link_libraries(print_lib math_lib) #This shared library depends on the static library
What am I doing wrong?