C.O.
C.O.

Reputation: 2329

Visual Studio error LNK2001: unresolved external symbol _fgetc_unlocked

I'm trying to use libjasper from http://www.ece.uvic.ca/~frodo/jasper/ as a static library in compiling dcraw.c from http://www.cybercom.net/~dcoffin/dcraw/ on windows with VC9. I have resolved several issues on the way and finally get three linking errors.

1>dcraw.obj : error LNK2001: unresolved external symbol _ftello
1>dcraw.obj : error LNK2001: unresolved external symbol _fseeko
1>dcraw.obj : error LNK2001: unresolved external symbol _getc_unlocked

the first two of these are easily resolved it seems, I added

#define fseeko _fseeki64
#define ftello _ftelli64

and that does it but what about the third one:

1>dcraw.obj : error LNK2001: unresolved external symbol _getc_unlocked

How can I work around that on windows with visual studio?

Thanks.

Upvotes: 2

Views: 2309

Answers (4)

James M
James M

Reputation: 16718

#define getc_unlocked _fgetc_nolock

Only difference is that getc is thread-safe (and probably slower).

http://pubs.opengroup.org/onlinepubs/000095399/functions/getc_unlocked.html

EDIT: As @Fanael pointed out in another answer, _fgetc_nolock makes for a better replacement than getc.

Upvotes: 1

JimR
JimR

Reputation: 16153

Replace calls to getc and getc_unlocked with fgetc when compiling for Windows.

I vaguely remember ftello, fseeko and possibly getc_unlocked as being specific to linux/gcc/posix.

getc is roughly prototyped as int getc( FILE* f);

fgetc is roughly prototyped as int fgetc( FILE* f );

and, in fact, in MSVS 10, getc is a define for fgetc.

Upvotes: 0

user784668
user784668

Reputation:

The actual equivalent of getc_unlocked is not getc, it's _fgetc_nolock. So, assuming that whoever wrote the original code knew what he's doing and had some reasons to prefer the thread-unsafe version, you probably want this:

#define getc_unlocked _fgetc_nolock

Upvotes: 5

Martin Beckett
Martin Beckett

Reputation: 96147

It's a posix function not on win32, just do

#define getc_unlocked fgetc

Upvotes: 0

Related Questions