11

so i'm getting the following errors:

1>SDL2main.lib(SDL_windows_main.obj) : error LNK2019: unresolved external symbol __imp__fprintf referenced in function _ShowError
1>SDL2main.lib(SDL_windows_main.obj) : error LNK2019: unresolved external symbol __imp____iob_func referenced in function _ShowError

my code is simply:

#include <iostream>
#include "SDL2\SDL.h"

int main(int argc, char* argv[])
{
    std::cout << "Hello World!" << std::endl;

    return 0;
}

i've linked the libraries correctly, and this works fine in vs2012, but for some reason won't compile in vs2015.

jape670
  • 141
  • 1
  • 6
  • 2
    @KenWhite can you not? – jape670 Jan 31 '15 at 06:41
  • VS2015 uses a completely rewritten CRT. It's not terribly surprising that things like this will break; you may need to just recompile SDL2main. – Sean Middleditch Feb 06 '15 at 00:11
  • that's what i did, i was just asking in case there was a quicker way to do things, not that recompiling sdl took long, but i was just wondering if there was a project setting i could change or something. – jape670 Feb 07 '15 at 05:26
  • 2
    A quicker way is to download a [Windows build](https://buildbot.libsdl.org/sdl-builds/sdl-visualstudio/) from the SDL build bot as suggested [here](http://www.gamedev.net/topic/664434-problem-installing-sdl-in-visual-studio-2015/#entry5210967). This may not be stable enough to release with but likely fine for development. – John McFarlane Jul 17 '15 at 23:20

3 Answers3

4

I had the same issue with SDL 1.2 - the solution that worked for me was to download SDL source and build the lib with VS 2015. The problem was fixed when I linked to the newly (VS2015) built libs - maybe someone should try the same for SDL 2 (rebuild lib from source)?

oddsock
  • 41
  • 2
2

idk if it's something in vs2015's default runtime libraries why it's causing these unresolved externals or something not default linked anymore when making a win32 console project, but one of the unresolved externals go away when i switch the runtime library to /MTd, imp_iob_func still appears, but the solution i ended up going with is downloading the sdl2 source code, which is free, going to the sdl2main project file, editting the showerror function

from

fprintf(stderr, "%s: %s\n", title, message);

to

printf("%s: %s\n", title, message);

so, this may or may not be a horrible idea, but hey well, it builds and compiles. i just replaced my sdl2main.lib with the new modified one. and voila no more linker error. so this may or may not have been a horrible mistake and will bite me whenever i ask sdl to produce an error message. i'll probably add an edit or comment to this in the future if i find a better solution or confirm this was a big mistake. but this is what i got to work.

jape670
  • 141
  • 1
  • 6
  • 2
    I'm running into the exact same issue, and while using printf instead of fprintf does solve one of the linker errors, what about the other? I'm still experiencing the "__imp____iob_func" error and have no clue on what's causing it. – Dids May 19 '15 at 20:47
  • 1
    this is probably already really late since i don't hang out on stack overflow often, can you paste the exact error you're getting, also as it turns out, vs2015 deprecated certain c libraries, what's likely happening is that the sdl source is calling function overloads or values in c libraries deprecated in vs2015. replacing those function calls with more their new equivalents is probably the best way going about it. – jape670 Jun 12 '15 at 22:56
  • 1
    The exact error is "SDL2main.lib(SDL_windows_main.obj) : error LNK2001: unresolved external symbol __imp____iob_func". – Dids Jun 13 '15 at 06:05
  • 1
    Fixing the "__imp__fprintf" error was simple enough, but "iob_func" gives no clues as to what function is causing it. :( – Dids Jun 13 '15 at 06:06
  • 1
    Figured it out! It was a weird issue with linker search paths. Seems to compile now. :) – Dids Jun 13 '15 at 06:56
  • 1
    Wait, VS2015 deprecated `fprintf`?!?! – a paid nerd Jun 13 '15 at 21:30
  • 1
    @apaidnerd no, they deprecated stderr, it's all cerr now – jape670 Jun 14 '15 at 02:51
0

Have you tried just creating a unused function in your own project referring to these unresolved functions i.e.

void HackToReferencePrintEtc()
{
    fprint(stderr, "%d", 1);
    // Add other unresolved functions
}

This solved some issues we had when using Intel MKL which refers to printf, where the linker kept giving unresolved externals, but adding the above to StdAfx.cpp (precompiled file) fixed it.

nietras
  • 3,949
  • 1
  • 34
  • 38
  • Though this trick makes the error disappear (in VS2017), it produces the warning LNK4217: locally defined symbol _fprintf imported in function _ShowError – AntonK Jul 04 '17 at 13:59