简体   繁体   中英

xlsxwriter installation for C on windows

I am fairly new in C and I am trying to manipulate same data files and export them in an excel file.

Similar to this case Running libxlsxwriter on Windows , I am trying to install libxlsxwriter on windows usingMSYS2.

I have done so far:

1) Installed MSYS2 64 bit along with the installation instructions

2) From MSYS2 terminal pacman -S git gcc make zlib-devel

3) And also:

git clone https://github.com/jmcnamara/libxlsxwriter.git

MichKon@MichKon-PC MSYS ~
$ cd libxlsxwriter

MichKon@MichKon-PC MSYS ~/libxlsxwriter
$ make
make[1]: Entering directory '/home/MichKon/libxlsxwriter/third_party/minizip'
make[1]: Leaving directory '/home/MichKon/libxlsxwriter/third_party/minizip'
make[1]: Entering directory '/home/MichKon/libxlsxwriter/third_party/tmpfileplus'
make[1]: Leaving directory '/home/MichKon/libxlsxwriter/third_party/tmpfileplus'
make[1]: Entering directory '/home/MichKon/libxlsxwriter/src'
make[1]: Leaving directory '/home/MichKon/libxlsxwriter/src'


MichKon@MichKon-PC MSYS ~/libxlsxwriter
$ make install

MichKon@MichKon-PC MSYS ~/libxlsxwriter
$ cc myexcel.c -o myexcel -lxlsxwriter
/usr/lib/../lib/libxlsxwriter.a(zip.o):zip.c:(.text+0x1bc9): undefined reference to `crc32'
/usr/lib/../lib/libxlsxwriter.a(zip.o):zip.c:(.text+0x1bc9): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `crc32'
/usr/lib/../lib/libxlsxwriter.a(zip.o):zip.c:(.text+0x1d1f): undefined reference to `deflate'
/usr/lib/../lib/libxlsxwriter.a(zip.o):zip.c:(.text+0x1d1f): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `deflate'
/usr/lib/../lib/libxlsxwriter.a(zip.o):zip.c:(.text+0x2280): undefined reference to `deflate'
/usr/lib/../lib/libxlsxwriter.a(zip.o):zip.c:(.text+0x2280): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `deflate'
/usr/lib/../lib/libxlsxwriter.a(zip.o):zip.c:(.text+0x238a): undefined reference to `deflateEnd'
/usr/lib/../lib/libxlsxwriter.a(zip.o):zip.c:(.text+0x238a): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `deflateEnd'
/usr/lib/../lib/libxlsxwriter.a(zip.o):zip.c:(.text+0x25e6): undefined reference to `deflateEnd'
/usr/lib/../lib/libxlsxwriter.a(zip.o):zip.c:(.text+0x25e6): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `deflateEnd'
/usr/lib/../lib/libxlsxwriter.a(zip.o):zip.c:(.text+0x2649): undefined reference to `deflateEnd'
/usr/lib/../lib/libxlsxwriter.a(zip.o):zip.c:(.text+0x2649): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `deflateEnd'
/usr/lib/../lib/libxlsxwriter.a(zip.o):zip.c:(.text+0x2e06): undefined reference to `deflateInit2_'
/usr/lib/../lib/libxlsxwriter.a(zip.o):zip.c:(.text+0x2e06): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `deflateInit2_'
collect2: error: ld returned 1 exit status

MichKon@MichKon-PC MSYS ~/libxlsxwriter
$ ./myexcel
bash: ./myexcel: No such file or directory

MichKon@MichKon-PC MSYS ~/libxlsxwriter
$ cc myexcel.c -o myexcel -lxlsxwriter
/usr/lib/../lib/libxlsxwriter.a(zip.o):zip.c:(.text+0x1bc9): undefined reference to `crc32'
/usr/lib/../lib/libxlsxwriter.a(zip.o):zip.c:(.text+0x1bc9): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `crc32'
/usr/lib/../lib/libxlsxwriter.a(zip.o):zip.c:(.text+0x1d1f): undefined reference to `deflate'
/usr/lib/../lib/libxlsxwriter.a(zip.o):zip.c:(.text+0x1d1f): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `deflate'
/usr/lib/../lib/libxlsxwriter.a(zip.o):zip.c:(.text+0x2280): undefined reference to `deflate'
/usr/lib/../lib/libxlsxwriter.a(zip.o):zip.c:(.text+0x2280): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `deflate'
/usr/lib/../lib/libxlsxwriter.a(zip.o):zip.c:(.text+0x238a): undefined reference to `deflateEnd'
/usr/lib/../lib/libxlsxwriter.a(zip.o):zip.c:(.text+0x238a): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `deflateEnd'
/usr/lib/../lib/libxlsxwriter.a(zip.o):zip.c:(.text+0x25e6): undefined reference to `deflateEnd'
/usr/lib/../lib/libxlsxwriter.a(zip.o):zip.c:(.text+0x25e6): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `deflateEnd'
/usr/lib/../lib/libxlsxwriter.a(zip.o):zip.c:(.text+0x2649): undefined reference to `deflateEnd'
/usr/lib/../lib/libxlsxwriter.a(zip.o):zip.c:(.text+0x2649): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `deflateEnd'
/usr/lib/../lib/libxlsxwriter.a(zip.o):zip.c:(.text+0x2e06): undefined reference to `deflateInit2_'
/usr/lib/../lib/libxlsxwriter.a(zip.o):zip.c:(.text+0x2e06): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `deflateInit2_'
collect2: error: ld returned 1 exit status

MichKon@MichKon-PC MSYS ~/libxlsxwriter
$ ./myexcel
bash: ./myexcel: No such file or directory

MichKon@MichKon-PC MSYS ~/libxlsxwriter
$ xdg-open myexcel.xlsx
bash: xdg-open: command not found

MichKon@MichKon-PC MSYS ~/libxlsxwriter
$ cc myexcel.c -o myexcel -I /path/to/libxlsxwriter/include
/tmp/ccp8qMT9.o:myexcel.c:(.text+0x15): undefined reference to `workbook_new'
/tmp/ccp8qMT9.o:myexcel.c:(.text+0x15): relocation truncated to fit: R_X86_64_PC 32 against undefined symbol `workbook_new'
/tmp/ccp8qMT9.o:myexcel.c:(.text+0x2a): undefined reference to `workbook_add_worksheet'
/tmp/ccp8qMT9.o:myexcel.c:(.text+0x2a): relocation truncated to fit: R_X86_64_PC 32 against undefined symbol `workbook_add_worksheet'
/tmp/ccp8qMT9.o:myexcel.c:(.text+0x64): undefined reference to `worksheet_write_string'
/tmp/ccp8qMT9.o:myexcel.c:(.text+0x64): relocation truncated to fit: R_X86_64_PC 32 against undefined symbol `worksheet_write_string'
/tmp/ccp8qMT9.o:myexcel.c:(.text+0x70): undefined reference to `workbook_close'
/tmp/ccp8qMT9.o:myexcel.c:(.text+0x70): relocation truncated to fit: R_X86_64_PC 32 against undefined symbol `workbook_close'
collect2: error: ld returned 1 exit status

MichKon@MichKon-PC MSYS ~/libxlsxwriter
$ ./myexcel
bash: ./myexcel: No such file or directory

MichKon@MichKon-PC MSYS ~/libxlsxwriter
$ cc myexcel.c -o myexcel -I /path/to/libxlsxwriter/lib/libxlsxwiter.a -lz
/tmp/ccgsiylm.o:myexcel.c:(.text+0x15): undefined reference to `workbook_new'
/tmp/ccgsiylm.o:myexcel.c:(.text+0x15): relocation truncated to fit: R_X86_64_PC 32 against undefined symbol `workbook_new'
/tmp/ccgsiylm.o:myexcel.c:(.text+0x2a): undefined reference to `workbook_add_worksheet'
/tmp/ccgsiylm.o:myexcel.c:(.text+0x2a): relocation truncated to fit: R_X86_64_PC 32 against undefined symbol `workbook_add_worksheet'
/tmp/ccgsiylm.o:myexcel.c:(.text+0x64): undefined reference to `worksheet_write_string'
/tmp/ccgsiylm.o:myexcel.c:(.text+0x64): relocation truncated to fit: R_X86_64_PC 32 against undefined symbol `worksheet_write_string'
/tmp/ccgsiylm.o:myexcel.c:(.text+0x70): undefined reference to `workbook_close'
/tmp/ccgsiylm.o:myexcel.c:(.text+0x70): relocation truncated to fit: R_X86_64_PC 32 against undefined symbol `workbook_close'
collect2: error: ld returned 1 exit status

MichKon@MichKon-PC MSYS ~/libxlsxwriter
$ make myexcel
cc     myexcel.c   -o myexcel
/tmp/ccMI33kF.o:myexcel.c:(.text+0x15): undefined reference to `workbook_new'
/tmp/ccMI33kF.o:myexcel.c:(.text+0x15): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `workbook_new'
/tmp/ccMI33kF.o:myexcel.c:(.text+0x2a): undefined reference to `workbook_add_worksheet'
/tmp/ccMI33kF.o:myexcel.c:(.text+0x2a): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `workbook_add_worksheet'
/tmp/ccMI33kF.o:myexcel.c:(.text+0x64): undefined reference to `worksheet_write_string'
/tmp/ccMI33kF.o:myexcel.c:(.text+0x64): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `worksheet_write_string'
/tmp/ccMI33kF.o:myexcel.c:(.text+0x70): undefined reference to `workbook_close'
/tmp/ccMI33kF.o:myexcel.c:(.text+0x70): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `workbook_close'

collect2: error: ld returned 1 exit status make: *** [: myexcel] Error 1

MichKon@MichKon-PC MSYS ~/libxlsxwriter
$

So it doesn't seem to work at the end. There is no exe file created. It seems that the last three commands are ordering a compileing, but something is wrong with the header files...

Thank you for your time

EDIT:

So I have looked deeper into this solution: Running libxlsxwriter on Windows as it seems I have a similar problem as Carl.

Make does not work except if I place the .c file inside one of the predefined files like examples, then through the command window I can compile and run it. But I would like to know if there is anything that can be done in order to be able to compile and run the files normally, like any other C files through Devc++.

I tried adding C:\\msys64\\usr\\bin in user and computer PATH (environment variables) but it doesn't seem to work.

Thank you for your time!

It should work according to the instructions . I re-ran them to check and everything worked:

# Install MYSYS2 from http://www.msys2.org/
# For the example below I used msys2-x86_64-20161025.exe

# Run the MYSYS2 Shell and install the dependencies:
$ cd /tmp
$ pacman -S git gcc make zlib-devel

# Clone, make, and install libxlswriter:
$ git clone https://github.com/jmcnamara/libxlsxwriter.git
$ cd libxlsxwriter/
$ make
$ make install

# Create a sample C test file in another directory:
$ cd ..
$ mkdir mytmp
$ cd mytmp
$ vim myexcel.c
$ cat myexcel.c
#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);
}

# Compile and run the application:
$ cc myexcel.c -o myexcel -lxlsxwriter -lz
$ ./myexcel.exe

$ ls -ltr
total 1077
-rw-r--r-- 1 jmcnamara Domain Users     313 Apr  6 19:02 myexcel.c
-rwxr-xr-x 1 jmcnamara Domain Users 1093488 Apr  6 19:03 myexcel.exe
-rw-r--r-- 1 jmcnamara Domain Users    5254 Apr  6 19:03 myexcel.xlsx

The issues that you are seeing are due to the header/library not been found so double check your installation stage.

Also, this isn't the same issue as the other SO question that you linked to. In their case they had a mix or 32 and 64bit libraries that was causing link issues. I am the author of libxlsxwriter, btw.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM