0

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'.
  • not sure why the problem is happening, but what if you instead `add_library(libconfigcxx STATIC IMPORTED)` and then set its imported location as described in [the docs](https://cmake.org/cmake/help/latest/command/add_library.html#imported-libraries)? – starball Mar 10 '23 at 18:48
  • I tried and still got the same error unfortunately. – Dominic Sesto Mar 10 '23 at 18:58
  • 1
    Looks like the file `libconfig++_d.lib` is not a static library but the **export** file for a shared library (`.dll`). With `lib /list libconfig++_d.lib` you could determine the actual nature of the file: https://stackoverflow.com/a/6403559/3440745 – Tsyvarev Mar 10 '23 at 19:06
  • ah ok, when I do that it lists ```libconfig++_d.dll``` 50-ish times. So I need to link in the ```.dll``` as well? What are my options? – Dominic Sesto Mar 10 '23 at 19:18
  • so you knew there was a DLL but thought it was a static library? In Windows, a DLL always has a corresponding .lib file (import library). https://learn.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-creation#creating-an-import-library – starball Mar 10 '23 at 19:42

0 Answers0