Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

unresolved external symbols 1

Status
Not open for further replies.

ravenspawn

Technical User
May 3, 2001
13
US
what might be wrong with this code:

#include <stdio.h>
#include &quot;dirent.h&quot;
#include <stdlib.h>


int main()
{
struct S_Dir* dirp;
struct dirent* direntp;

dirp = opendir( &quot;C:/WINDOWS/Desktop/OATS_MONITOR/OATS/usr/home/clf&quot; );
if( dirp != NULL ) {
for(;;) {
direntp = readdir( dirp);
if( direntp == NULL ) break;

printf( &quot;%s\n&quot;, direntp->d_name );
}

closedir(dirp );

return 0;
} }

it comes up with an error-
directorything.obj : error LNK2001: unresolved external symbol &quot;void __cdecl closedir(struct S_Dir *)&quot; (?closedir@@YAXPAUS_Dir@@@Z)
 
Check &quot;dirent.h&quot; or &quot;dirent.cpp&quot; (if it exists) you might have a funtion without a prototype. Rob Marriott
rob@career-connections.net
 

This code is used to traverse a directory in UNIX systems
using C. I dont know how you got it to compile using VC++, since VC doesnt have the header &quot;dirent.h&quot; and assoc. functions. Instead use the normal dialog box with OPENFILENAME to get files in a directory.

If you want the code you can mail me.

Regards,
abp :))
 
Evidently you have dirent.h because your not getting a compile-time error (or are you?). The link-time error appears because you are not linking to the object file or library file containing the compiled &quot;closedir()&quot; function.
The header file must exist because the linker knows to much about the function it is trying to resolve. None protoyped functions are assumed to return &quot;int&quot;. If you have the dirent.c source file then make sure this is included in your project file or make file depending on the development environment.
 
As a second thought, a better way to list directory contents
in Windows is to use the Win API functions FindFirstFile() and FindNextFile() in a loop. I have posted some code, in reply to your second question.

Best Regards,

abp :cool:
 
abp,

Actually, the findfirstfile() won't work for what I am needing. I am using VC++, but the code has to work on a Unix server as well.

Will
 

I dont understand. Could you post some
code ?

abp :cool:
 
{
int count;
struct DIR *d;
if( (d = opendir(&quot;.&quot;)) != NULL)
{
for(count = 0; readdir(d) != NULL; count++);
closedir(d);
}
printf(&quot;\n %d&quot;, count);
return 0;
}

 
If your trying to do this on UNIX then a typical readdir for loop would look like this:

DIR* temp;
struct dirent *dirp;

if((temp = opendir(&quot;.&quot;)) == NULL)
{ /* error */ }

for(dirp=readdir(temp); dirp!=NULL; dirp=readdir(temp))
printf(&quot;%s\n&quot;, dirp->d_name);
closedir(temp);

As far as making this run on windows and unix you are pretty much screwed because they both have fairly different directory handling functions. You would have to make two separate files and use the appropriate one depending on what system your on. Plus it depends whether or not this is a Windows question or a DOS question. Do you have to do this graphically or can you do it behind the scenes?

bitwise
 
Bitwise,

I kinda figured I'd be shooting in the dark. What I have to work with is VC++, but the program itself is to be implemented onto a Unix server.
The actual program takes the number of files in a directory and throws the output onto an HTML page using JavaScript. All of this works at this point in time except the counter and when I get the chance to test this shall hopefully (with your assistance and advice) get this to work). Otherwise, there'll be some kicking accomplished to vent some frustration. I thank everyone who has put forth their knowledge in trying to assist in this problem.

Will
 
So your saying your just developing it on windows but it needs to run on UNIX? If you only need to get the count of the directory contents your code above works fine. Keep in mind that it includes the '.' and '..' directory plus any other '.file'. If it has to run on UNIX then your going to have to compile it on UNIX anyway so there's no point in trying to get link on Windows. I think you need to get a UNIX account for whatever your doing. Alternatively, if you had Linux you would could develop it there b/c they both use glibc but...do you?

bitwise
 
Bitwise,

Actually the app now runs. My main frustration was that I didn't have access to the Unix server until I harassed a friend outside of work to check it out for me and it runs as desired.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top