LNK2001 - unresolved external symbol (stat)

  • Thread starter Thread starter Murray Foxcroft
  • Start date 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)
 
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
 
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-(
 
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
 
I got away with using the managed stuff - File.Exists and <myfile>.Length

Thanks for the help tho - much appreciated.
 
Back
Top