SWRiP: Compiling using Cygwin (Undefined reference problem)

Posted by Nekekami on Thu 05 Jan 2006 11:43 PM — 20 posts, 78,924 views.

United Kingdom #0
Hello list,

I have been attempting to get SWRiP to compile within Cygwin for the last couple of hours. I get a problem that I have read up on but haven't found a solution to.

I would save you all excessive spam by pasting my make output, however it seems that for most standard functions (fprintf, calloc, perror, strcat, sprintf, etc) I get a 'Undefined reference to problem.

This sounds like its most probably a problem with the way in which my Cygwin is setup, however I am unsure how to solve this, or what needs to be modified.

My makefile:
Quote:
CC = g++
PROF =
NOCRYPT =
#Uncomment the next line if you want MCCP support
#DBUGFLG = -DMCCP
C_FLAGS = $(OPT_FLAG) -O -g3 -Wall -Wuninitialized $(PROF) $(NOCRYPT) $(DBUGFLG) -DSMAUG $(SOLARIS_FLAG) $(TIME) $(REG) -DCYGWIN -Wno-trigraphs
L_FLAGS = $(OPT_FLAG) $(PROF) $(SOLARIS_LINK)

O_FILES = act_comm.o act_info.o act_move.o act_obj.o act_wiz.o boards.o \
build.o clans.o comm.o comments.o const.o db.o fight.o \
handler.o hashstr.o id.o interp.o magic.o makeobjs.o \
misc.o mud_comm.o mud_prog.o krearena.o player.o requests.o \
reset.o save.o shops.o skills.o special.o tables.o task.o \
track.o update.o \
space.o space2.o bounty.o swskills.o alias.o grub.o mapper.o templateparse.o trivia.o

C_FILES = act_comm.c act_info.c act_move.c act_obj.c act_wiz.c boards.c \
build.c clans.c comm.c comments.c const.c db.c fight.c \
handler.c hashstr.c id.c interp.c magic.c makeobjs.c \
misc.c mud_comm.c mud_prog.c krearena.c player.c requests.c \
reset.c save.c shops.c skills.c special.c tables.c task.c \
track.c update.c \
space.c space2.c bounty.c swskills.c alias.c grub.c mapper.c templateparse.c trivia.c

H_FILES = mud.h bet.h

all:
# co $(H_FILES)
make swrip
# rm -f $(H_FILES)
mv swrip ../bin/swrip

swrip: $(O_FILES)
rm -f swrip
$(CC) $(L_FLAGS) -o swrip $(O_FILES) -lm
chmod g+w swrip
chmod g+w $(O_FILES)

.c.o: mud.h
$(CC) -c $(C_FLAGS) $<

clean:
rm -f $(O_FILES)


I downloaded Cygwin today and installed /all/ packages.

If you would like further information just drop me a reply.

Thanks,

-Nek
Amended on Sat 07 Jan 2006 09:46 AM by Nekekami
USA #1
Sounds like you're including the wrong header file, or missing an include for those functions. Could you paste some of the exact errors?
Amended on Fri 06 Jan 2006 12:37 AM by Zeno
United Kingdom #2
Here is a copy of some of the errors I have been getting. I will include at the bottom a list of the Includes for each file.

Quote:
//swskills.c:5941: undefined reference to `strcpy'
//swskills.c:5942: undefined reference to `stderr'
//swskills.c:5942: undefined reference to `fprintf'
//swskills.c:5942: undefined reference to `free'
//swskills.c:6018: undefined reference to `strcat'
swskills.o: In function `_Z13do_makemedpacP9char_dataPc':
//swskills.c:6119: undefined reference to `strcpy'
//swskills.c:6120: undefined reference to `stderr'
//swskills.c:6120: undefined reference to `fprintf'
//swskills.c:6167: undefined reference to `stderr'
swskills.o: In function `_Z16do_makefurnitureP9char_dataPc':
//swskills.c:6400: undefined reference to `strcpy'
//swskills.c:6402: undefined reference to `stderr'
//swskills.c:6402: undefined reference to `fprintf'
//swskills.c:6402: undefined reference to `free'
alias.o: In function `_Z8do_aliasP9char_dataPc':
/root/alias.c:76: undefined reference to `stderr'
/root/alias.c:76: undefined reference to `fprintf'
/root/alias.c:76: undefined reference to `free'
alias.o: In function `_Z12free_aliasesP9char_data':
/root/alias.c:115: undefined reference to `stderr'
/root/alias.c:115: undefined reference to `fprintf'
/root/alias.c:115: undefined reference to `free'
/root/alias.c:117: undefined reference to `stderr'
/root/alias.c:117: undefined reference to `fprintf'
/root/alias.c:117: undefined reference to `free'
/root/alias.c:118: undefined reference to `stderr'
/root/alias.c:118: undefined reference to `fprintf'
/root/alias.c:118: undefined reference to `free'
alias.o: In function `_Z11check_aliasP9char_dataPcS1_':
/root/alias.c:137: undefined reference to `sprintf'
/root/alias.c:165: undefined reference to `strcat'
/root/alias.c:166: undefined reference to `strcat'
grub.o: In function `_Z8do_rgrubP9char_dataPc':
//grub.c:136: undefined reference to `atoi'
//grub.c:139: undefined reference to `atoi'
//grub.c:140: undefined reference to `atoi'
//grub.c:155: undefined reference to `qsort'
grub.o: In function `_Z7go_initv':
//grub.c:196: undefined reference to `strcpy'
//grub.c:197: undefined reference to `strcpy'
//grub.c:198: undefined reference to `strcpy'
//grub.c:199: undefined reference to `strcpy'
//grub.c:200: undefined reference to `strcpy'


:: Swskills.c
#include <math.h>
#include <sys/types.h>
#include <ctype.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include "mud.h"

:: Alias.c
#include <sys/types.h>
#include <ctype.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <sys/stat.h>
#include "mud.h"

:: Grub.c
#include <sys/types.h>
#include <ctype.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include "mud.h"

Do you want any more information? Also, I have cut down the repetition of errors in the above so make this post able.

-Nek
Australia Forum Administrator #3
For a start, these are link errors, not compile errors. See this test program:


int blah ();

int main ()
  {
  blah ();
  return 0;
  }


Note the attempt to call "blah" which is defined but there is no code for it.

If we compile that:


$ gcc test.c
/tmp/ccsANsIj.o(.text+0x11): In function `main':
: undefined reference to `blah'
collect2: ld returned 1 exit status


That is your error message. It cannot link to the functions in your error list. Now there are a couple of funny things in your error log:


//swskills.c


Why does the filename have // in it? That looks strange.


/root/alias.c


Why are files in the root directory? This looks odd. I would expect you to have a home directory and the files be in that.

Assuming you installed as Nekekami I would expect something like:


/home/Nekekami/SWRiP/src/swskills.c


Did you unzip with folder names? There is something strange about the directory structure you are using.
United Kingdom #4
I just checked the layout of the files, they are all stored within the src directory which is contained at: /cygdrive/d/toc/swtoc/src

Thats the address within Cygwin, they are actually stored in D:\ToC\swtoc\src\

I am at a loss as to what is going on here, but I do agree, its strange that its //swskills.c and why its but root in front of alias... I am not sure.

-Nek
Australia Forum Administrator #5
I would untar them inside Cygwin, and in your personal directory. Thus it should be something like:

/cygdrive/d/home/Nekekami/swtoc/src

In other words, in the Cygwin shell, type "cd" to go to your home directory, and untar the archive there.
United Kingdom #6
Well, I found my home directory and copied the files across to there. Then ran make again. Same set of errors again, with this at the bottom:

Quote:
ollow
collect2: ld returned 1 exit status
make[1]: *** [swrip] Error 1
make[1]: Leaving directory `/home/Nunya Bizness/swtoc/src'
make: *** [all] Error 2

USA #7
Check if you can compile a normal codebase like SmaugFUSS. If not, something is wrong with your Cygwin. If you can, something is wrong with that SWRiP source.
United Kingdom #8
Ok, it compiles SWR FUSS absolutely fine. Any idea what is going on here? Or any further information i can provide?

-Nek
USA #9
Try replacing the Makefile with the one from SWR FUSS maybe? I find this line a little odd:
C_FILES = $(wildcard *.c)
United Kingdom #10
Heh, i was one step ahead, just used the SWR Fuss makefile and I've got some progress:

mud.h:1295: warning: shadowed declaration is here
act_comm.c: In function `add_follower':
act_comm.c:2459: error: dereferencing pointer to incomplete type
act_comm.c:2465: error: dereferencing pointer to incomplete type
act_comm.c:2466: error: dereferencing pointer to incomplete type
act_comm.c:2467: error: dereferencing pointer to incomplete type
act_comm.c:2467: error: dereferencing pointer to incomplete type
act_comm.c:2467: error: dereferencing pointer to incomplete type
act_comm.c:2467: error: dereferencing pointer to incomplete type
act_comm.c:2467: error: dereferencing pointer to incomplete type
act_comm.c:2468: error: dereferencing pointer to incomplete type
act_comm.c: At top level:
act_comm.c:2480: warning: declaration of 'ch' shadows a global de
mud.h:1295: warning: shadowed declaration is here
act_comm.c: In function `stop_follower':
act_comm.c:2482: error: dereferencing pointer to incomplete type
act_comm.c:2488: error: dereferencing pointer to incomplete type
act_comm.c:2488: error: dereferencing pointer to incomplete type
act_comm.c:2488: error: dereferencing pointer to incomplete type
act_comm.c:2488: error: dereferencing pointer to incomplete type
act_comm.c:2488: error: dereferencing pointer to incomplete type
act_comm.c:2489: error: dereferencing pointer to incomplete type
act_comm.c:2491: error: dereferencing pointer to incomplete type
act_comm.c:2493: error: dereferencing pointer to incomplete type
act_comm.c:2497: error: dereferencing pointer to incomplete type
act_comm.c:2498: error: dereferencing pointer to incomplete type
act_comm.c:2499: error: dereferencing pointer to incomplete type
act_comm.c:2501: error: dereferencing pointer to incomplete type
act_comm.c:2502: error: dereferencing pointer to incomplete type

These are my latest batch of errors. What im not understanding here is that this code compiled perfectly on the unix box it was on before i moved it into cygwin...

-Nek
Amended on Fri 06 Jan 2006 11:44 PM by Nekekami
USA #11
Could you edit that to use the code tag and not quote? It's very hard to read.

[EDIT] What's around lines 1295 in mud.h?
Amended on Fri 06 Jan 2006 11:45 PM by Zeno
United Kingdom #12
This is bizarre. Line 1295 is the CHAR_DATA *ch part of the below. It belongs to the ship_data structure...

int maxcargo;
sh_int caughtsmugcargo;
CHAR_DATA *ch;
SPACE_DATA *inorbitof;
int count;
MODULE_DATA *first_module;

-Nek
USA #13
Are you sure it's in a struct? See this topic for what the error means:
http://www.gammon.com.au/forum/bbshowpost.php?bbsubject_id=6198
Amended on Sat 07 Jan 2006 03:33 AM by Zeno
USA #14
Could you tell us where you downloaded this source from? The only SWRiP packages I can find don't have the same Makfile you do.
United Kingdom #15
This might help, I realised that the Makefile i posted wasn't actually the one i was using. Sorry for the confusion, I can edited by first post with the actual makefile.

The source was downloaded from swrip.net and is actually just a slightly modified SWR RiP 2.0.

-Nek
Amended on Sat 07 Jan 2006 09:47 AM by Nekekami
USA #16
Did you already correct a bunch of errors? This is what I'm getting when trying to compile on Cygwin:
act_move.c: In function `ROOM_INDEX_DATA* generate_exit(ROOM_INDEX_DATA*, EXIT_D
ATA**)':
act_move.c:604: error: ISO C++ forbids cast to non-reference type used as lvalue


And that is besides the crypt errors. SWRiP doesn't seem like a good source that supports Cygwin. I see no Cygwin flags or nocrypt toggles in the Makefile.
USA #17
You don't need nocrypt toggles to support Cygwin. Just install the crypt library and make sure any files that bark about crypt() being undefined are including crypt.h.

The act_move.c error is an older bug found in Smaug and would complain with the linux version as well, so that's not a Cygwin issue.

The line

    (EXIT_DATA *) pexit = xit;


should become:

    *pexit = xit;


I'm sure there are other minor things to fix but most of these will be universal in nature.
USA #18
Oh that error. It was a warning in gcc, so I didn't know it was the same.

The crypt lib? I installed everything that came with Cygwin. Is it not included?
USA #19
In a default install, no. But if you told it to install all of the packages, then you should have it and have no problems with making use of it.