I had previously built a static Tor lib on tag in MinGW previously with the following configure:

LIBS=-lcrypt32 ./configure --prefix=$PWD/dist \
                            --disable-gcc-hardening \
                            --enable-static-tor \
                            --enable-static-libevent \
                            --with-libevent-dir=$PWD/../libevent/dist \
                            --enable-static-openssl \
                            --with-openssl-dir=$PWD/../openssl/dist \
                            --enable-static-zlib \
                            --with-zlib-dir=$PWD/../openssl/dist \

This of course assumes I have statically built all those deps which I have. Now on tag, I can successfully build using the same command. But when I try to link with my program, I get all sorts of errors like:

c:/my/path/tor-static/tor/src/or/libtor.a(main.o): In function `shutdown_did_not_work_callback':
C:\my\path\tor-static\tor/src/or/main.c:742: undefined reference to `tor_fix_source_file'
C:\my\path\tor-static\tor/src/or/main.c:742: undefined reference to `tor_assertion_failed_'
c:/my/path/tor-static/tor/src/or/libtor.a(main.o): In function `directory_all_unreachable_cb':
C:\my\path\tor-static\tor/src/or/main.c:1073: undefined reference to `log_fn_'
C:\my\path\tor-static\tor/src/or/main.c:1078: undefined reference to `tor_fix_source_file'
c:/my/path/tor-static/tor/src/or/libtor.a(main.o): In function `TO_ENTRY_CONN':
C:\my\path\tor-static\tor/src/or/or.h:1964: undefined reference to `tor_fix_source_file'
C:\my\path\tor-static\tor/src/or/or.h:1964: undefined reference to `tor_assertion_failed_'
c:/my/path/tor-static/tor/src/or/libtor.a(main.o): In function `check_fw_helper_app_callback':
C:\my\path\tor-static\tor/src/or/main.c:2202: undefined reference to `tor_check_port_forwarding'
C:\my\path\tor-static\tor/src/or/main.c:2207: undefined reference to `smartlist_free_'

This is when including (along with the deps) ext/ed25519/ref10/libed25519_ref10.a, ext/ed25519/donna/libed25519_donna.a, trunnel/libor-trunnel.a, ext/keccak-tiny/libkeccak-tiny.a, common/libcurve25519_donna.a, common/libor.a, common/libor-crypto.a, common/libor-ctime.a, common/libor-event.a, and or/libtor.a.

What library am I not including? Or is this a bug?

  • This might be due to the order of my libs in LD...still investigating... – Chad Retz May 17 '18 at 16:06

First MinGW has a current bug which can be solved, as mentioned here, by downgrading some libs using:

pacman -U /var/cache/pacman/pkg/mingw-w64-x86_64-crt-git-
pacman -U /var/cache/pacman/pkg/mingw-w64-x86_64-headers-git-
pacman -U /var/cache/pacman/pkg/mingw-w64-x86_64-winpthreads-git- /var/cache/pacman/pkg/mingw-w64-x86_64-libwinpthread-git-

You have to recompile everything once those have been fixed.

Then, I had my libs in a bad order. Assuming `%TOR_STATIC% is set as the base dir w/ tor and other deps beneath, here are a set of LDFLAGS, one per line:

-L%TOR_STATIC%/tor/src/or -ltor
-L%TOR_STATIC%/tor/src/common -lor -lor-crypto -lcurve25519_donna -lor-ctime -lor-event
-L%TOR_STATIC%/tor/src/trunnel -lor-trunnel
-L%TOR_STATIC%/tor/src/ext/keccak-tiny -lkeccak-tiny
-L%TOR_STATIC%/tor/src/ext/ed25519/ref10 -led25519_ref10
-L%TOR_STATIC%/tor/src/ext/ed25519/donna -led25519_donna
-L%TOR_STATIC%/libevent/dist/lib -levent
-L%TOR_STATIC%/xz/dist/lib -llzma
-L%TOR_STATIC%/zlib/dist/lib -lz
-L%TOR_STATIC%/openssl/dist/lib -lssl -lcrypto
-lws2_32 -lcrypt32 -lgdi32

Those flags will link in Tor statically to the exe.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.