brechtsanders / xlsxio

XLSX I/O - C library for reading and writing .xlsx files
MIT License
417 stars 112 forks source link

Build static lib with MinGW on Windows? #58

Closed urbster1 closed 4 years ago

urbster1 commented 4 years ago

Hi! I want to build xlsxio_write as a static lib on Windows with MinGW64 but I have no idea how to do this? I'd like to distribute my code as a static .exe that doesn't require the libxlsxwrite.dll file. I don't have MSVC so any help is appreciated, thanks!

yvwmash commented 4 years ago

Follow the instructions: https://github.com/brechtsanders/xlsxio#building-from-source.

сб, 7 мар. 2020 г. в 22:34, urbster1 notifications@github.com:

Hi! I want to build xlsxio_write as a static lib on Windows with MinGW64 but I have no idea how to do this? I'd like to distribute my code as a static .exe that doesn't require the libxlsxwrite.dll file. I don't have MSVC so any help is appreciated, thanks!

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/brechtsanders/xlsxio/issues/58?email_source=notifications&email_token=ALSOZLG4CA5OTSTKBMUNQFTRGKVUNA5CNFSM4LDSZG32YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4ITKL5TQ, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALSOZLBURFNYW65X55UH343RGKVUNANCNFSM4LDSZG3Q .

-- Ярослав Машко

+380990293574

live:yaroslaw.mashko

brechtsanders commented 4 years ago

You will also need to build all the dependancies as static libraries and link them into your .exe together with libxlsxwrite.a. You can do this in the MSYS2 shell on Windows with MinGW-w64.

urbster1 commented 4 years ago

I was able to build libxlsxio_write.a but am getting this error in my code. The linker is definitely able to find the lib, so I'm not sure what the issue is. Any insight is appreciated.

obj\Debug\main.o: In function `createExcel(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)':
main.cpp:253: undefined reference to `__imp_xlsxiowrite_open'
main.cpp:260: undefined reference to `__imp_xlsxiowrite_add_column'
main.cpp:262: undefined reference to `__imp_xlsxiowrite_next_row'
main.cpp:272: undefined reference to `__imp_xlsxiowrite_add_cell_string'
main.cpp:275: undefined reference to `__imp_xlsxiowrite_next_row'
main.cpp:280: undefined reference to `__imp_xlsxiowrite_close'
collect2.exe: error: ld returned 1 exit status
brechtsanders commented 4 years ago

Those look like dynamic imports.Try to build your static lib with compiler flag -DSTATIC -------- Original message --------From: urbster1 notifications@github.com Date: 09/03/20 17:56 (GMT+01:00) To: brechtsanders/xlsxio xlsxio@noreply.github.com Cc: Brecht Sanders brecht@sanders.org, Comment comment@noreply.github.com Subject: Re: [brechtsanders/xlsxio] Build static lib with MinGW on Windows?   (#58) I was able to build libxlsxio_write.a but am getting this error in my code. The linker is definitely able to find the lib, so I'm not sure what the issue is. Any insight is appreciated. obj\Debug\main.o: In function createExcel(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)': main.cpp:253: undefined reference toimp_xlsxiowrite_open' main.cpp:260: undefined reference to `imp_xlsxiowrite_add_column' main.cpp:262: undefined reference to __imp_xlsxiowrite_next_row' main.cpp:272: undefined reference toimp_xlsxiowrite_add_cell_string' main.cpp:275: undefined reference to `imp_xlsxiowrite_next_row' main.cpp:280: undefined reference to `__imp_xlsxiowrite_close' collect2.exe: error: ld returned 1 exit status

—You are receiving this because you commented.Reply to this email directly, view it on GitHub, or unsubscribe. [ { "@context": "http://schema.org", "@type": "EmailMessage", "potentialAction": { "@type": "ViewAction", "target": "https://github.com/brechtsanders/xlsxio/issues/58?email_source=notifications\u0026email_token=AEGT46K62ZNBGIWQMHNDVX3RGUUVZA5CNFSM4LDSZG32YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEOICVVQ#issuecomment-596650710", "url": "https://github.com/brechtsanders/xlsxio/issues/58?email_source=notifications\u0026email_token=AEGT46K62ZNBGIWQMHNDVX3RGUUVZA5CNFSM4LDSZG32YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEOICVVQ#issuecomment-596650710", "name": "View Issue" }, "description": "View this Issue on GitHub", "publisher": { "@type": "Organization", "name": "GitHub", "url": "https://github.com" } } ]

urbster1 commented 4 years ago

Thanks. Not sure why setting OPTION(BUILD_STATIC "Build static libraries" ON) for Cmake wouldn't work in this case.

brechtsanders commented 4 years ago

You're right, there was an error in CMakeLists.txt. I have fixed this in master and it will be in release 0.2.22. Can you try with the version from master?

urbster1 commented 4 years ago

Sure I'll give it a shot, thanks!

urbster1 commented 4 years ago

It seems to work OK! I will note this error just in case

lib/xlsxio_read.c:12:1: note: include '<stdio.h>' or provide a declaration of 'sscanf'
   11 | #  include <minizip/unzip.h>
  +++ |+#include <stdio.h>
   12 | #  define ZIPFILETYPE unzFile

When I added #include <stdio.h> to xlsxio_read.h it seemed to solved this issue.

brechtsanders commented 4 years ago

You're right. I fixed it in master.