VC++ 6.0 Compiling LNK2001 error

Posted by Mike Scherling on Mon 12 Jul 2004 09:48 PM — 4 posts, 16,994 views.

USA #0
Linking...
Descriptor2.obj : error LNK2001: unresolved external symbol "void __cdecl status_update(class CCharacter *)" (?status_update@@YAXPAVCCharacter@@@Z)
.\Debug/SmaugWiz.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

SmaugWiz.exe - 2 error(s), 0 warning(s)




Working on a new status_update script on Smaug 1.4 that was ported to windows xp (everything runs fine through it) using SmaugWiz... Using a new system for things like.. if someone buffs your con stat (for instance) your life and defence woudl go up as well, all sat dependant.. and this script forces an update every time prompt is loaded...

Im having a problem with linking to the SMAUG.H file using a previous void status_update (CCharacter *ch); line


now...

This is the line I put into my SMAUG.H file
extern void status_update (CCharacter *ch);

question is, would this be all i need to do to link to my UPDATE.CPP file so it can be called upon by my Descriptor2.cpp file? Ive tried many different ways of using it, and searched through similar linkings to find how they did it, but i cant seem to find why i get the error as mentioned above.

Any help is appreciated, thanks! =)
Amended on Mon 12 Jul 2004 09:54 PM by Mike Scherling
Australia Forum Administrator #1
The line you have added:


extern void status_update (CCharacter *ch);


*declares* that you will, somewhere, have a status_update function.

However since you are getting a linker error you haven't *defined* what that does.

In other words, somewhere in your source (in a .c file) you need to have:


void status_update (CCharacter *ch)
  {

  // ... do something here

  }


Also, this .c file need to compile successfully, and be linked into the link.

For example, the status_update routine either needs to be in an existing file, or you add the new file to your Makefile, like this:


O_FILES = act_comm.o act_info.o act_move.o act_obj.o act_wiz.o boards.o \
          build.o clans.o color.o comm.o comments.o const.o db.o deity.o fight.o \
          handler.o hashstr.o ident.o interp.o magic.o makeobjs.o \
          mapout.o misc.o mpxset.o mud_comm.o mud_prog.o player.o polymorph.o \
          reset.o save.o shops.o skills.o special.o tables.o \
          track.o update.o grub.o ban.o services.o planes.o \
          imm_host.o  status_update.o


C_FILES = act_comm.c act_info.c act_move.c act_obj.c act_wiz.c boards.c \
          build.c clans.c color.c comm.c comments.c const.c db.c deity.c fight.c \
          handler.c hashstr.c ident.c interp.c magic.c makeobjs.c \
          mapout.c misc.c mpxset.c mud_comm.c mud_prog.c player.c polymorph.c \
          reset.c save.c shops.c skills.c special.c tables.c \
          track.c update.c grub.c ban.c services.c planes.c \
          imm_host.c  status_update.c



(edit)

I notice your post mentions an update.cpp file. That is presumably where the status_update routine is to go. This implies you are using C++ rather than C, but the rest of my comments stand.
Amended on Mon 12 Jul 2004 10:10 PM by Nick Gammon
USA #2
Thanks for the much needed answer, and I realized what I had done...

I had 2 versions of this script (update_stats) and (status_update)..

what i had done was written out update_stats for my void (the one with all the info) and it wasnt finding my origional 100+ lines of code.. and to fix this, naturally, i renamed it, and now it works, =)


Thanks for the well spent tie in writing the post, it made me realize the error of my ways =)


EDIT: ugh, now this problem...


void status_update (CCharacter *ch)
{
ASSERT (ch);
if (! ch->IsNpc())
CClassData *pClass = ClassTable.GetClassData (ch->GetClass ());
{
int con = (int) ch->GetConstitution();



I am getting a critical error on an ASSERT: problem dealing with that line there... what exactly needs to be defined there for it to work correctly...

note - it wasnt a compiling error, it compiled clean, the error happened when i ran my .exe and loaded it up.. crashed upon loading





***
EDIT - AGAIN: Okay, i compiled again after seeing nothign wrong with the code.. and it works, loaded up playing correctly... AND, my script is working successfully, i origionall had it toied in with a Pulse check for mobiles, but that took too long (up to a minute for stats to update), now every time my prompt loads up, it activates the script.. WOOHOO, Buggy Windows XP sure has its quirks, eh? =)
Amended on Mon 12 Jul 2004 10:20 PM by Mike Scherling
Australia Forum Administrator #3
The ASSERT looks OK, sounds like a bug that it was calling the routine with a null ch.

It is almost worth taking the assert out and letting it crash, then use the debugger to find where it was called from.

Alternatively, guard yourself like this:


if (ch == NULL)
  {
  // maybe log an error message
  return;
  }