VS2019 linker error using SDL library

Pages: 12
Hi All

I'm trying to use SDL 1.2 library.
I'm using Visual Studio 2019 with v142 compiler.I have linked to SDL.lib and SDLmain.lib in Linker -> Input -> Additional Dependencies and I have made sure that the VC++ Directories are correct.

But I end up with below linker errors in VS 2019. Any idea how to solve this?



Error LNK2001 unresolved external symbol __imp__fprintf C:\Users\Denver\Documents\Test\SDLmain.lib(SDL_win32_main.obj) 1
Error LNK2001 unresolved external symbol __imp____iob_func \Users\Denver\Documents\Test\SDLmain.lib(SDL_win32_main.obj) 1

Is it vs 2019 compiler issue?
To fix Error LNK2001 unresolved external symbol __imp__fprintf issue, I added legacy_stdio_definitions.lib to my Linker ->Input->Additional Dependencies. Then the issue is gone.
I can see it under C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\lib\legacy_stdio_definitions.lib

Now all I need is to know how to fix the below error?
Someone please help me on this.

Error LNK2001 unresolved external symbol __imp____iob_func \Users\Denver\Documents\Test\SDLmain.lib(SDL_win32_main.obj) 1
Last edited on
I found this solution and added these lines to my VS 19 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.
But after adding the above lines to fix for the errors (LNK4098- defaultlib 'msvcrt.lib' conflicts with use of other libs; use /NODEFAULTLIB:library) and (LNK2019- unresolved external symbol __imp__iob_func references in function ShowError) during Debug Build compilation of my App.exe in VS2019, I now get run time exception as below.

Exception thrown at 0x00007FF9D4A1FD01 (ntdll.dll) in App.exe: 0xC0000005: Access violation reading location 0x0000000000000010.


Below is the line of code that throws run time exceptions in C:\Program Files (x86)\Microsoft VisualStudio\2019\Professional\VC\Tools\MSVC\14.29.30133\crt\src\vcruntime\exe_common.inl

#if defined _SCRT_STARTUP_MAIN

using main_policy = __scrt_main_policy;
using file_policy = __scrt_file_policy;
using argv_policy = __scrt_narrow_argv_policy;
using environment_policy = __scrt_narrow_environment_policy;

static int __cdecl invoke_main()
{
return main(__argc, __argv, _get_initial_narrow_environment());
}




Can anyone tell me how to fix these errors? Is it VS2019 compiler issue? My Debug version should uses /MDd consistently. Still not able to figure out why these errors are seen? Any help would be appreciated here as I am stuck with this now and not able to proceed with it.
If I remove below code, it gives LNK4098, LNK2019. if I add this code, end up with run time exception with thrown at 0x00007FF9D4A1FD01 (ntdll.dll) in App.exe: 0xC0000005: Access violation reading location 0x0000000000000010. Any fix for this issue?

1
2
3
4
5
6
7
#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; }
I did small workaround by going to Configuration Properties-> Linker-> Input, then Selected Ignore All Default Libraries and set to Yes(/NODEFAULTLIB). after I compile now, then error is gone (LNK4098 - defaultlib 'msvcrt.lib' conflicts with use of other libs; use /NODEFAULTLIB:library), but end up with new set of errors seen from all my project .obj files like

LNK2001 unresolved external symbol "void_cdecl operator delete(void*, unsigned_int64)"
LNK2001 unresolved external symbol _RTC_InitBase
LNK2001 unresolved external symbol _RTC_ShutDown
LNK2001 unresolved external symbol _RTC_CheckStackVars
LNK2001 unresolved external symbol _purecall
LNK2001 unresolved external symbol _std_exception_copy
LNK2001 unresolved external symbol _std_exception_destroy
LNK2001 unresolved external symbol _CxxThrowException
LNK2001 unresolved external symbol _CxxFrameHandler4
LNK2001 unresolved external symbol memcpy
LNK2001 unresolved external symbol memmove
LNK2001 unresolved external symbol strlen
LNK2001 unresolved external symbol mainCRTStartup



Is this due to Cruntime library and VS service package issues? How to fix this?
Last edited on
RTC errors are gone after doing the below workaround
Configuration Properties->C/C++->Code Generation -> Basic Runtime Check, and change the value from "Both(...)" to "Default Value".



But rest of the errors still exists.
LNK2001 unresolved external symbol "void_cdecl operator delete(void*, unsigned_int64)"
LNK2001 unresolved external symbol _purecall
LNK2001 unresolved external symbol _std_exception_copy
LNK2001 unresolved external symbol _std_exception_destroy
LNK2001 unresolved external symbol _CxxThrowException
LNK2001 unresolved external symbol _CxxFrameHandler4
LNK2001 unresolved external symbol memcpy
LNK2001 unresolved external symbol memmove
LNK2001 unresolved external symbol strlen
LNK2001 unresolved external symbol mainCRTStartup
I reverted back all my workarounds and was able to overcome the below errrors after I downloaded and compiled and then generated .lib and .dll separately for SDL source .

Error LNK2001 unresolved external symbol __imp__fprintf C:\Users\Denver\Documents\Test\SDLmain.lib(SDL_win32_main.obj) 1
Error LNK2001 unresolved external symbol __imp____iob_func \Users\Denver\Documents\Test\SDLmain.lib(SDL_win32_main.obj) 1
I am trying to compile SDL_image source and end up with below errors.

Error LNK1104 cannot open file '..\Release\SDL_image.lib' showimage

The reason here is that while I run into an error “cannot open file ..\Release\SDL_image.lib” this error occurs because the SDL_image project place it’s .lib file in the wrong location we can either change the path to ..\x64\Release\SDL_image.lib or move the .lib file to the desired path.

Where exactly can I find ( ..\Release\SDL_image.lib”) or change it?
I tried to search for LINK file in VS, but not able to find it.




See this:

http://wiki.libsdl.org/Installation

SDL Wiki wrote:
On Windows, SDL does not depend on a C runtime at all, not even for malloc().
So you shouldn't have all this problems.

SDL Wik wrote:
SDL currently provides Visual Studio project files for Visual Studio 2010 or later in various flavors
Did you try that? Or the CMake variant?
I have seen this link before, but not helping to resolve this issue. I was able to compile the code for SDL and get SDL.dll , SDL.lib, SDLmain.lib. Similarly I need to get SDL_image.lib (which is current issue), gives error while linking as seen below.. I use VS2019 on Windows 10 64 bit. Trying to compile source code for SDL_image-1.2.12.zip and end up with only this error. It looks like the linker path is wrong.
How can I modify it in vs?

Error LNK1104 cannot open file '..\Release\SDL_image.lib' showimage
Last edited on
Do you actually have an SDL_image.lib somewhere on your system? Is it a file you've built, or is it one you've downloaded/installed from elsewhere?
I had downloaded source code for SDL_image and then tried to build it by launching .sln under VisualC folder.
I did a Debug build for 64 bit and got that linker error.
Yes, I can see SDL_image.lib under the below path.
SDL_image-1.2.12\SDL_image-1.2.12\VisualC\x64\Debug\SDL_image.lib


I guess it got created at the wrong path during the build and hence Linker is looking for this file in some other path. All I need to know is
where in Linker file I should modify or add any new path to resolve Error LNK1104 cannot open file '..\Release\SDL_image.lib'?


Just add that directory to the list of paths where the linker will look for files to link against.
Few more details about the error:

Severity Code Description Project File Line Suppression State
Error LNK1104 cannot open file '..\Release\SDL_image.lib' showimage C:\Users\Denver\Documents\Test\SDL_image-1.2.12\VisualC\showimage\LINK 1

Severity Code Description Project File Line Suppression State
Error MSB6006 "link.exe" exited with code 1104. showimage C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets 1074

Hi MikeyBoy


I added the this (C:\Users\Denver\Documents\Test\SDL_image-1.2.12\VisualC\x64\Debug) directory path under Linker->General->Additional Library Directories.
Then Rebuild my VS solution, but still has got the same errors.

I refer to this link, where its mentioned "Following these steps will have you run into an error “cannot open file ..\Release\SDL_image.lib” this error occurs because the SDL_image project place it’s .lib file in the wrong location we can either change the path to ..\x64\Release\SDL_image.lib or move the .lib file to the desired path."
How to do this? this is my actual problem here...But I dont understand what needs to be done here?


https://nolte96.wordpress.com/2018/12/01/attempting-to-build-goblin-camp/
OK, wait. It looks as though you have a Debug build of SDL_image.lib, and your project is looking for a Release build. Try doing a Release build of SDL_image.lib, and see if that works.
Pages: 12