I am not able to build a sample file using XLNT library

37 Views Asked by At

I am trying to build a simple C++ program with xlnt with GNU compiler and Visual Studio Code IDE. I have had some challenges with getting the build environment to include the xlnt libraries, and the problem may be related to that. The program is below:

#include <xlnt/xlnt.hpp>

int main() {
    // Create a new workbook and load an existing file
    xlnt::workbook wb;            // <---- this is line 6, which is causing the error (below)
    try {
        wb.load("example.xlsx");
    } catch (const std::exception& e) {
        std::cerr << "Error loading file: " << e.what() << std::endl;
        return 1;
    }
    return 0;
}

I am getting the following output (partial):

[build] [ 50%] Building CXX object CMakeFiles/ExcelAccess.dir/src/ExcelAccess.cpp.obj

[build] [100%] Linking CXX executable ExcelAccess.exe

[build] C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\ExcelAccess.dir/objects.a(ExcelAccess.cpp.obj): in function `main':

[build] C:/Users/Public/Documents/Excel/src/ExcelAccess.cpp:6:(.text+0x19): undefined reference to `xlnt::workbook::workbook()'

[build] C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/Public/Documents/Excel/src/ExcelAccess.cpp:8:(.text+0x4d): undefined reference to `xlnt::workbook::load(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&)'

Any ideas how to resolve the error: undefined reference to `xlnt::workbook::workbook()'?

xlnt previously built, with the following output:

[main] Building folder: xlnt

[build] Starting build

[proc] Executing command: chcp

[proc] Executing command: "C:\Program Files\CMake\bin\cmake.EXE" -- build c:/xlnt/xlnt/build --config Debug --target all -j 42 --

[build] [ 11%] Built target libstudxml

[build] [100%] Built target xlnt

[driver] Build completed: 00:00:00.909

[build] Build finished with exit code 0

0

There are 0 best solutions below