I have been working on a game engine and have come across a few problems.
Problem #1
In order to be able to use the regular main() function on windows with SDL, you need to use SDLmain.lib. The problem is, I want my engine to be as simple to use as possible, which means that I only want the user to have to link to my engine, and not both my engine and SDLmain.lib. Is there anyway to do this? I'm using VC++ 2008 Express edition, in case that makes any difference.
Problem #2
I would like it if the user does not have to return any values from their main function.
Are you saying that you just don't want it to require you to have SDL.dll with the program? Because if so, this is not legal. It discusses this as one of the terms of use on the SDL website.
If you would like you can just build your engine with many SDL specifics and include them in the engine files so that you don't have to in your main, you would still have to have SDL.dll though. But I recommend just doing it the original way.
While Jesus equipped with angels, the Devil's equipped with cops
For God so loved the world that he blessed the thugs with rock
So what are you trying to accomplish? You simply don't want your users to have to return a value or add parameters to their main function? If so, I wrote this really ugly code that will help. I know it's not the ideal solution but it works heh. The obvious downfall as far as user friendliness is concerned is that they have to declare Engine globally and pass in their main function. Maybe someone else can come up with a nicer solution?
But really, why not just let the user define the main function? Surely they know enough to be able to do that? If you're linking against SDL and SDLMain in your Engine I'm pretty sure the user won't have to link to SDLMain.
I can live with the user having to return a value in main(), the main problem is that I link SDLmain.lib in my engine and everything compiles/links fine, but when I test out my engine, I get this error:
LINK : fatal error LNK1561: entry point must be defined
lotios611 wrote:I can live with the user having to return a value in main(), the main problem is that I link SDLmain.lib in my engine and everything compiles/links fine, but when I test out my engine, I get this error:
LINK : fatal error LNK1561: entry point must be defined
lotios611 wrote:I can live with the user having to return a value in main(), the main problem is that I link SDLmain.lib in my engine and everything compiles/links fine, but when I test out my engine, I get this error:
LINK : fatal error LNK1561: entry point must be defined
lotios611 wrote:the main problem is that I link SDLmain.lib in my engine and everything compiles/links fine, but when I test out my engine, I get this error
...
It compiles and links fine until you "test out" the engine... Then it doesn't link right. What do you mean by testing it out? If you get a linker error when you "test out" the engine, but normally you don't, I can only assume that by this you mean you are building under release? I'm just guessing lol but if you are make sure under project properties that you changed what is says next to configuration at the top from debug to release and then add SDLmain.lib to the linker... I could be completely wrong though haha but this is just what I see could be happening.
lotios611 wrote:the main problem is that I link SDLmain.lib in my engine and everything compiles/links fine, but when I test out my engine, I get this error
...
It compiles and links fine until you "test out" the engine... Then it doesn't link right. What do you mean by testing it out? If you get a linker error when you "test out" the engine, but normally you don't, I can only assume that by this you mean you are building under release? I'm just guessing lol but if you are make sure under project properties that you changed what is says next to configuration at the top from debug to release and then add SDLmain.lib to the linker... I could be completely wrong though haha but this is just what I see could be happening.
My engine is compiled into a debug .lib file. I am writing a game using my engine, and in that game I get the error.
Well, I got everything to compile and link fine, the only problem is that I have to add SplinterEngine.lib SDL.lib SDLmain.lib SDL_image.lib SDL_mixer.lib SDL_ttf.lib to my linker settings and I have to set the subsystem to windows in my test game. Is there any way to get around having to do that and just being able to link to SplinterEngine.lib? Splinter Engine is the name of my game engine by the way.
lotios611 wrote:Well, I got everything to compile and link fine, the only problem is that I have to add SplinterEngine.lib SDL.lib SDLmain.lib SDL_image.lib SDL_mixer.lib SDL_ttf.lib to my linker settings and I have to set the subsystem to windows in my test game. Is there any way to get around having to do that and just being able to link to SplinterEngine.lib? Splinter Engine is the name of my game engine by the way.
Are you adding those libraries to your librarian's linker input for your engine? I swear that Visual Studio lets me statically link to just one .lib containing the others...
As for not wanting the application utilizing your engine to not have to return a value... tough shit. That's how exiting an application and returning to the operating system works. However, I'm pretty sure that want you want to do is this:
lotios611 wrote:Well, I got everything to compile and link fine, the only problem is that I have to add SplinterEngine.lib SDL.lib SDLmain.lib SDL_image.lib SDL_mixer.lib SDL_ttf.lib to my linker settings and I have to set the subsystem to windows in my test game. Is there any way to get around having to do that and just being able to link to SplinterEngine.lib? Splinter Engine is the name of my game engine by the way.
Are you adding those libraries to your librarian's linker input for your engine? I swear that Visual Studio lets me statically link to just one .lib containing the others...
Well, the problem is that I don't know. When I try to add the stuff to the linker settings when building a .lib, I can't find the linker settings, so I change the project to compile as an .exe, change the linker settings, and then change the project back to compiling as a .lib.
I've just tried going into the project file for my engine and manually editing the linker settings from there, but it still doesn't work.
I get these error messages in my test game now:
SplinterEngine.lib(SE_Engine.obj) : error LNK2019: unresolved external symbol _SDL_Init referenced in function "public: __thiscall SE::Engine::Engine(void)" (??0Engine@SE@@QAE@XZ)
SplinterEngine.lib(SE_Engine.obj) : error LNK2019: unresolved external symbol _SDL_Quit referenced in function "public: __thiscall SE::Engine::~Engine(void)" (??1Engine@SE@@QAE@XZ)
MSVCRTD.lib(crtexew.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup
C:\Programming\C++\Splinter Games\Pickin' Sticks\Debug\Pickin' Sticks.exe : fatal error LNK1120: 3 unresolved externals
lotios611 wrote:Well, I got everything to compile and link fine, the only problem is that I have to add SplinterEngine.lib SDL.lib SDLmain.lib SDL_image.lib SDL_mixer.lib SDL_ttf.lib to my linker settings and I have to set the subsystem to windows in my test game. Is there any way to get around having to do that and just being able to link to SplinterEngine.lib? Splinter Engine is the name of my game engine by the way.
Are you adding those libraries to your librarian's linker input for your engine? I swear that Visual Studio lets me statically link to just one .lib containing the others...
Well, the problem is that I don't know. When I try to add the stuff to the linker settings when building a .lib, I can't find the linker settings, so I change the project to compile as an .exe, change the linker settings, and then change the project back to compiling as a .lib.
I've just tried going into the project file for my engine and manually editing the linker settings from there, but it still doesn't work.
I get these error messages in my test game now:
SplinterEngine.lib(SE_Engine.obj) : error LNK2019: unresolved external symbol _SDL_Init referenced in function "public: __thiscall SE::Engine::Engine(void)" (??0Engine@SE@@QAE@XZ)
SplinterEngine.lib(SE_Engine.obj) : error LNK2019: unresolved external symbol _SDL_Quit referenced in function "public: __thiscall SE::Engine::~Engine(void)" (??1Engine@SE@@QAE@XZ)
MSVCRTD.lib(crtexew.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup
C:\Programming\C++\Splinter Games\Pickin' Sticks\Debug\Pickin' Sticks.exe : fatal error LNK1120: 3 unresolved externals
Fuck only knows what's going on there... you aren't ever supposed to do that. I'm guessing you probably didn't also include the corresponding paths to these libraries? You need to find out how to link against additional libraries with your static library (under "librarian" settings).
I've pretty much given up on problem #2.
Why? The code snippet that I posted is literally THE way to handle that scenario...
lotios611 wrote:Well, I got everything to compile and link fine, the only problem is that I have to add SplinterEngine.lib SDL.lib SDLmain.lib SDL_image.lib SDL_mixer.lib SDL_ttf.lib to my linker settings and I have to set the subsystem to windows in my test game. Is there any way to get around having to do that and just being able to link to SplinterEngine.lib? Splinter Engine is the name of my game engine by the way.
Are you adding those libraries to your librarian's linker input for your engine? I swear that Visual Studio lets me statically link to just one .lib containing the others...
Well, the problem is that I don't know. When I try to add the stuff to the linker settings when building a .lib, I can't find the linker settings, so I change the project to compile as an .exe, change the linker settings, and then change the project back to compiling as a .lib.
I've just tried going into the project file for my engine and manually editing the linker settings from there, but it still doesn't work.
I get these error messages in my test game now:
SplinterEngine.lib(SE_Engine.obj) : error LNK2019: unresolved external symbol _SDL_Init referenced in function "public: __thiscall SE::Engine::Engine(void)" (??0Engine@SE@@QAE@XZ)
SplinterEngine.lib(SE_Engine.obj) : error LNK2019: unresolved external symbol _SDL_Quit referenced in function "public: __thiscall SE::Engine::~Engine(void)" (??1Engine@SE@@QAE@XZ)
MSVCRTD.lib(crtexew.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup
C:\Programming\C++\Splinter Games\Pickin' Sticks\Debug\Pickin' Sticks.exe : fatal error LNK1120: 3 unresolved externals
Fuck only knows what's going on there... you aren't ever supposed to do that. I'm guessing you probably didn't also include the corresponding paths to these libraries? You need to find out how to link against additional libraries with your static library (under "librarian" settings).
I tried doing that, and now I get these warnings when I compile my library:
SDL_image.lib(SDL_image.dll) : warning LNK4006: __NULL_IMPORT_DESCRIPTOR already defined in SDL.lib(SDL.dll); second definition ignored
SDL_image.lib(SDL_image.dll) : warning LNK4221: no public symbols found; archive member will be inaccessible
SDL_mixer.lib(SDL_mixer.dll) : warning LNK4006: __NULL_IMPORT_DESCRIPTOR already defined in SDL.lib(SDL.dll); second definition ignored
SDL_mixer.lib(SDL_mixer.dll) : warning LNK4221: no public symbols found; archive member will be inaccessible
SDL_ttf.lib(SDL_ttf.dll) : warning LNK4006: __NULL_IMPORT_DESCRIPTOR already defined in SDL.lib(SDL.dll); second definition ignored
SDL_ttf.lib(SDL_ttf.dll) : warning LNK4221: no public symbols found; archive member will be inaccessible
I've pretty much given up on problem #2.
Why? The code snippet that I posted is literally THE way to handle that scenario...
I realized that would be the way to handle it a while ago, and decided that I didn't want to design my engine like that.