3

I am tryig to compile an application in VS2017 (C++) and I get the errors:

1>libeay32.lib(cryptlib.obj) : error LNK2001: unresolved external symbol ___iob_func
1>libeay32.lib(pem_lib.obj) : error LNK2001: unresolved external symbol ___iob_func
1>libeay32.lib(ui_openssl.obj) : error LNK2001: unresolved external symbol ___iob_func

Other posts reported on such an error are for VS2015 and refer to stdin, stdout and stderr. But those fixes have not worked for me.

Strangely, if I go to stdin in the code and (right click) go to definition it takes me to Visual Studio 11.0 include directories, not the VS2017 ones.

My error is in libeay32.lib which I can't find a C++ source for anywhere.

Has anybody else had this problem?

JustBaron
  • 2,319
  • 7
  • 25
  • 37
Chris H Baker
  • 31
  • 1
  • 1
  • 3
  • Looks like someone was directly messing around with the internals of `FILE` which is unsupported and not available in VS2015 and upwards. – Mgetz May 18 '18 at 12:26
  • 1
    Add C++ standard library to linker i.e. `msvcrt.lib` – Victor Gubin May 18 '18 at 12:29
  • @VictorGubin linking against MSVCRT is not supported or recommended and should be avoided for binary compatibility reasons. – Mgetz May 18 '18 at 12:37
  • Possible duplicate of [unresolved external symbol \_\_imp\_\_fprintf and \_\_imp\_\_\_\_iob\_func, SDL2](https://stackoverflow.com/questions/30412951/unresolved-external-symbol-imp-fprintf-and-imp-iob-func-sdl2) – Mgetz May 18 '18 at 12:39
  • 1
    You are trying to link a library that was built with the wrong VS version. And old one so you don't get a better linker error. The IDE navigating to the wrong directory is another excellent hint. You must obtain an up-to-date build of it. – Hans Passant May 18 '18 at 13:19

1 Answers1

5

I found this solution and added these lines to my VS 17 C++ project

#define stdin  (__acrt_iob_func(0))
#define stdout (__acrt_iob_func(1))
#define stderr (__acrt_iob_func(2))

FILE _iob[] = { *stdin, *stdout, *stderr };
extern "C" FILE * __cdecl __iob_func(void) { return _iob; }

This worked for me.
ari
  • 51
  • 1
  • 5
  • 2
    Instead of just posting the code, please also explain how that works for you and/or what difference does it make – Andreas Nov 28 '18 at 05:59