rothran670
rothran670

Reputation: 141

How to fix unresolved externals of SDL 2.0.3 on Visual Studio 2015 Preview?

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.

Upvotes: 11

Views: 9686

Answers (3)

oddsock
oddsock

Reputation: 41

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)?

Upvotes: 4

nietras
nietras

Reputation: 4048

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.

Upvotes: 0

rothran670
rothran670

Reputation: 141

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.

Upvotes: 2

Related Questions