Running libxlsxwriter on Windows

2019-07-13 03:03发布

问题:

I am trying to use libxlsxwriter, but I can seem to get things to compile or run correctly.

I followed the directions for Windows using Mingw-w64 and msys2 available here: http://libxlsxwriter.github.io/getting_started.html.

I installed msys2 from their website and updated everything using pacman -Syu. Then I installed zlib with the recommended:

# Install the dev tools for libxlsxwriter.
pacman -S git gcc make zlib-devel

Then I run the code to download and compile libxlswriter:

# Clone and build libxlsxwriter.
git clone https://github.com/jmcnamara/libxlsxwriter.git
cd libxlsxwriter/
make
make install
# run example
cd ..
cc myexcel.c -o myexcel -lxlsxwriter -lz

Now there is an executable named myexcel which should create an basic excel document, but when I double click it I get the errors:

The program can't start because msys-2.0.dll is missing from your computer.

I also get the error for missing msys-z.dll

I'm not sure what I did wrong or how to fix it.

Any help would be appreciated

edit:

if I run:

make examples
./examples/hello

The hello world example successfully runs so things seem to be installed properly. I guess I just don't understand how to get it to run a user made .c

回答1:

MSYS console defines the path to MSYS commands & DLLs when opening the console: ex if MSYS is installed in C:\msys64 it locally adds the path to C:\msys64\usr\bin but it does not add it to the Windows system PATH.

So if you click on the executable outside MSYS, it cannot find the DLLs because they are not in windows PATH.

many solutions:

1) add C:\msys64\usr\bin in user or computer PATH (edit environment variables). As a bonus you gain access to commands like grep in your windows CMD. As a drawback, there can be mixups/conflicts with commands like find or sort.

or

2) create a myexcel.bat file containing the following in your executable directory:

@echo off
set PATH=C:\msys64\usr\bin;%PATH%
%~PD0\myexcel.exe

(%~PD0 prefix allows to find the executable from the .bat path so if .bat file is run from another directory it still finds the executable)

3) copy the MSYS DLLs where your executable resides. Since the DLLs are in the same directory as the .exe Windows will find them. Recommended for a standalone distribution, not for personal use since it creates a lot of copies.

4) static linkage against MSYS .a libs. I don't know if this can be done for all libs. Cannot seem to find libz.a for instance.