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
and here's my project configuration:
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).
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