Author Topic: SDL and VC compiler  (Read 6105 times)

Offline sushi_cw

  • Single posting newcomer
  • *
  • Posts: 6
SDL and VC compiler
« on: August 29, 2005, 09:41:36 pm »
I'm trying to build a simple SDL project in codeblocks using the VC compiler, and (obviously) having difficulty.

I'm using the VC6 SDL binaries from libsdl.org.
I've got the paths all set up correctly, no problems there.
I've set the "Multi-threaded DLL runtime library" flag in the project build options.
I have a single source file, main.cpp, with the following code:
Code: [Select]
#/* -- Include the precompiled libraries -- */
#ifdef WIN32
#pragma comment(lib, "SDL.lib")
#pragma comment(lib, "SDLmain.lib")
#endif
#include "SDL.h"

int main(int argc, char **argv)
{
printf("\nHello SDL User!\n");

/* initialize SDL */
if ( SDL_Init( SDL_INIT_VIDEO ) < 0 )
{
fprintf( stderr, "Video initialization failed: %s\n",
SDL_GetError( ) );
SDL_Quit( );
}
SDL_Quit( );
return 0;
}

When I try to build, it compiles fine, but returns the following link error:
LINK : fatal error LNK1561: entry point must be defined

I've googled this error, and apparently it usually happens when a main() function isn't defined. As you can see, I have one. Any ideas what I am missing?

PS: Please forgive my newb-ness, especially if I am missing something really obvious. :)
« Last Edit: August 29, 2005, 10:19:46 pm by sushi_cw »

Offline grv575

  • Official tester
  • Regular
  • ***
  • Posts: 381
Re: SDL and VC compiler
« Reply #1 on: August 30, 2005, 01:06:18 am »
1. set default compiler to vc++ toolkit
2. create a new project, select sdl application
3. extract the sdl vc6 developer zip somewhere
4. set project build options:
    compiler directories - add sdl header include directory
    linker directories - add sdl lib directory
    linker - remove mingw32 library
    *** other linker options: /subsystem:windows
    (that should be a bug report but no linker options checkboxes are available :/ :\ :0 )
    hexedit SDLmain.lib (j/k) - you'll see DEFAULTLIB:"MSVCRT" which is the dll C runtime so we must also use this runtime in our app
    (unless you download the SDL source and add SDLmain.cpp to your project instead of linking against SDLmain.lib):
       compiler options - Multi-threaded DLL Runtime library
5. realize you don't have the .lib for this runtime
    build it: see http://forums.codeblocks.org/index.php/topic,748.msg5614.html#msg5614 (step 4b)
6. rebuild

btw, general vc++ toolkit libraries setup:
http://wiki.codeblocks.org/index.php/FAQ#I_can.27t_compile_a_multithreaded_app_with_VC_Toolkit.21_Where_are_the_libraries.3F
http://wiki.codeblocks.org/index.php/Integrating_Microsoft_Visual_Toolkit_2003_with_Code::Blocks_IDE

Offline sushi_cw

  • Single posting newcomer
  • *
  • Posts: 6
Re: SDL and VC compiler
« Reply #2 on: August 30, 2005, 03:05:45 am »
As it turned out, all that I still needed to do was add the "/subsystem:windows" link option. One of these days I'll actually understand how all of this works... :) Thanks for the help!


megizin

  • Guest
Re: SDL and VC compiler
« Reply #3 on: October 26, 2005, 05:16:07 pm »
What does the "/subsystem:windows" linker option do?  I was building a project that could not make the dll from the lib (had a bunch of unresolved external symbol __fltused errors on linking) but when I added this option to the linker options, it worked.  I am using a multithreaded dll project (OgreMain, from Ogre3d) with Code::Blocks v1.0 RC2 using VC Toolkit 2003.

Thanks in advance!

megizin

  • Guest
Re: SDL and VC compiler
« Reply #4 on: October 27, 2005, 05:51:22 am »
Ok, I found this out.  LINK.exe has the /subsystem option to let the compiler know how the exe will be run (as a console, as a windows app, as a dll...).  I'm not sure what all it does exactly, but one thing is change the entry point (/entry) to WinMain instead of main if I use /subsystem:windows

now you know.