Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unresolved symbol `__imp__iob`, not `__imp___iob`

I'm compiling a program with Visual Studio 2017 that links with the precompiled static version of libusb, available here.

When I tried to link it I got some unresolved symbols like these and the answers pointed me to legacy_stdio_definitions.lib which resolved all of the linker errors except:

unresolved external symbol __imp__iob

This page from Microsoft talks about legacy_stdio_definitions.lib and says it provides __imp___iob but doesn't mention __imp__iob (note the different number of underscores).

What's going on here?

(Also, yes mixing CRT versions is a bad idea and I should really compile libusb from source. I know.)

like image 816
Timmmm Avatar asked Mar 18 '18 22:03

Timmmm


1 Answers

Had the same problem with libusb on VS2018 - 32bit, this helped me:

  1. Hacky solution: Linker complains about some missing function -- so just give it to it -- such function should return the implementation defined IO function pointers. For statically linked libusb-1.0 I had to add the following to my code:

    #pragma comment(lib, "legacy_stdio_definitions.lib")
    #ifdef __cplusplus
    FILE iob[] = { *stdin, *stdout, *stderr };
    extern "C" {
        FILE * __cdecl _iob(void) { return iob; }
    }
    #endif
    
  2. Better solution: Simply recompile static libs under VS 2018 (which I assume you are also using) and follow carefully the Readme file attached.

like image 157
Kupto Avatar answered Sep 18 '22 20:09

Kupto