User forums > Using Code::Blocks
Using libxlsxwriter : how to use -lz
bonelli:
Hello,
I'm trying to use the libxlsxwriter lib to write basic excel files.
- I successfully compiled it
- The example are compiling and working using gcc or g++ from the msys command line:
gcc myexcel.c -o myexcel -I /path/to/libxlsxwriter/include \
/path/to/libxlsxwriter/lib/libxlsxwriter.a -lz
It is mandatory to specify -lz.
How to do that from codeblocks?
I have already specified the include/lib path.
=> Without -lz option I have numerous errors: undefined reference to __getreent...
=> With -lz option I have: error: cannot find -lz
According to this link https://libxlsxwriter.github.io/getting_started.html#gsg_minizip
--- Quote ---The source files for minizip are included in the src tree of libxlsxwriter and are statically linked by default.
--- End quote ---
Beyond this point I'm not sure to understand what is statically linked or not. If minizip is statically linked at compile-time of libxlsxwriter, why should take care of "-lz" at compile time of a source code using libxlsxwriter?
I really don't konw what to do. Any help appreciated :)
--Below is a optional religious debate--
Why does software-people ALWAYS provides sources codes to recompile each time and VERY RARELY precompiled binaries? The instruction set of x86-64 computers is standardized. Even if they where open sources, no ones want to recompile notepad++, google earth, chrome, 7z... I'm from the hardware world, hopefully, I don't have to recompile solidworks, eagle, ADS, Altium to use them :o I'm using USB connected hardware tools: the manufacturers provides .h/.lib/.dll files. Nothing to recompile, not my job, and what a lost of time (considering millions of people are basically compiling the same sources for a couple of OS). Don't understand how it could be better to recompile libxlsxwriter and the zipper instead of using precompiled binaries. This is necessary for a particular CPU-architecture, but most of people are using standard OS on a well-known standard architecture.
Miguel Gimenez:
You must add this to Linker settings -> Link libraries
--- Code: ---/path/to/libxlsxwriter/lib/libxlsxwriter.a
/path/to/zlib/libz.a
--- End code ---
libz.a can be in the minizip folder or you can have it beforehand (from zlib, for example).
bonelli:
--- Quote from: Miguel Gimenez on July 22, 2020, 10:36:33 pm ---You must add this to Linker settings -> Link libraries
--- Code: ---/path/to/libxlsxwriter/lib/libxlsxwriter.a
/path/to/zlib/libz.a
--- End code ---
libz.a can be in the minizip folder or you can have it beforehand (from zlib, for example).
--- End quote ---
Hi Miguel and thanks for your response... But this didn't solve the problem, I still have the same errors.
Miguel Gimenez:
I didn't know libxlsxwriter when I read your message, but then I wrote a small test project before answering, and it was so easy to integrate that I added xlsx capability to my biggest project.
I have attached the CBP and the main.c file, it assumes you have defined a global variable named xlsxwriter pointing to the folder containing the library source (base = G:\Librerias81\xlsxwriter-0.9.5 in my system) and another global variable zlib (in my system it contains G:\Librerias81\zlib-1.2.11 in base, include and lib).
If you can't compile this small project then attach a full rebuild log:
http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_%28general%29#Q:_How_do_I_report_a_compilation_problem_on_the_forums.3F
bonelli:
compiler=gcc (mingw32)
OS=win10/x64
code::blocks 17.12
--- Code: ---<html>
<head>
<title>Excel build log</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head>
<body>
<tt>
Build started on: <u>03-08-2020 at 13:40.53</u><br />
Build ended on: <u>03-08-2020 at 13:40.53</u><p />
<b>-------------- Build: Release in Excel (compiler: GNU GCC Compiler)---------------</b><br />
mingw32-g++.exe -o bin\Excel.exe obj\main.o -s D:\libxlsxwriter\libxlsxwriter\lib\libxlsxwriter.a D:\libxlsxwriter\libxlsxwriter\zlib-1.2.11\libz.a<br />
D:\libxlsxwriter\libxlsxwriter\lib\libxlsxwriter.a(workbook.o): In function "store_defined_name':<br />
<font color="#ff0000">/d/libxlsxwriter/libxlsxwriter/src/workbook.c:591: undefined reference to "__getreent'</font><br />
D:\libxlsxwriter\libxlsxwriter\lib\libxlsxwriter.a(workbook.o): In function "populate_range_data_cache':<br />
<font color="#ff0000">/d/libxlsxwriter/libxlsxwriter/src/workbook.c:744: undefined reference to "__getreent'</font><br />
D:\libxlsxwriter\libxlsxwriter\lib\libxlsxwriter.a(workbook.o): In function "populate_range_dimensions':<br />
<font color="#ff0000">/d/libxlsxwriter/libxlsxwriter/src/workbook.c:852: undefined reference to "__getreent'</font><br />
D:\libxlsxwriter\libxlsxwriter\lib\libxlsxwriter.a(workbook.o): In function "prepare_workbook':<br />
<font color="#ff0000">/d/libxlsxwriter/libxlsxwriter/src/workbook.c:370: undefined reference to "__getreent'</font><br />
<font color="#ff0000">/d/libxlsxwriter/libxlsxwriter/src/workbook.c:379: undefined reference to "__getreent'</font><br />
<font color="#ff0000">D:\libxlsxwriter\libxlsxwriter\lib\libxlsxwriter.a(workbook.o):/d/libxlsxwriter/libxlsxwriter/src/workbook.c:376: more undefined references to "__getreent' follow</font><br />
D:\libxlsxwriter\libxlsxwriter\lib\libxlsxwriter.a(workbook.o): In function "workbook_close':<br />
<font color="#ff0000">/d/libxlsxwriter/libxlsxwriter/src/workbook.c:1936: undefined reference to "__errno'</font><br />
<font color="#ff0000">/d/libxlsxwriter/libxlsxwriter/src/workbook.c:1933: undefined reference to "__getreent'</font><br />
<font color="#ff0000">/d/libxlsxwriter/libxlsxwriter/src/workbook.c:1928: undefined reference to "__errno'</font><br />
<font color="#ff0000">/d/libxlsxwriter/libxlsxwriter/src/workbook.c:1926: undefined reference to "__getreent'</font><br />
<font color="#ff0000">/d/libxlsxwriter/libxlsxwriter/src/workbook.c:1943: undefined reference to "__errno'</font><br />
<font color="#ff0000">/d/libxlsxwriter/libxlsxwriter/src/workbook.c:1941: undefined reference to "__getreent'</font><br />
<font color="#ff0000">/d/libxlsxwriter/libxlsxwriter/src/workbook.c:1948: undefined reference to "__getreent'</font><br />
<font color="#ff0000">/d/libxlsxwriter/libxlsxwriter/src/workbook.c:1953: undefined reference to "__getreent'</font><br />
<font color="#ff0000">/d/libxlsxwriter/libxlsxwriter/src/workbook.c:1914: undefined reference to "__errno'</font><br />
<font color="#ff0000">/d/libxlsxwriter/libxlsxwriter/src/workbook.c:1912: undefined reference to "__getreent'</font><br />
<font color="#ff0000">/d/libxlsxwriter/libxlsxwriter/src/workbook.c:1921: undefined reference to "__errno'</font><br />
<font color="#ff0000">/d/libxlsxwriter/libxlsxwriter/src/workbook.c:1919: undefined reference to "__getreent'</font><br />
<font color="#ff0000">/d/libxlsxwriter/libxlsxwriter/src/workbook.c:1898: undefined reference to "__errno'</font><br />
<font color="#ff0000">/d/libxlsxwriter/libxlsxwriter/src/workbook.c:1896: undefined reference to "__getreent'</font><br />
D:\libxlsxwriter\libxlsxwriter\lib\libxlsxwriter.a(workbook.o): In function "workbook_add_chartsheet':<br />
<font color="#ff0000">/d/libxlsxwriter/libxlsxwriter/src/workbook.c:1733: undefined reference to "__getreent'</font><br />
<font color="#ff0000">/d/libxlsxwriter/libxlsxwriter/src/workbook.c:1754: undefined reference to "__getreent'</font><br />
<font color="#ff0000">/d/libxlsxwriter/libxlsxwriter/src/workbook.c:1762: undefined reference to "__getreent'</font><br />
<font color="#ff0000">/d/libxlsxwriter/libxlsxwriter/src/workbook.c:1741: undefined reference to "__getreent'</font><br />
<font color="#ff0000">D:\libxlsxwriter\libxlsxwriter\lib\libxlsxwriter.a(workbook.o):/d/libxlsxwriter/libxlsxwriter/src/workbook.c:1722: more undefined references to "__getreent' follow</font><br />
D:\libxlsxwriter\libxlsxwriter\lib\libxlsxwriter.a(worksheet.o): In function "write_inline_rich_string_cell':<br />
<font color="#ff0000">/d/libxlsxwriter/libxlsxwriter/src/worksheet.c:3192: undefined reference to "__locale_ctype_ptr'</font><br />
D:\libxlsxwriter\libxlsxwriter\lib\libxlsxwriter.a(worksheet.o): In function "write_inline_string_cell':<br />
<font color="#ff0000">/d/libxlsxwriter/libxlsxwriter/src/worksheet.c:3153: undefined reference to "__locale_ctype_ptr'</font><br />
D:\libxlsxwriter\libxlsxwriter\lib\libxlsxwriter.a(worksheet.o): In function "write_inline_rich_string_cell':<br />
<font color="#ff0000">/d/libxlsxwriter/libxlsxwriter/src/worksheet.c:3193: undefined reference to "__locale_ctype_ptr'</font><br />
D:\libxlsxwriter\libxlsxwriter\lib\libxlsxwriter.a(worksheet.o): In function "write_inline_string_cell':<br />
<font color="#ff0000">/d/libxlsxwriter/libxlsxwriter/src/worksheet.c:3154: undefined reference to "__locale_ctype_ptr'</font><br />
D:\libxlsxwriter\libxlsxwriter\lib\libxlsxwriter.a(worksheet.o): In function "new_row':<br />
<font color="#ff0000">/d/libxlsxwriter/libxlsxwriter/src/worksheet.c:561: undefined reference to "__getreent'</font><br />
<font color="#ff0000">/d/libxlsxwriter/libxlsxwriter/src/worksheet.c:564: undefined reference to "__getreent'</font><br />
D:\libxlsxwriter\libxlsxwriter\lib\libxlsxwriter.a(worksheet.o): In function "lxw_worksheet_new':<br />
<font color="#ff0000">/d/libxlsxwriter/libxlsxwriter/src/worksheet.c:105: undefined reference to "__getreent'</font><br />
<font color="#ff0000">/d/libxlsxwriter/libxlsxwriter/src/worksheet.c:164: undefined reference to "__getreent'</font><br />
<font color="#ff0000">/d/libxlsxwriter/libxlsxwriter/src/worksheet.c:176: undefined reference to "__getreent'</font><br />
<font color="#ff0000">D:\libxlsxwriter\libxlsxwriter\lib\libxlsxwriter.a(worksheet.o):/d/libxlsxwriter/libxlsxwriter/src/worksheet.c:147: more undefined references to "__getreent' follow</font><br />
D:\libxlsxwriter\libxlsxwriter\lib\libxlsxwriter.a(xmlwriter.o): In function "lxw_escape_url_characters':<br />
<font color="#ff0000">/d/libxlsxwriter/libxlsxwriter/src/xmlwriter.c:328: undefined reference to "__locale_ctype_ptr'</font><br />
<font color="#ff0000">/d/libxlsxwriter/libxlsxwriter/src/xmlwriter.c:328: undefined reference to "__locale_ctype_ptr'</font><br />
D:\libxlsxwriter\libxlsxwriter\lib\libxlsxwriter.a(utility.o): In function "lxw_name_to_row':<br />
<font color="#ff0000">/d/libxlsxwriter/libxlsxwriter/src/utility.c:247: undefined reference to "__locale_ctype_ptr'</font><br />
D:\libxlsxwriter\libxlsxwriter\lib\libxlsxwriter.a(utility.o): In function "lxw_name_to_col':<br />
<font color="#ff0000">/d/libxlsxwriter/libxlsxwriter/src/utility.c:270: undefined reference to "__locale_ctype_ptr'</font><br />
D:\libxlsxwriter\libxlsxwriter\lib\libxlsxwriter.a(utility.o): In function "lxw_name_to_row':<br />
<font color="#ff0000">/d/libxlsxwriter/libxlsxwriter/src/utility.c:247: undefined reference to "__locale_ctype_ptr'</font><br />
<font color="#ff0000">D:\libxlsxwriter\libxlsxwriter\lib\libxlsxwriter.a(utility.o):/d/libxlsxwriter/libxlsxwriter/src/utility.c:247: more undefined references to "__locale_ctype_ptr' follow</font><br />
D:\libxlsxwriter\libxlsxwriter\lib\libxlsxwriter.a(utility.o): In function "lxw_quote_sheetname':<br />
<font color="#ff0000">/d/libxlsxwriter/libxlsxwriter/src/utility.c:504: undefined reference to "__getreent'</font><br />
D:\libxlsxwriter\libxlsxwriter\lib\libxlsxwriter.a(chartsheet.o): In function "lxw_chartsheet_new':<br />
<font color="#ff0000">/d/libxlsxwriter/libxlsxwriter/src/chartsheet.c:36: undefined reference to "__getreent'</font><br />
<font color="#ff0000">/d/libxlsxwriter/libxlsxwriter/src/chartsheet.c:31: undefined reference to "__getreent'</font><br />
D:\libxlsxwriter\libxlsxwriter\lib\libxlsxwriter.a(chartsheet.o): In function "chartsheet_set_chart_opt':<br />
<font color="#ff0000">/d/libxlsxwriter/libxlsxwriter/src/chartsheet.c:256: undefined reference to "__getreent'</font><br />
<font color="#ff0000">/d/libxlsxwriter/libxlsxwriter/src/chartsheet.c:240: undefined reference to "__getreent'</font><br />
<font color="#ff0000">D:\libxlsxwriter\libxlsxwriter\lib\libxlsxwriter.a(chartsheet.o):/d/libxlsxwriter/libxlsxwriter/src/chartsheet.c:234: more undefined references to "__getreent' follow</font><br />
D:\libxlsxwriter\libxlsxwriter\lib\libxlsxwriter.a(shared_strings.o): In function "write_t':<br />
<font color="#ff0000">/d/libxlsxwriter/libxlsxwriter/src/shared_strings.c:128: undefined reference to "__locale_ctype_ptr'</font><br />
<font color="#ff0000">/d/libxlsxwriter/libxlsxwriter/src/shared_strings.c:129: undefined reference to "__locale_ctype_ptr'</font><br />
D:\libxlsxwriter\libxlsxwriter\lib\libxlsxwriter.a(packager.o): In function "add_file_to_zip':<br />
<font color="#ff0000">/d/libxlsxwriter/libxlsxwriter/src/packager.c:1259: undefined reference to "__getreent'</font><br />
<font color="#ff0000">/d/libxlsxwriter/libxlsxwriter/src/packager.c:1290: undefined reference to "__getreent'</font><br />
<font color="#ff0000">/d/libxlsxwriter/libxlsxwriter/src/packager.c:1281: undefined reference to "__getreent'</font><br />
<font color="#ff0000">/d/libxlsxwriter/libxlsxwriter/src/packager.c:1272: undefined reference to "__getreent'</font><br />
D:\libxlsxwriter\libxlsxwriter\lib\libxlsxwriter.a(packager.o): In function "lxw_packager_new':<br />
<font color="#ff0000">/d/libxlsxwriter/libxlsxwriter/src/packager.c:89: undefined reference to "__getreent'</font><br />
<font color="#ff0000">D:\libxlsxwriter\libxlsxwriter\lib\libxlsxwriter.a(packager.o):/d/libxlsxwriter/libxlsxwriter/src/packager.c:82: more undefined references to "__getreent' follow</font><br />
D:\libxlsxwriter\libxlsxwriter\lib\libxlsxwriter.a(styles.o): In function "lxw_styles_write_string_fragment':<br />
<font color="#ff0000">/d/libxlsxwriter/libxlsxwriter/src/styles.c:83: undefined reference to "__locale_ctype_ptr'</font><br />
<font color="#ff0000">/d/libxlsxwriter/libxlsxwriter/src/styles.c:84: undefined reference to "__locale_ctype_ptr'</font><br />
<font color="#ff0000">D:\libxlsxwriter\libxlsxwriter\lib\libxlsxwriter.a(tmpfileplus.o):tmpfileplus.c:(.text+0x182): undefined reference to "__errno'</font><br />
<font color="#ff0000">D:\libxlsxwriter\libxlsxwriter\lib\libxlsxwriter.a(tmpfileplus.o):tmpfileplus.c:(.text+0x1db): undefined reference to "__errno'</font><br />
<font color="#ff0000">D:\libxlsxwriter\libxlsxwriter\lib\libxlsxwriter.a(tmpfileplus.o):tmpfileplus.c:(.text+0x27c): undefined reference to "__errno'</font><br />
<font color="#ff0000">D:\libxlsxwriter\libxlsxwriter\lib\libxlsxwriter.a(tmpfileplus.o):tmpfileplus.c:(.text+0x3bb): undefined reference to "__errno'</font><br />
<font color="#ff0000">D:\libxlsxwriter\libxlsxwriter\lib\libxlsxwriter.a(tmpfileplus.o):tmpfileplus.c:(.text+0x4ea): undefined reference to "__errno'</font><br />
C:/Program Files (x86)/CodeBlocks/MinGW/bin/../lib/gcc/mingw32/5.1.0/../../../../mingw32/bin/ld.exe: D:\libxlsxwriter\libxlsxwriter\lib\libxlsxwriter.a(tmpfileplus.o): bad reloc address 0x20 in section ".eh_frame'<br />
C:/Program Files (x86)/CodeBlocks/MinGW/bin/../lib/gcc/mingw32/5.1.0/../../../../mingw32/bin/ld.exe: final link failed: Invalid operation<br />
<font color="#ff0000">collect2.exe: error: ld returned 1 exit status</font><br />
<font color="#a00000">Process terminated with status 1 (0 minute(s), 0 second(s))</font><br />
<font color="#a00000">50 error(s), 0 warning(s) (0 minute(s), 0 second(s))</font><br />
</tt>
</body>
</html>
--- End code ---
Navigation
[0] Message Index
[#] Next page
Go to full version