2
votes

I am trying to do one that requires I use SDL2 and I was excited to finally start attempting to write a program. I downloaded SDL2 and didn't have any problems.

Next I opened a new empty project followed the instructions to add the include folder, lib(x86) folder, and I added the sdl2.lib and sdl2main.lib to the linker.

When I tried to build the project I received the following error.

1>MSVCRTD.lib(cinitexe.obj) : warning LNK4098: defaultlib 'msvcrt.lib' conflicts with use of other libs; use /NODEFAULTLIB:library 1>sdl2main.lib(SDL_windows_main.obj) : error LNK2019: unresolved external
symbol _SDL_main referenced in function _main 1>c:\users\nas\documents\visual studio 2013\Projects\Basic SDL\Debug\Basic SDL.exe : fatal error LNK1120: 1 unresolved externals

1

1 Answers

1
votes

You need to link to the library files.

  1. Right click the project and then properties
  2. Click VC++ Directories.
  3. Click include directories, then the down arrow, then <edit>.
  4. Then add the directory of the include files (where all the .h files are, for example E:\Visual Studio .NET\SDL2-2.0.3\Include).
  5. Then do the same for the library files by clicking library directories',down arrow,edit. However, you will want to make sure you are targeting x86 (for 32 bit program for exampleE:\Visual Studio .NET\SDL2-2.0.3\lib\x86`) or x64 (64bit program, not so common)
  6. Then expand linker and click input on the left hand side.
  7. Click additional dependencies, and then edit and add SDL2.lib and SDL2main.lib.
  8. Click system under the linker heading.
  9. Change SubSystem to /SUBSYSTEM:CONSOLE.
  10. Finally make sure the SDL.dll file is in the folder of your project debug folder.