1

For two days I have spent several hours trying to get libxlsxwriter to work with mingw on Windows. I followed the instructions to install and build the library, but every time I attempt to include the header files in one of my projects and use one of the function in the library, I end up getting the same error:

D:\Apps\CLion\bin\cmake\win\bin\cmake.exe --build C:\Users\Simon\CLionProjects\myexcel\cmake-build-debug --target all -- -j 4
[ 50%] Linking CXX executable myexcel.exe
D:/Apps/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\myexcel.dir/objects.a(main.cpp.obj): in function `main':
C:/Users/Simon/CLionProjects/myexcel/main.cpp:4: undefined reference to `workbook_new'
D:/Apps/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/Simon/CLionProjects/myexcel/main.cpp:5: undefined reference to `workbook_add_worksheet'
D:/Apps/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/Simon/CLionProjects/myexcel/main.cpp:8: undefined reference to `worksheet_write_string'
D:/Apps/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/Simon/CLionProjects/myexcel/main.cpp:9: undefined reference to `workbook_close'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[2]: *** [CMakeFiles\myexcel.dir\build.make:85: myexcel.exe] Error 1
mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:75: CMakeFiles/myexcel.dir/all] Error 2
mingw32-make.exe: *** [Makefile:83: all] Error 2

My code is very basic (it's pretty much one of the sample codes provided):

#include "xlsxwriter.h"

int main() {
    lxw_workbook  *workbook  = workbook_new("myexcel.xlsx");
    lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
    int row = 0;
    int col = 0;
    worksheet_write_string(worksheet, row, col, "Hello me!", NULL);
    return workbook_close(workbook);
}

I have tried several ways to get deploy mingw, but I've ultimately settled for msys2 as a platform to host mingw as I feel the *nix environments are beneficial when it comes to managing a multitude of packages and it comes with the needed zlib preinstalled.

For all it'S worth here's my toolchain configuration in CLion 2019.3

enter image description here

and here's my project configuration:

enter image description here

Any ideas what's wrong here? I am a newby as it relates to C/C++... help is very much appreciated!


EDIT:

I've tried to install the built files from the mys2 console with pacman pacman -Ss xlsx. From what it looks like, it's already installed. This is the output of the console:

$ pacman -Ss xlsx
mingw32/mingw-w64-i686-libxlsxwriter 0.9.4-1
    A C library for creating Excel XLSX files (mingw-w64)
mingw32/mingw-w64-i686-python-openpyxl 3.0.2-1
    A python library to read/write Excel 2007 xlsx/xlsm file (mingw-w64)
mingw32/mingw-w64-i686-python-xlsxwriter 1.2.7-1
    A Python module for creating Excel XLSL files (mingw-w64)
mingw32/mingw-w64-i686-xlnt 1.4.0-1
    User-friendly xlsx library for C++14 (mingw-w64)
mingw64/mingw-w64-x86_64-libxlsxwriter 0.9.4-1
    A C library for creating Excel XLSX files (mingw-w64)
mingw64/mingw-w64-x86_64-python-openpyxl 3.0.2-1
    A python library to read/write Excel 2007 xlsx/xlsm file (mingw-w64)
mingw64/mingw-w64-x86_64-python-xlsxwriter 1.2.7-1
    A Python module for creating Excel XLSL files (mingw-w64)
mingw64/mingw-w64-x86_64-xlnt 1.4.0-1
    User-friendly xlsx library for C++14 (mingw-w64)

I don't get it, frankly. There is no libxlsxwriter.so anywhere. I have the two files (libxlsxwriter.a, libxlsxwriter.dll) in the usr/local folder and in the home folder (where they have been built originally).

  • I don't know about your IDE but it seems you aren't building the xlsxwriter library – M.M Jan 27 '20 at 01:55
  • MSYS2 includes libxlsxwriter as a package (`pacman -Ss xlsx`) so you could install that rather than trying to build it – M.M Jan 27 '20 at 01:58
  • Seems you are right. I've got these two files built: libxlsxwriter.a, libxlsxwriter.dll No signs of a libxlsxwriter.so, which should be there, according to the manual. Is this correct? I will try your suggested solution and report back –  Jan 27 '20 at 04:59
  • I atttempted you solution and edited my post. Still nothing, unfortunately –  Jan 27 '20 at 05:15
  • There are no `.so` files in Windows. You should link against the `.a` file – M.M Jan 27 '20 at 07:01
  • Did you set up your project to *link* with `libxlsxwriter.a`? – the busybee Jan 27 '20 at 07:47
  • Could you tell me exactly how this linking is done? I would love to try that one out. I thought I merely had to include the header file(s) (`#include "xlsxwriter.h"`) in the .cpp file. –  Jan 27 '20 at 08:05
  • maybe check CLion or cmake documentation for how to link against a library – M.M Jan 27 '20 at 08:39
  • .so is a dynamic library used on Linux. – Sergio Jan 09 '22 at 12:32

1 Answers1

2

You can find the libxlsxwriter library as Msys2 package and install them using (from MinGW 64 shell) the following command:
pacman -S mingw-w64-x86_64-libxlsxwriter

Sergio
  • 891
  • 9
  • 27