[GH-ISSUE #79] Building 32-bit version of libxlsxwriter with MSYS2 and Mingw-w64 #66

Closed
opened 2026-05-05 11:35:30 -06:00 by gitea-mirror · 13 comments
Owner

Originally created by @Z3ROQL on GitHub (Nov 20, 2016).
Original GitHub issue: https://github.com/jmcnamara/libxlsxwriter/issues/79

Originally assigned to: @jmcnamara on GitHub.

Hello. I successfully built my first application using MSYS2 and Mingw-64. Now I want to build a 32-bit version of it, so I installed the 32-bit version of gcc from MSYS2, opened up the MINGW32 shell and ran the usual command: gcc example.cpp -o example -lxlsxwriter -lz. The problem is that the linker cannot find the library. Here's the error:

C:/msys64/mingw32/bin/../lib/gcc/i686-w64-mingw32/6.2.0/../../../../i686-w64-mingw32/bin/ld.exe: cannot find -lxlsxwriter
collect2.exe: error: ld returned 1 exit status

So I thought: "Should I remove my already existing library and make it again?". So I did it: I ran make and make install, but nothing changed.

UPDATE: I also tried to use CFLAGS='-m32' make and CFLAGS='-m32' make install, but nothing changed.

Originally created by @Z3ROQL on GitHub (Nov 20, 2016). Original GitHub issue: https://github.com/jmcnamara/libxlsxwriter/issues/79 Originally assigned to: @jmcnamara on GitHub. Hello. I successfully built my first application using MSYS2 and Mingw-64. Now I want to build a 32-bit version of it, so I installed the 32-bit version of gcc from MSYS2, opened up the MINGW32 shell and ran the usual command: `gcc example.cpp -o example -lxlsxwriter -lz`. The problem is that the linker cannot find the library. Here's the error: ``` C:/msys64/mingw32/bin/../lib/gcc/i686-w64-mingw32/6.2.0/../../../../i686-w64-mingw32/bin/ld.exe: cannot find -lxlsxwriter collect2.exe: error: ld returned 1 exit status ``` So I thought: "Should I remove my already existing library and `make` it again?". So I did it: I ran `make` and `make install`, but nothing changed. **UPDATE**: I also tried to use `CFLAGS='-m32' make` and `CFLAGS='-m32' make install`, but nothing changed.
gitea-mirror 2026-05-05 11:35:30 -06:00
Author
Owner

@jmcnamara commented on GitHub (Nov 20, 2016):

Hi @Z3ROQL,

Did make install work correctly?

Either way you can try this fallback from the Libxlsxwriter installation guide :

If the installation didn't work for you then you can link against the static library you created in the "Build the source code" step:

cc myexcel.c -o myexcel -I /path/to/libxlsxwriter/include \
                           /path/to/libxlsxwriter/lib/libxlsxwriter.a -lz

See also this online documentation on HOWTO Specify the Location of Libraries for use with MinGW.

<!-- gh-comment-id:261793977 --> @jmcnamara commented on GitHub (Nov 20, 2016): Hi @Z3ROQL, Did `make install` work correctly? Either way you can try this fallback from the Libxlsxwriter [installation guide](http://libxlsxwriter.github.io/getting_started.html#gsg_using) : > If the installation didn't work for you then you can link against the static library you created in the "[Build the source code](http://libxlsxwriter.github.io/getting_started.html#gsg_build)" step: > > ``` > cc myexcel.c -o myexcel -I /path/to/libxlsxwriter/include \ > /path/to/libxlsxwriter/lib/libxlsxwriter.a -lz > ``` See also this online documentation on [HOWTO Specify the Location of Libraries for use with MinGW](http://www.mingw.org/wiki/LibraryPathHOWTO).
Author
Owner

@Z3ROQL commented on GitHub (Nov 20, 2016):

make install worked correctly. I executed this command ---> cc main.cpp -o main -I c:/msys64/home/z3roql/libxlsxwriter/include \c:/msys64/home/z3roql/libxlsxwriter/lib/libxlsxwriter.a -lz and now it gives me this error ---> C:\msys64\tmp\ccUeeXG4.o:main.cpp:(.text+0x16): undefined reference to 'workbook_new' (for every function in main.cpp).

<!-- gh-comment-id:261797492 --> @Z3ROQL commented on GitHub (Nov 20, 2016): `make install` worked correctly. I executed this command ---> `cc main.cpp -o main -I c:/msys64/home/z3roql/libxlsxwriter/include \c:/msys64/home/z3roql/libxlsxwriter/lib/libxlsxwriter.a -lz` and now it gives me this error ---> `C:\msys64\tmp\ccUeeXG4.o:main.cpp:(.text+0x16): undefined reference to 'workbook_new'` (for every function in `main.cpp`).
Author
Owner

@jmcnamara commented on GitHub (Nov 21, 2016):

What happen if you do make examples?

<!-- gh-comment-id:261867411 --> @jmcnamara commented on GitHub (Nov 21, 2016): What happen if you do `make examples`?
Author
Owner

@jmcnamara commented on GitHub (Nov 21, 2016):

Also is it correct that the lib path is escaped: \c:/msys64/home/...

<!-- gh-comment-id:261867984 --> @jmcnamara commented on GitHub (Nov 21, 2016): Also is it correct that the lib path is escaped: ` \c:/msys64/home/...`
Author
Owner

@Z3ROQL commented on GitHub (Nov 21, 2016):

What happen if you do make examples?

If I do make examples it gives me a bunch of undefined reference to [...] errors ---> make[1]: entering directory "/home/z3roql/libxlsxwriter/examples" C:\msys64\tmp\ccSMi9UL.o: In function 'write_worksheet_data': C:\msys64\home\z3roql\libxlsxwriter\examples/chart_scatter.c:26: undefined reference to 'lxw_name_to_col' [...]

Also is it correct that the lib path is escaped: \c:/msys64/home/...

Yes, I think it's correct since it doesn't output any syntax error.

<!-- gh-comment-id:262041396 --> @Z3ROQL commented on GitHub (Nov 21, 2016): > What happen if you do `make examples`? If I do `make examples` it gives me a bunch of `undefined reference to [...]` errors ---> ```make[1]: entering directory "/home/z3roql/libxlsxwriter/examples" C:\msys64\tmp\ccSMi9UL.o: In function 'write_worksheet_data': C:\msys64\home\z3roql\libxlsxwriter\examples/chart_scatter.c:26: undefined reference to 'lxw_name_to_col' [...]``` > Also is it correct that the lib path is escaped: `\c:/msys64/home/...` Yes, I think it's correct since it doesn't output any syntax error.
Author
Owner

@jmcnamara commented on GitHub (Nov 22, 2016):

I'm afraid I can't help you with this. I retested with MSYS2 32bit using the latest installer: http://repo.msys2.org/distrib/i686/msys2-i686-20161025.exe

Then I ran the installation instructions from the docs:

# Install MSYS2 64 or 32 bit from http://msys2.github.io/

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

# Clone and build libxlsxwriter.
git clone https://github.com/jmcnamara/libxlsxwriter.git
cd libxlsxwriter/
make

Everything worked fine as did make examples and make test_unit.

I think that you should verify that all of that works for you first.

<!-- gh-comment-id:262211556 --> @jmcnamara commented on GitHub (Nov 22, 2016): I'm afraid I can't help you with this. I retested with MSYS2 32bit using the latest installer: http://repo.msys2.org/distrib/i686/msys2-i686-20161025.exe Then I ran the installation instructions from the docs: ``` # Install MSYS2 64 or 32 bit from http://msys2.github.io/ # Install the dev tools for libxlsxwriter. pacman -S git gcc make zlib-devel # Clone and build libxlsxwriter. git clone https://github.com/jmcnamara/libxlsxwriter.git cd libxlsxwriter/ make ``` Everything worked fine as did `make examples` and `make test_unit`. I think that you should verify that all of that works for you first.
Author
Owner

@Z3ROQL commented on GitHub (Nov 22, 2016):

I'll try to download and install again MSYS2. Thank you for answering. I'll post a comment here when I'm done.

<!-- gh-comment-id:262234768 --> @Z3ROQL commented on GitHub (Nov 22, 2016): I'll try to download and install again MSYS2. Thank you for answering. I'll post a comment here when I'm done.
Author
Owner

@Z3ROQL commented on GitHub (Nov 22, 2016):

Ok. I downloaded and installed everything again. Now it compiles without any problem, but it gives me this error code when I try to execute it: 0xc000007b.

<!-- gh-comment-id:262301226 --> @Z3ROQL commented on GitHub (Nov 22, 2016): Ok. I downloaded and installed everything again. Now it compiles without any problem, but it gives me this error code when I try to execute it: `0xc000007b`.
Author
Owner

@jmcnamara commented on GitHub (Nov 22, 2016):

but it gives me this error code when I try to execute it: 0xc000007b.

What gives an error code? What are you running?

Do you get the same error if you run the following from the shell after the commands above:

 ./examples/hello.exe

The issue may be that you don't have admin rights to write to the Windows TEMP. You can try run in Admin mode or use a different TEMP folder as explained here in the docs: http://libxlsxwriter.github.io/getting_started.html#gsg_tmpdir

Make sure the dir in .tmpdir = "C:\\Temp" is writable by you/your application.

<!-- gh-comment-id:262306795 --> @jmcnamara commented on GitHub (Nov 22, 2016): > but it gives me this error code when I try to execute it: 0xc000007b. What gives an error code? What are you running? Do you get the same error if you run the following from the shell after the commands above: ./examples/hello.exe The issue may be that you don't have admin rights to write to the Windows TEMP. You can try run in Admin mode or use a different TEMP folder as explained here in the docs: http://libxlsxwriter.github.io/getting_started.html#gsg_tmpdir Make sure the dir in `.tmpdir = "C:\\Temp"` is writable by you/your application.
Author
Owner

@Z3ROQL commented on GitHub (Nov 22, 2016):

What gives an error code? What are you running?

I'm running my test program.

Do you get the same error if you run the following from the shell after the commands above:

./examples/hello.exe

EDIT: I don't get any error, but I also don't get any .xlsx file. If I try to double-click on the binary, it gives me the 0xc000007b error.

I tried running my program as Administrator but with same results. Also, I don't think that the TEMP directory is a problem since it works perfectly with the other 64-bit program I made before.

UPDATE: Ok... This is REALLY strange. For some reason if I run the program from the MSYS2 shell using this command ---> ./main.exe everything works. However, if I try to double-click on the binary to execute it, it gives me the aforementioned error. I'm confused...

<!-- gh-comment-id:262329831 --> @Z3ROQL commented on GitHub (Nov 22, 2016): > What gives an error code? What are you running? I'm running my test program. > Do you get the same error if you run the following from the shell after the commands above: > > ` ./examples/hello.exe` **EDIT**: I don't get any error, but I also don't get any `.xlsx` file. If I try to double-click on the binary, it gives me the `0xc000007b ` error. I tried running my program as Administrator but with same results. Also, I don't think that the TEMP directory is a problem since it works perfectly with the other 64-bit program I made before. **UPDATE**: Ok... This is REALLY strange. For some reason if I run the program from the MSYS2 shell using this command ---> `./main.exe` everything works. However, if I try to double-click on the binary to execute it, it gives me the aforementioned error. I'm confused...
Author
Owner

@jmcnamara commented on GitHub (Nov 23, 2016):

Maybe the issue is that you are trying to run a 32bit application in a 64bit version of Windows.

There are some suggestion here on fixing the 0xc000007b error code: http://www.techcrises.com/how-to/how-to-fix-error-code-0xc000007b-in-windows-7-8-8-1/

I'd suggest "Method 4 : Fix Compatibility Issue Between System and Application".

<!-- gh-comment-id:262483211 --> @jmcnamara commented on GitHub (Nov 23, 2016): Maybe the issue is that you are trying to run a 32bit application in a 64bit version of Windows. There are some suggestion here on fixing the 0xc000007b error code: http://www.techcrises.com/how-to/how-to-fix-error-code-0xc000007b-in-windows-7-8-8-1/ I'd suggest "Method 4 : Fix Compatibility Issue Between System and Application".
Author
Owner

@jmcnamara commented on GitHub (Nov 23, 2016):

Here is another link that suggests the issue is mixing 32bit code and 64bit dlls (or vice versa): https://msoos.wordpress.com/2010/09/11/0xc000007b-error-solution/

<!-- gh-comment-id:262484157 --> @jmcnamara commented on GitHub (Nov 23, 2016): Here is another link that suggests the issue is mixing 32bit code and 64bit dlls (or vice versa): https://msoos.wordpress.com/2010/09/11/0xc000007b-error-solution/
Author
Owner

@Z3ROQL commented on GitHub (Nov 23, 2016):

YES! Finally! I love you! I used Dependency Walker as you suggested and replaced msys-2.0.dll, msys-gcc_s-1.dll and msys-z.dll from my project folder (they were 64-bit instead of 32-bit) and now everything works again! 💃

<!-- gh-comment-id:262485791 --> @Z3ROQL commented on GitHub (Nov 23, 2016): YES! Finally! I love you! I used Dependency Walker as you suggested and replaced `msys-2.0.dll`, `msys-gcc_s-1.dll` and `msys-z.dll` from my project folder (they were 64-bit instead of 32-bit) and now everything works again! 💃
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/libxlsxwriter#66
No description provided.