Sign in to follow this  
Zouflain

Trying to get into SDL (Requirements for SDL based applications?)

Recommended Posts

I've heard plenty of good things about SDL (compatibility with OpenGL, easy to use, and most importantly cross platform), but the thing is I can't get it to work. I already had a project started and tried to add SDL and cannot for the life of me get past these linker errors. The project has the Multi-Threaded DLL setting The project is linked to SDL.lib and SDLmain.lib If the project includes either SDL.h or SDL_main.h, linker errors (see below) I use Visual C++ 2005 (version 8) First I tried including using the linker, that returned errors, so I changed it to just including within the source itself. If it's possible, I'd rather avoid this - I want cross platform portability. [script]#ifdef WIN32 #pragma comment(lib,"SDL.lib") #pragma comment(lib,"SDL_main") #endif #include <iostream> #include <cstring> #include <vector> #include <SDL_main.h> #include <SDL.h> using namespace std; int main(int argc,char*argv[]){ return(0); }[/script] This shouldn't have errors, but I keep getting the error: LINK : fatal error LNK1561: entry point must be defined When did main() stop being the entry point? How can I define main() as my entry point (or, since I've done some research, how do I get to that SDL_main() function? The macro obviously isn't working here)? I appreciate any answers and/or suggestions. [Edited by - Zouflain on August 6, 2007 2:33:03 AM]

Share this post


Link to post
Share on other sites
Quote:
Original post by Frizbe
Did you change the linker input settings in your project settings?

I tried this, but it did nothing. Besides, I thought the pragma's already covered that? Thank you anyway.
Quote:
Original post by ForestMaster
try to swap your pragmas :0)

This, again, does nothing. Actually the reason they aren't in the same order as the header files is because I was experimenting with their placement. Thank you, though.

Share this post


Link to post
Share on other sites
Quote:
Original post by Lazy Foo
It's SDLmain not SDL_main.

SDLmain.h? No such header file exists. I can see the library is called SDLmain, but not the header. If you did mean the library, please note that what I put was just a typo. The line should read:
Quote:
#pragma comment(lib,"SDLmain.lib")

I was rather tired while typing that post.

Share this post


Link to post
Share on other sites
Quote:
Original post by DavidGr
are you using

int main(int argc, char* argv[])

as the parameters for the main method? if not try that :D

Yes, I stated that in my original post. Thank you for offering a suggestion, though.
Quote:
Original post by ForestMaster
anyway why including SDL_main.h on your own? i thought SDL.h was already including it

#ifndef _SDL_H
#define _SDL_H

#include "SDL_main.h"
...

?

I can't see how this makes a difference, and including or not including SDL_main.h does not change the compiler error, so it's unrelated.

Share this post


Link to post
Share on other sites
Quote:
Original post by Lazy Foo
Just follow these instructions exactly, and it should work.


Not to sound impertinent but I did read these (they pop up on this forum [and google searches] quite a bit). So too does this error, but no one seems to ever have an answer). Thanks for answering so many times, though - I don't mean to sound ungrateful.

I do have a few questions that aren't mentioned in your tutorial. Why does it have to be a win32 application? What's the difference in settings between an empty project (ie not win32 empty, just totally empty) and a win32 one? Doesn't dependency on windows immediately negate cross-platform portability (thus negating any reason I would have for even considering the use of SDL)?

Share this post


Link to post
Share on other sites
Try using a console application instead.

In the project properties (alt-F7) look under Configuration Properties->Linker->System and make sure that the SubSystem is "Console (/SUBSYSTEM:CONSOLE)".

Quote:
Doesn't dependency on windows immediately negate cross-platform portability (thus negating any reason I would have for even considering the use of SDL)?


How you set up your IDE/compiler/linker will vary however the code shouldn't need to be modified if you are careful in what you use. For instance, using the #pragma's may give you troubles if you were to compile using gcc on linux as you can tell since you added the #ifdef WIN32 around them.

Share this post


Link to post
Share on other sites
just an idea, have you tried doing #include "SDL.h" before "SDL_main.h"??

also try using double quotes (") instead of the <>

one more thing :D in your main function do you have SDL_Init(SDL_INIT_EVERYTHING); and SDL_Quit();


you probably have that but felt i should mention it.

Share this post


Link to post
Share on other sites
Quote:
Original post by DavidGr
just an idea, have you tried doing #include "SDL.h" before "SDL_main.h"??

also try using double quotes (") instead of the <>

one more thing :D in your main function do you have SDL_Init(SDL_INIT_EVERYTHING); and SDL_Quit();


you probably have that but felt i should mention it.


Linker errors happen at link time. The different things you suggested all affect compile time and run time, they will not change the link time errors.

Making randomly guessed changes to the OP's source will, in general, not help.

He shouldn't include SDL_main.h at all, it isn't intended to be used in client applications.

Using double quotes for including SDL header files is recommended in the SDL documentation in case people choose to locate their SDL headers in a non-standard include folder.

Not calling SDL_Init and SDL_Quit will probably cause serious run time errors in an average SDL application, but are not required to get such an applicatin to link correctly.

Share this post


Link to post
Share on other sites
Thank you all for trying to help - much of what you've said has been helpful. Defining the application entry was, apparently, simply a matter of setting the subsystem (currently CONSOLE). The pragma were merely an experiment, and have been removed (replaced within the linker).

My issue now is that I get this warning:
warning LNK4075: ignoring '/EDITANDCONTINUE' due to '/OPT:ICF' specification

that I cannot use any optimization (apparently incompatable with most of the options suggested by Lazy Foo), and that while it can now compile properly (besides that warning), it returns the error:
Quote:
This application has failed to start because the application configuration is incorrect. Reinstalling the application may fix this problem."
Sadly, this issue arises for many reasons apparently, so I can't google search it - however, I did find out how to get more information than this cryptic message.

The admin Event Viewer reports these three issues:
Quote:
Generate Activation Context failed for <filepath>. Reference error message: The operation completed successfully.
Quote:
Resolve Partial Assembly failed for Microsoft.VC80.CRT. Reference error message: The referenced assembly is not installed on your system.
Quote:
Dependent Assembly Microsoft.VC80.CRT could not be found and Last Error was The referenced assembly is not installed on your system.
I have no idea what that means, however, and can't seem to find the information on google.

Share this post


Link to post
Share on other sites
I would recommend creating a new EMPTY windows console application from the start and copying your code to the new project (making sure pre compiled headers is off). Add SDL.lib and SDLmain.lib to the linker and include SDL.h. If your new project doesn't work then we at least know what is set and not set and we can probably help more although I doubt you will see errors if you do this as it looks like some settings may have been changed that we do not know about and starting from a fresh project is the best way to tell if this is the case.

Share this post


Link to post
Share on other sites
Quote:
Original post by evillive2
I would recommend creating a new EMPTY windows console application from the start and copying your code to the new project (making sure pre compiled headers is off). Add SDL.lib and SDLmain.lib to the linker and include SDL.h. If your new project doesn't work then we at least know what is set and not set and we can probably help more although I doubt you will see errors if you do this as it looks like some settings may have been changed that we do not know about and starting from a fresh project is the best way to tell if this is the case.

Same issue.

Share this post


Link to post
Share on other sites
Quote:
Original post by Zouflain
I do have a few questions that aren't mentioned in your tutorial. Why does it have to be a win32 application? What's the difference in settings between an empty project (ie not win32 empty, just totally empty) and a win32 one?


If you don't set up as a Win32, you're going to get library errors. An empty Win32 project isn't truly empty, it just that an "empty" project doesn't automatically generate some files.

Quote:
Original post by ZouflainDoesn't dependency on windows immediately negate cross-platform portability (thus negating any reason I would have for even considering the use of SDL)?


The Windows implementation of SDL uses native windows code, the Linux implementation uses Linux code, etc, etc. SDL is a wrapper for the low level system specific code.

Those are the exact instructions I have used to set up, compile and run SDL apps on, so I know they work.

Did you also do the mini set up tutorial for Visual C++? In the latest version of SDL, you have to set up Visual C++ in a certain way for it to work with SDL. I had uninstall my current VC++ 05E setup, download the latest version of VC++ 05E, download and install the service pack for it, and install and configure the SDK before I could even begin setting up SDL.

Share this post


Link to post
Share on other sites
Quote:
Original post by Lazy Foo
If you don't set up as a Win32, you're going to get library errors. An empty Win32 project isn't truly empty, it just that an "empty" project doesn't automatically generate some files.
I don't get library errors: I get runtime errors. Like I said, it compiled using the susbsystem CONSOLE option set on a completely empty file setup. I get the same runtime errors with Win32 projects.
Quote:
Original post by Lazy Foo
The Windows implementation of SDL uses native windows code, the Linux implementation uses Linux code, etc, etc. SDL is a wrapper for the low level system specific code.
I know what SDL is (I researched it before giving it a try), I just didn't understand a bit of information about the compiler itself. Now I do.
Quote:
Original post by Lazy Foo
Those are the exact instructions I have used to set up, compile and run SDL apps on, so I know they work.
For you and some who have been there. My situation demonstrates that they don't work all the time.
Quote:
Original post by Lazy Foo
Did you also do the mini set up tutorial for Visual C++? In the latest version of SDL, you have to set up Visual C++ in a certain way for it to work with SDL. I had uninstall my current VC++ 05E setup, download the latest version of VC++ 05E, download and install the service pack for it, and install and configure the SDK before I could even begin setting up SDL.

I don't use visual C++ express, I use visual C++ 8 (from Microsoft Visual Studio 2005). Are you saying I need additional libraries for microsoft visual studio? Also, where is this mini set up tutorial? If it's the one you linked, it didn't work - even when creating an entirely new project following your directions step by step.

Also, the default optimization settings (/O2) conflict with the settings you clearly display in your tutorial. You might want to add a note.

Share this post


Link to post
Share on other sites
Quote:
Original post by evillive2
Are you on Vista by chance?
XP Home edition. I wont be upgrading to vista any time soon (ironically to avoid issues like this).

Share this post


Link to post
Share on other sites
Quote:
Original post by Zouflain
I don't use visual C++ express, I use visual C++ 8 (from Microsoft Visual Studio 2005). Are you saying I need additional libraries for microsoft visual studio? Also, where is this mini set up tutorial?


It's this one.

The service pack is different, but easily available through googling.


Share this post


Link to post
Share on other sites
I'll google search it now, however I think it prudent to post what information I have on the version of Microsoft Studio I'm running. After finding this service pack, I'll edit this post with any changes (or lack there of).
Quote:
Help->About
Microsoft Visual Studio 2005
Version 8.0.50727.42 (RTM.050727-4200)
Microsoft .NET Framework
Version 2.0.50727

Installed Edition: Professional
Update: After installing the patch which ate 4 gigabytes of my hard drive, I got an amazing result:

No change.

Second Update:
Wow. I think I am done with SDL. After installing this patch a second time, it worked (apparently the first time it crashed and exited halfway through without an error message)... without me having to recompile.

Quite frankly, I find it simply retarded to expect anyone using any of my applications to have to patch their system with this ludicrously large thing. If this cannot be avoided, I am done with SDL and will vigorously suggest against any of my friends or colleagues from using it.

[Edited by - Zouflain on August 6, 2007 2:46:30 AM]

Share this post


Link to post
Share on other sites
Any patching you need to do should only need to be done on the developers machine. You may need to distribute the Microsoft C++ runtime installer too, I am not sure, I don't use Visual Studio.

I use G++ with SDL on windows and it produces a self-contained executable, which only needs the SDL dlls to be bundled with it.

Your case seems to be an extreme outlier from the normal case of SDL usage. When I was a beginner I used SDL and I found it very easy to use. I can't imagine why you're having such a rough experience with it...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this