LNK2001 - unresolved external symbol (stat)

  • Thread starter Murray Foxcroft
  • Start date
M

Murray Foxcroft

Hi all -

Can anyone tell me what I should link in to get the following error sorted?
Also - for future reference - any quick ways to resolve a linker reference
from an include like #include <sys/stat.h> in order to beat these linker
errors quickly?


error LNK2001: unresolved external symbol "int __cdecl stat(char const
*,struct stat *)" (?stat@@$$J0YAHPBDPAU0@@Z)
 
T

Thobias Jones

Murray said:
Also - for future reference - any quick ways to resolve a linker reference
from an include like #include <sys/stat.h> in order to beat these linker
errors quickly?

There isn't necessarily a correllation between header includes and
linker import libraries. You should consult your API documentation to
find out what import libraries are required for the functions you intend
to link against. In general, Visual Studio sets up default import
libraries for common Windows APIs and the C standard library.

The function stat() should have been included in one of those default
libraries, likely libcmt.lib. I haven't physically checked this myself
for the case of stat(), but this is what the documentation has.

Thobias Jones
 
M

Murray Foxcroft

Thanks Thobias,

As far as the documentation is concerned, it should have been in
msvcrt.lib - which is linked in to my project already. 8-(
 
T

Thobias Jones

Murray said:
Thanks Thobias,

As far as the documentation is concerned, it should have been in
msvcrt.lib - which is linked in to my project already. 8-(

Is there some reason you are linking against stat() instead of _stat()?
If you really need stat(), link against oldnames.lib.

Thobias Jones
http://ace.roqs.net
 
M

Murray Foxcroft

I got away with using the managed stuff - File.Exists and <myfile>.Length

Thanks for the help tho - much appreciated.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top