#1221 Can't compile with SDL with MSVC++ VS 2008

fixed_in_v2.5
closed
5
2014-05-24
2010-04-18
M8R-icxd4w
No

I can't compile the bochs-2.4.2-src with MS Visual Studio 2008 when I use --with-sdl configuration parameter.
The compile works fine (still many warnings, though), but at the linking stage I get
Error 2 error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup LIBCMTD.lib bochs
I tried to follow http://bochs.sourceforge.net/doc/docbook/user/compiling.html#COMPILE-SDL as closely as possible. I added the path to SDL (for the bochs project and the gui project), the SDL.lib for bochs. I had to comment out line 63-65 in sdlkeys.h. I added gui/sdl.cc to gui, but I did not remove the gui/win32.cc, because then I get an unresolved symbole more.

Anyone knows who get it to compile?

I have to say, that I can compile the sources perfectly fine with the cygwin compiler (with SDL enabled!). So I can use SDL to get Bochs in fullscreen running on my Windows 7 64x. (You have to specify fullscreen as display option).
You may wonder why I care about MSVC, by I started with that and spent much time to figure it out, and it still doesn't work!

Discussion

  • M8R-icxd4w
    M8R-icxd4w
    2010-04-18

    I must add, that there is a warning when I run sh ./conf.win32-vcpp : The pthread.c can't be compiled. It seems that the cl.exe (MSVC++) can't find strings.h. MSVC is only shipped with string.h, so maybe that's somehow related. I have added the VS path fromt he command promt batch file to my bochs environment.

     
  • Hello.
    Here is my receipt of make it working. I used last stable releases: Bochs 2.4.6 and SDL 1.2.14.

    • comment out strings in gui\sdlkeys.h contaning comment inside macro params (62..64 in my case);
    • if you included --with-win32 in source configuration file then don't exclude gui\win32.cc from the gui project;
    • besides SDL.lib you must include SDLmain.lib too in bochs project.
    • ALL projects of the solution must be compiled with DLL standard runtime libraries (not staticly linked to) - use /MD compile key;
    • In file bochs\main.cc function RedirectIOToConsole() before if (!AllocConsole()).. you should add FreeConsole() (RATIONALE: AllocConsole() may fail in case (my case) the process already has some console;
    • ALL pointers to screen memory buffer in SDL fullscreen mode must be corrected by adding sdl_fullscreen->offset value as follows:
      (Bit8u )sdl_fullscreen->pixels + sdl_fullscreen->offset + ...
      (Uint32
      )sdl_fullscreen->pixels + sdl_fullscreen->offset/4;
      ... and so on (check for sdl_fullscreen->pixels keyword)
      RATIONALE: In my case the simulated screen area has 720x400 pixels of size. When switching to full screen mode the SDL library picks up the nearest bigger supported resolution (i.e. 800x600). So we have some margins around our simulated screen area (100 pixels at top/bottom and 40 at sides). By means of some 'scientific shooting' I found that sdl_fullscreen->pixels member hold pointer to the whole 800x600 area and the beginning of our simulated portion is just (Bit8u *)sdl_fullscreen->pixels + sdl_fullscreen->offset. It seems this is not documented anywhere so I don't know is it a SDL's bug or a feature.

    The project seems to me rather buggy. Hope my coment will be helpful.

     
  • Could you include a patch file with the changes you did ?

    Thanks,
    Stanislav

     
  • I don't know how to attach files to my comment so I post the diff right here:

    diff -crB bochs-2.4.6-original\gui\sdl.cc bochs-2.4.6\gui\sdl.cc
    bochs-2.4.6-original\gui\sdl.cc Tue May 18 22:33:42 2010
    --- bochs-2.4.6\gui\sdl.cc Thu Sep 29 12:18:16 2011
    ***
    233,239 ****
    sdl_fullscreen = SDL_SetVideoMode(res_x,res_y,32, SDL_HWSURFACE|SDL_FULLSCREEN);
    src.y = 0;
    SDL_BlitSurface(tmp,&src,sdl_fullscreen,&dst);
    ! SDL_UpdateRect(tmp,0,0,res_x,res_y);
    SDL_FreeSurface(tmp);

    SDL_ShowCursor(0);
    

    --- 233,239 ----
    sdl_fullscreen = SDL_SetVideoMode(res_x,res_y,32, SDL_HWSURFACE|SDL_FULLSCREEN);
    src.y = 0;
    SDL_BlitSurface(tmp,&src,sdl_fullscreen,&dst);
    !
    SDL_FreeSurface(tmp);

    SDL_ShowCursor(0);
    

    482,488
    buf_row = (Uint32
    )sdl_screen->pixels + headerbar_heightdisp;
    } else {
    disp = sdl_fullscreen->pitch/4;
    ! buf_row = (Uint32
    )sdl_fullscreen->pixels;
    }
    // first invalidate character at previous and new cursor location
    if ((prev_cursor_y < text_rows) && (prev_cursor_x < text_cols)) {
    --- 482,488 ----
    buf_row = (Uint32 )sdl_screen->pixels + headerbar_heightdisp;
    } else {
    disp = sdl_fullscreen->pitch/4;
    ! buf_row = (Uint32 )sdl_fullscreen->pixels + sdl_fullscreen->offset/4;
    }
    // first invalidate character at previous and new cursor location
    if ((prev_cursor_y < text_rows) && (prev_cursor_x < text_cols)) {
    **

    688,694
    else
    {
    disp = sdl_fullscreen->pitch/4;
    ! buf = (Uint32
    )sdl_fullscreen->pixels + y*disp + x;
    }

    i = tileheight;
    

    --- 688,694 ----
    else
    {
    disp = sdl_fullscreen->pitch/4;
    ! buf = (Uint32 )sdl_fullscreen->pixels + ydisp + x + sdl_fullscreen->offset/4;
    }

    i = tileheight;
    

    778,784
    sdl_screen->format->BytesPerPixel
    x0;
    }
    else {
    ! return (Bit8u )sdl_fullscreen->pixels +
    sdl_fullscreen->pitch
    (y0) +
    sdl_fullscreen->format->BytesPerPixelx0;
    }
    --- 778,784 ----
    sdl_screen->format->BytesPerPixel
    x0;
    }
    else {
    ! return (Bit8u )sdl_fullscreen->pixels + sdl_fullscreen->offset +
    sdl_fullscreen->pitch
    (y0) +
    sdl_fullscreen->format->BytesPerPixelx0;
    }
    **

    1192,1198
    {
    color = SDL_MapRGB(sdl_fullscreen->format, 0,0, 0);
    disp = sdl_fullscreen->pitch/4;
    ! buf = (Uint32
    )sdl_fullscreen->pixels;
    }
    else return;

    --- 1192,1198 ----
    {
    color = SDL_MapRGB(sdl_fullscreen->format, 0,0, 0);
    disp = sdl_fullscreen->pitch/4;
    ! buf = (Uint32 *)sdl_fullscreen->pixels + sdl_fullscreen->offset/4;
    }
    else return;

    diff -crB bochs-2.4.6-original\gui\sdlkeys.h bochs-2.4.6\gui\sdlkeys.h
    bochs-2.4.6-original\gui\sdlkeys.h Sat Dec 05 03:02:12 2009
    --- bochs-2.4.6\gui\sdlkeys.h Tue Sep 27 13:37:30 2011
    ***
    59,67
    DEF_SDL_KEY( SDLK_GREATER )
    DEF_SDL_KEY( SDLK_QUESTION )
    DEF_SDL_KEY( SDLK_AT )
    ! DEF_SDL_KEY( /
    )
    ! DEF_SDL_KEY( Skip uppercase letters )
    ! DEF_SDL_KEY( / )
    DEF_SDL_KEY( SDLK_LEFTBRACKET )
    DEF_SDL_KEY( SDLK_BACKSLASH )
    DEF_SDL_KEY( SDLK_RIGHTBRACKET )
    --- 59,67 ----
    DEF_SDL_KEY( SDLK_GREATER )
    DEF_SDL_KEY( SDLK_QUESTION )
    DEF_SDL_KEY( SDLK_AT )
    ! //DEF_SDL_KEY( /
    )
    ! //DEF_SDL_KEY( Skip uppercase letters )
    ! //DEF_SDL_KEY( */ )
    DEF_SDL_KEY( SDLK_LEFTBRACKET )
    DEF_SDL_KEY( SDLK_BACKSLASH )
    DEF_SDL_KEY( SDLK_RIGHTBRACKET )
    diff -crB bochs-2.4.6-original\main.cc bochs-2.4.6\main.cc
    bochs-2.4.6-original\main.cc Sun Nov 21 19:02:12 2010
    --- bochs-2.4.6\main.cc Thu Sep 29 12:18:16 2011
    **
    420,425

    --- 420,426 ----
    long lStdHandle;
    FILE *fp;
    // allocate a console for this app
    + FreeConsole();
    if (!AllocConsole()) {
    MessageBox(NULL, "Failed to create text console", "Error", MB_ICONERROR);
    return 0;

    Diffs for project files are not included.
    The project was configured in Cygwin with the following settings (from .conf.win32-vcpp):
    ./configure --target=pentium-windows \ --enable-sb16 \ --enable-ne2000 \ --enable-all-optimizations \ --enable-cpu-level=6 \ --enable-x86-64 \ --enable-smp \ --enable-pci \ --enable-acpi \ --enable-clgd54xx \ --enable-usb \ --enable-usb-ohci \ --enable-show-ips \ --disable-readline \ --enable-debugger \ --without-x \ --with-sdl

    Also I have a few screenshots I'd like to include.

     
  • Volker Ruppert
    Volker Ruppert
    2012-03-05

    The sources are now ready for compiling with SDL support on VS2008Ex and the documentation for setting up the project has been updated. When you confirm that it's okay now, this bug report can be closed.

     
  • Volker Ruppert
    Volker Ruppert
    2014-05-24

    • status: open --> closed
    • assigned_to: Volker Ruppert
    • Group: --> fixed_in_v2.5