resolve link errors for __imp__open and other similarly named functions using Microsoft Visual C++ 6.0

5k Views Asked by At

Link errors like this sometimes occur when compiling C++ using Microsoft Visual C++ 6.0:

error LNK2001: unresolved external symbol __imp__close
error LNK2001: unresolved external symbol __imp__read
error LNK2001: unresolved external symbol __imp__lseek
error LNK2001: unresolved external symbol __imp__open

My fix, which I found after searching fruitlessly using Google for a long time, is this:

Do NOT disable language extensions. In the Project Settings dialog, in the C/C++ tab, make sure that the 'Disable language extensions' checkbox is not checked.

The functions close, read, lseek, open, etc., are not standard parts of the C library and the declarations are skipped by conditional compilation using #if !__STDC__ in <io.h>. This happens if you disable language extensions.

1

There are 1 best solutions below

1
On

The answer is that the __imp prefix refers to function stubs in the OBJ library for the DLL version of the CRT. This means your linker options are incompatible with your compiler options (linker set to static CRT or no CRT and compiler set to dynamic CRT).

In your case rather than the CRT itself it is another library, but the same idea.