Linking Static libconfig Library to Example Program using CMake in Visual Studio

33 views Asked by At

I am attempting to compile an example program using a static library libconfig++_d.lib with CMake in Visual Studio 2019.

I was able to properly build and link my example program using CMake. However, when I go to run the executable, I get an error:

LIB_LINK.exe - System Error The code execution cannot proceed because libconfig++_d.dll was not found. Reinstalling the program may fix this problem.

In the CMake file, I linked a static library .lib. Why is the executable looking for a dynamically linked library .dll? Are the static library file and the associated header files all I need to properly link?

Here is my CMake file:

cmake_minimum_required(VERSION 3.10)

project(LIB_LINK)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)

add_executable(LIB_LINK "example1.cpp")

target_compile_definitions(LIB_LINK PUBLIC LIBCONFIGXX_STATIC)
target_include_directories(LIB_LINK PUBLIC ${CMAKE_SOURCE_DIR}/libconfig/lib)
target_link_libraries(LIB_LINK ${CMAKE_SOURCE_DIR}/libconfig/libconfig++_d.lib)

example1.cpp:

#include <iostream>
#include <iomanip>
#include <cstdlib>
#include "libconfig.h++"

using namespace std;
using namespace libconfig;

// This example reads the configuration file 'example.cfg'
int main(int argc, char** argv)
{
    (void)argc;
    (void)argv;

    Config cfg;

    // Read the file. If there is an error, report it and exit.
    try
    {
        cfg.readFile("example.cfg");
    }
    catch (const FileIOException& fioex)
    {
        std::cerr << "I/O error while reading file." << std::endl;
        return(EXIT_FAILURE);
    }

    return(EXIT_SUCCESS);
}

Here is the Debug output:

'LIB_LINK.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ntdll.dll'. 
'LIB_LINK.exe' (Win32): Loaded 'C:\Windows\SysWOW64\kernel32.dll'. 
'LIB_LINK.exe' (Win32): Loaded 'C:\Windows\SysWOW64\KernelBase.dll'. 
The thread 0x329c has exited with code -1073741515 (0xc0000135).
The thread 0x62d8 has exited with code -1073741515 (0xc0000135).
The program '[18412] LIB_LINK.exe' has exited with code -1073741515 
(0xc0000135) 'A dependent dll was not found'.
0

There are 0 answers