I'm trying to make a program that interacts with MS Excel using libxlsxwriter. I'm using MSYS2 with Mingw-w64 to build my application. Whenever I try to compile my code with the 64-bit version of gcc, everything works flawlessly; however, If I try to compile with the 32-bit version of gcc, it gives me this kind of error for every function I use: C:\msys64\tmp\ccknaH4k.o:main.cpp:(.text+0x16): undefined reference to 'workbook_new'
. What could it be?
Asked
Active
Viewed 875 times
2

sgrontflix
- 91
- 1
- 9
1 Answers
1
The library appears to have been built for 64-bit only, so when you try to link a 32-bit binary with it, the linker is only able to find 64-bit symbols, not 32-bit ones.
To solve this, you'll have to compile or download a 32-bit version of the library.

ForceBru
- 43,482
- 10
- 63
- 98
-
The library is for 32-bit as well as 64-bit systems. You have to build the library in order to use it. I used the MINGW32 shell and compiled it again using `make` and `make install` but with the same results. Another strange thing is that the compiled libraries are put by default in `C:\msys64\usr\lib` and if I want to use the 32-bit gcc, I have to copy the libraries in `C:\msys64\mingw32\lib` (this doesn't happen with the MINGW64 shell). – sgrontflix Nov 20 '16 at 15:58
-
@sgrontflix, did you link the binary against _the correct_ (32-bit) library file when building for 32-bit? – ForceBru Nov 20 '16 at 16:04
-
I'm not sure, I use this command ---> `gcc myexcel.c -o myexcel -lxlsxwriter -lz` to compile and link libraries to my executable. How can I make sure that I'm actually linking a 32-bit library? I'm sorry if I sound stupid but I'm new to these things. – sgrontflix Nov 20 '16 at 16:15
-
1@sgrontflix, don't worry, that doesn't sound stupid at all. You could try specifying the file manually: substitute the `-lxlsxwriter` option by `-L/path/to/64_bit/libxlsxwriter.lib` (the extension might be different, though). – ForceBru Nov 20 '16 at 16:17
-
Same story. I used this command ---> `gcc myexcel.cpp -o myexcel -LC:\msys64\usr\lib\libxlsxwriter.a -lz` and it gives me the `undefined reference to [...]` error. – sgrontflix Nov 20 '16 at 16:21
-
@sgrontflix, oh, I'm very sorry,I meant to say _32-bit_ version from `C:\msys64\mingw32\lib`. – ForceBru Nov 20 '16 at 16:22
-
The 32-bit version from `C:\msys64\mingw32\lib` doesn't exist. For some reason when I build the library, it will be saved to `C:\msys64\usr\lib\`, regardless of the compiler used. The funny thing is that everything works with the `MINGW64` shell but not with the `MINGW32` one. – sgrontflix Nov 20 '16 at 16:29
-
@sgrontflix, you said you had to copy the library file to that location, did you actually do that? Here's what you could try: build the library for 32-bit by doing `CFLAGS='-m32' make`, then copy the file to needed location. After that try to link the binary with the library using the method I was talking about earlier. – ForceBru Nov 20 '16 at 16:33
-
Yeah, I copied the libraries to that location but I removed them after realising it didn't work. Now I copied them again in that folder after running your command to build the libraries but I'm still getting the `undefined reference to [...]` error. – sgrontflix Nov 20 '16 at 16:46
-
@sgrontflix, have you included all the headers properly? Have you specified the path where to search for them? You could also do `gcc -I/path/to/header/directory -L/path/to/32_bit/library/directory myexcel.c -o myexcel -lxlsxwriter -lz`. If that won't work, I'm out of ideas for now... – ForceBru Nov 20 '16 at 16:59
-
I copied every header in the same directory as the executable, however I shouldn't have to: if I use the MINGW64 shell I don't have to do anything, just a simple command and everything is ok. Maybe I should download `zlib-devel` and compile it again (libxlsxwriter depends on it), but I'm not sure that it would work. Anyway, thank you for trying to help me, I really appreciate :) – sgrontflix Nov 20 '16 at 17:15