capnproto icon indicating copy to clipboard operation
capnproto copied to clipboard

build: compile failure with mingw-w64

Open fanquake opened this issue 1 year ago • 3 comments

Following the instructions on https://capnproto.org/install.html, using the master branch (f5531718b95c2ad4fcedc624e0d46866455007f4) and compiling for mingw-w64 on Ubuntu 22.04:

git clone https://github.com/capnproto/capnproto.git
cd capnproto/c++
git checkout master
autoreconf -i
./configure --host=x86_64-w64-mingw32
make -j6 check
...
libtool: compile:  x86_64-w64-mingw32-g++ -DHAVE_CONFIG_H -I. -I./src -I./src -DKJ_HEADER_WARNINGS -DCAPNP_HEADER_WARNINGS -DCAPNP_INCLUDE_DIR=\"/usr/local/include\" -mthreads -O2 -DNDEBUG -mthreads -DKJ_USE_FIBERS -MT src/kj/filesystem-disk-win32.lo -MD -MP -MF src/kj/.deps/filesystem-disk-win32.Tpo -c src/kj/filesystem-disk-win32.c++ -o src/kj/filesystem-disk-win32.o >/dev/null 2>&1
libtool: compile:  x86_64-w64-mingw32-g++ -DHAVE_CONFIG_H -I. -I./src -I./src -DKJ_HEADER_WARNINGS -DCAPNP_HEADER_WARNINGS -DCAPNP_INCLUDE_DIR=\"/usr/local/include\" -mthreads -O2 -DNDEBUG -mthreads -DKJ_USE_FIBERS -MT src/capnp/compat/json.lo -MD -MP -MF src/capnp/compat/.deps/json.Tpo -c src/capnp/compat/json.c++ -o src/capnp/compat/json.o >/dev/null 2>&1
/bin/bash ./libtool  --tag=CXX   --mode=link x86_64-w64-mingw32-g++ -I./src -I./src -DKJ_HEADER_WARNINGS -DCAPNP_HEADER_WARNINGS -DCAPNP_INCLUDE_DIR='"/usr/local/include"' -mthreads -O2 -DNDEBUG -mthreads -DKJ_USE_FIBERS -release 1.1-dev -no-undefined  -o libkj.la -rpath /usr/local/lib src/kj/cidr.lo src/kj/common.lo src/kj/units.lo src/kj/memory.lo src/kj/refcount.lo src/kj/array.lo src/kj/list.lo src/kj/string.lo src/kj/string-tree.lo src/kj/source-location.lo src/kj/hash.lo src/kj/table.lo src/kj/encoding.lo src/kj/exception.lo src/kj/debug.lo src/kj/arena.lo src/kj/io.lo src/kj/mutex.lo src/kj/thread.lo src/kj/time.lo src/kj/filesystem.lo src/kj/filesystem-disk-unix.lo src/kj/filesystem-disk-win32.lo src/kj/test-helpers.lo src/kj/main.lo src/kj/parse/char.lo  
libtool: link: x86_64-w64-mingw32-g++ -shared -nostdlib /usr/lib/gcc/x86_64-w64-mingw32/10-win32/../../../../x86_64-w64-mingw32/lib/dllcrt2.o /usr/lib/gcc/x86_64-w64-mingw32/10-win32/crtbegin.o  src/kj/.libs/cidr.o src/kj/.libs/common.o src/kj/.libs/units.o src/kj/.libs/memory.o src/kj/.libs/refcount.o src/kj/.libs/array.o src/kj/.libs/list.o src/kj/.libs/string.o src/kj/.libs/string-tree.o src/kj/.libs/source-location.o src/kj/.libs/hash.o src/kj/.libs/table.o src/kj/.libs/encoding.o src/kj/.libs/exception.o src/kj/.libs/debug.o src/kj/.libs/arena.o src/kj/.libs/io.o src/kj/.libs/mutex.o src/kj/.libs/thread.o src/kj/.libs/time.o src/kj/.libs/filesystem.o src/kj/.libs/filesystem-disk-unix.o src/kj/.libs/filesystem-disk-win32.o src/kj/.libs/test-helpers.o src/kj/.libs/main.o src/kj/parse/.libs/char.o   -L/usr/lib/gcc/x86_64-w64-mingw32/10-win32 -L/usr/lib/gcc/x86_64-w64-mingw32/10-win32/../../../../x86_64-w64-mingw32/lib -lstdc++ -lmingw32 -lgcc_s -lgcc -lmoldname -lmingwex -lmsvcrt -ladvapi32 -lshell32 -luser32 -lkernel32 -lmingw32 -lgcc_s -lgcc -lmoldname -lmingwex -lmsvcrt /usr/lib/gcc/x86_64-w64-mingw32/10-win32/crtend.o  -mthreads -O2 -mthreads   -mthreads -o .libs/libkj-1-1-dev.dll -Wl,--enable-auto-image-base -Xlinker --out-implib -Xlinker .libs/libkj.dll.a
/usr/bin/x86_64-w64-mingw32-ld: src/kj/.libs/cidr.o:cidr.c++:(.text+0x1e5): undefined reference to `__imp_inet_ntop'
/usr/bin/x86_64-w64-mingw32-ld: src/kj/.libs/cidr.o:cidr.c++:(.text+0x447): undefined reference to `__imp_inet_pton'
collect2: error: ld returned 1 exit status
make: *** [Makefile:1940: libkj.la] Error 1

fanquake avatar Nov 03 '23 11:11 fanquake

Thank for the report. Unfortunately I don't have enough bandwidth to debug MinGW build issues but I'll be happy to accept a PR that fixes this if you can figure out the problem. FWIW we build with MinGW in CI, both directly on Windows and cross-compiling, and this issue did not come up there. It looks like CI is configured to test MinGW cross-compiling on Ubuntu 20.04.

kentonv avatar Nov 03 '23 14:11 kentonv

FWIW, I asked chatgpt about the error and it said the linker command line needs -lws2_32 (https://chat.openai.com/share/d80fe16c-2ab5-42e6-826e-84653b4f44db)

ryanofsky avatar Nov 04 '23 20:11 ryanofsky

Ah hah, the -lws2_32 link is present in configure.ac but only applied to libkj-async, not libkj, and it appears that the cidr library landed in libkj. It probably should have been in libkj-async instead, or maybe we need to link ws2_32 either way:

https://github.com/capnproto/capnproto/blob/ac91386f32313704503a0b43301cd9084dd01e11/c%2B%2B/configure.ac#L75

Probably wasn't caught in tests because I think our tests only build static libraries -- I honestly never could get DLLs working with MinGW...

kentonv avatar Nov 06 '23 20:11 kentonv