Compiler Notes
While compiling
TinyMARE, I ran in to the following error. After much mostly useless googling, lots of head scratching, and installing many packages I didn't need, I eventually stumbled across the answer. A week later I went to compile
TinyMARE again on another platform, and ran in to the same error, and couldn't for the life of me remember how I resolved it. After solving it for a second time, I'm documenting it here for the future.
The error
$ make
[...]
gcc -o netmare config.o crypt.o rand.o stats.o timer.o utils.o version.o ../game/libgame.a ../comm/libcomm.a ../db/libdb.a ../io/libio.a ../prog/libprog.a -lm
../io/libio.a(dns.o): In function `send_dns_request':
dns.c:(.text+0x6c): undefined reference to `__res_mkquery'
../io/libio.a(dns.o): In function `dns_receive':
dns.c:(.text+0x434): undefined reference to `__dn_expand'
dns.c:(.text+0x4d4): undefined reference to `__dn_expand'
dns.c:(.text+0x588): undefined reference to `__dn_expand'
collect2: error: ld returned 1 exit status
Makefile:9: recipe for target 'netmare' failed
make[1]: *** [netmare] Error 1
make[1]: Leaving directory '/home/pi/mare1.0.10338/src/mare'
Makefile:5: recipe for target 'all' failed
make: *** [all] Error 1
Note the
_res_mkquery
and all the references to
dns.c
. It turns out this all points back to
resolv
(good luck looking
that up by itself).
The solution
The solution I found in a
random forum post for compilation of some other code was to add
resolv
to the linker.
There are two methods. The easiest is to run
configure
and when prompted for additional libraries, enter
-lm -lresolv
(
-lm
is the default, so it needs to be included).
If you've already run
configure
and you don't want to run it again for whatever reason, you can just edit the configuration file. Edit
src/config.in
, find the line for
LDLIBS
and append
-lresolv
(
without an E on the end). Like so:
$ vim src/config.in
CC = gcc
CFLAGS = -O3 -Wall -fomit-frame-pointer -I${HDRS}
LDLIBS = -lm -lresolv
SUBDIRS = comm db game io prog mare
LIBS = ../game/libgame.a ../comm/libcomm.a ../db/libdb.a ../io/libio.a \
../prog/libprog.a
It should also be noted that during my efforts to fix this, along the way I also happened to install the Debian packages for
dnsutils
and
libbind-dev
. I can't say if they were necessary, but if it still won't link give that a shot.
--
SluggyQBFreak - 19 Feb 2017