unresolved external symbol (dirent.h)

Posted by ShadowFangs on Sun 03 Oct 2004 03:15 AM — 6 posts, 37,240 views.

#0
Hey all, Using MSVC 6.0

I read that An unresolved external means that you have called a function or variable but that the function or variable is not defined in the code linked to the executable.

these are the errors.
error LNK2001: unresolved external symbol _closedir
error LNK2001: unresolved external symbol _readdir
error LNK2001: unresolved external symbol _opendir

Great, so that means that this function wont work.

void do_plist(CHAR_DATA *ch, char *argument)
{
DESCRIPTOR_DATA *d;
BUFFER *pbuf;
struct dirent *Dir;
DIR *Directory;
char FName[80];
char buf[MSL];
int nMatch, neat1;
char neat[MSL];
char neat2[MSL];
char neat3[MSL];

nMatch = 0;

pbuf = new_buf();
d = new_descriptor();
Directory = opendir( PLAYER_DIR );
Dir = readdir( Directory );
send_to_char("{C PLAYER BASE {x\n\r",ch);
send_to_char("{RName lvl Race Class {x\n\r",ch);
send_to_char("{R==============================================={x\n\r",ch);
while( Dir != NULL )
{
sprintf(FName, PLAYER_DIR "%s", Dir->d_name);
{
if (Dir->d_name[0] >= 'A' && Dir->d_name[0] <= 'Z')
{
nMatch++;
load_char_obj( d, Dir->d_name );
if ( d->character->level <= ML )
{
sprintf(neat, "%s", Dir->d_name);
neat1 = d->character->level;
sprintf(neat2,"%s", capitalize(race_table[d->character->race].name));
sprintf(neat3,"%s", capitalize(class_table[d->character->class].name));


sprintf(buf, "{B[{c%-12s{B][{c%-2d {B][{c%-10s {B][{c%-12s {B]{x\n\r",
neat, neat1, neat2, neat3);
add_buf(pbuf, buf);
}
}
}
Dir = readdir( Directory );
}
closedir( Directory );
page_to_char(buf_string(pbuf), ch);
free_buf(pbuf);
sprintf( buf, "\n\r{cPlayers found{C: {Y%d{x\n\r", nMatch );
send_to_char( buf, ch );
return;
}

Any suggestions?

Canada #1
Yeah, a little searching on google, looks like they functions are just not in MSVC. I did read something that said you can try to use some defines, like
    #ifdef MSVC 
    #define open _open 
    #define O_RDONLY _O_RDONLY 
    #define fstat fstat 
    #define S_ISREG(m) ((m)&_S_IFREG) 
    #endif
This comes from http://www.cs.mu.oz.au/research/mercury/mailing-lists/mercury-users/mercury-users.0105/0076.html, that might help.

I also found this:
Quote:
One of the least standard aspects of libc is how to read what files are contained in a directory. Most DOS and Windows compilers have some kind of findfirst() and findnext() functions, but they differ as to exactly what these are called and what parameters they take. Posix systems (Unix, djgpp) have opendir() and readdir(), but these are missing from MSVC. So either don't do such things, or use the Allegro for_each_file() function, which is supported on all platforms.


I do not have MSVC myself, though, so I can't confirm any of this.
#2
Well, this being known now, is there any other way to do what i want this function to do? Any help is appreciated, thanks
Canada #3
Well, one option is to forget MSVC and try something like cygwin. Its free and tends to work fairly well. This - http://msdn.microsoft.com/library/en-us/dnucmg/html/ucmglp.asp - may also be of some help.
USA #4
Another option is to search the forum for dirent and copy the info Nick provided me a while back into a header file for your MSVC project.
Amended on Mon 04 Oct 2004 01:34 AM by Meerclar
Australia Forum Administrator #5
I did a simulation of the dirent stuff. It is in the SMAUG port.