Why is it that SDL won't work with a console application?

Whenever I include SDL.h on a Win32 console application I get the
following error:

IBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/MyProject.exe : fatal error LNK1120: 1 unresolved externals

I’m using VC++ 6 by the way.

Did you include SDLMAIN.LIB in your project’s Link/General settings?

Lilith>>> On 5/5/2007 at 8:00 PM, Manuel Garc?a Cabrera wrote:

Whenever I include SDL.h on a Win32 console application I get the
following error:

IBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/MyProject.exe : fatal error LNK1120: 1 unresolved externals

I’m using VC++ 6 by the way.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Lilith Calbridge escribi?:

Did you include SDLMAIN.LIB in your project’s Link/General settings?

Lilith

Whenever I include SDL.h on a Win32 console application I get the
following error:

IBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/MyProject.exe : fatal error LNK1120: 1 unresolved externals

I’m using VC++ 6 by the way.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Yes, I did.>>>> On 5/5/2007 at 8:00 PM, Manuel Garc?a Cabrera <@Manuel_Garcia_Cabrer> wrote:

Manuel Garc?a Cabrera ha scritto:

Whenever I include SDL.h on a Win32 console application I get the
following error:
IBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/MyProject.exe : fatal error LNK1120: 1 unresolved externals

How did you write your main ?
You must write like this :

int main( int argc, char **argv )

(with argc and argv arguments)–
SkunkGuru

SkunkGuru escribi?:

Manuel Garc?a Cabrera ha scritto:

Whenever I include SDL.h on a Win32 console application I get the
following error:
IBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/MyProject.exe : fatal error LNK1120: 1 unresolved externals

How did you write your main ?
You must write like this :

int main( int argc, char **argv )

(with argc and argv arguments)

It’s not working… Can anyone try to compile this:

#include <sdl.h>

int main(int argc, char **argv){
return 0;
}

Please, I know it seems stupid, but try to compile that with Visual C++
6. I can’t do it!

I’ll have to check as I’m currently in the middle of a large amount of
virtual machine wrangling but I do believe you have to include windows.h
when making a non-console application with VC++. So, create a console
app from the available template and see what #includes it has as they’re
probably needed.On Sun, 2007-05-06 at 16:30 -0300, Manuel Garc?a Cabrera wrote:

It’s not working… Can anyone try to compile this:

#include <sdl.h>

int main(int argc, char **argv){
return 0;
}


All new Yahoo! Mail “The new Interface is stunning in its simplicity and ease of use.” - PC Magazine
http://uk.docs.yahoo.com/nowyoucan.html

Manuel Garc?a Cabrera wrote:

SkunkGuru escribi?:

Manuel Garc?a Cabrera ha scritto:

Whenever I include SDL.h on a Win32 console application I get the
following error:
IBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/MyProject.exe : fatal error LNK1120: 1 unresolved externals

How did you write your main ?
You must write like this :

int main( int argc, char **argv )

(with argc and argv arguments)

It’s not working… Can anyone try to compile this:

#include <sdl.h>

int main(int argc, char **argv){
return 0;
}

Please, I know it seems stupid, but try to compile that with Visual C++
6. I can’t do it!

There’s a header called SDL_main.h that you could try to include, especially
if you use the SDL_main lib.

Christophe Cavalaria escribi?:

Manuel Garc?a Cabrera wrote:

SkunkGuru escribi?:

Manuel Garc?a Cabrera ha scritto:

Whenever I include SDL.h on a Win32 console application I get the
following error:
IBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/MyProject.exe : fatal error LNK1120: 1 unresolved externals

How did you write your main ?
You must write like this :

int main( int argc, char **argv )

(with argc and argv arguments)

It’s not working… Can anyone try to compile this:

#include <sdl.h>

int main(int argc, char **argv){
return 0;
}

Please, I know it seems stupid, but try to compile that with Visual C++
6. I can’t do it!

There’s a header called SDL_main.h that you could try to include, especially
if you use the SDL_main lib.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Nope… Not working.

It’s not working… Can anyone try to compile this:

#include <sdl.h>

int main(int argc, char **argv)
{
return 0;
}

Hi Manuel,

the above example compiles and links fine as a console application for
me with VC6 and the current SDL-devel download. BUT you have to
configure your project settings correctly for both release and debug
builds.

Under C/C++:

Category: code generation:
    Use runtime library: Multithreaded DLL

Category Preprocessor:
    Additional include directories: path-to-SDL-include-directory
    (you might use global settings that make this redundant)

Under Link:
Category: input
Object/Library modules: SDL.lib SDLmain.lib kernel32.lib …
Additional Library path: path-to-SDL-lib-directory
(you might use global settings that make this redundant)

I usually switch off pre-compiled headers, set the warning level to 4,
set optimisations to minimise size, and disable exception handling,

Remember: you have to set all of the above for Release and Debug. Make
sure that at the left of the “Project Settings” dialog, the top of the
tree (the project itself) is highlighted, otherwise you may end up
setting only file-specific settings, not project-wide ones.

I also copied SDL.dll into the ‘Release’ and ‘Debug’ sub-directories so
that I could actually run it.

By the way: please supply accurate copy+paste error messages. Your first
example:

IBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/MyProject.exe : fatal error LNK1120: 1 unresolved externals

has ‘L’ missing from the front of it, and note that this is the wrong
runtime library. The missing _main is because you aren’t linking with
’SDLmain.lib’, even if you think you are - trust me - you aren’t :slight_smile:

Also, saying:

Nope… Not working.

is no use to anyone, paste the specific error message and please trim the
list clutter out of your replies.

It does work, so persevere and good luck with it,

regards,
John.

PS here is a link to your minimal example with project files:
http://johnnypops.demon.co.uk/files/ctest.zip (3K)
It just needs the SDL-1.2 directory filling out with SDL-devel-1.2.11-VC6.zip
and SDL.dll copying into the Release and Debug directories (when they appear).On Sun, May 06, 2007 at 08:50:56PM -0300, Manuel Garc?a Cabrera wrote:

I use Visual Studio Express 2005, and I have had no problem with using SDL
in a console application. In fact, the only thing I found was that you have
to start a project as a console-project for output like printf() to work,
other than that, no problems.

Cheers,
Peter

Even that is not true, let me clarify how this works:

The startpoint of a program under win32 is typically WinMain(). Now, when you
choose a console project, there is some code that more or less adapts the
arguments passed to WinMain() so they fit the standard argc/argv and then
invokes main(). IOW, you do have a window application that just wraps main().

Now, what does that mean? It means that in a console application, you can
create windows (just try it, the only difficulty might be getting at the
additional info that WinMain() receives). It also means that it is possible
to use printf() in a windows application - all you need to do is
AllocConsole() in order to create a console window or to create a pipe and
redirect stdout to it. Simple as that.

Now, switching between those two is also rather easy. AFAICT, the only
difference is the argument passed to the linker, /subsystem:console
or /subsystem:windows. Now, even that isn’t even necessary, because the only
difference I know that this change makes is to change the default entry
point. For a windows application, the entry is WinMainCRTStartup while for a
console application is is mainACRTStartup. Note that there are some
variations of those two which have to do with the two different ways to
handle TCHAR, and just like CreateFile(), there are versions for TCHAR, CHAR
and WCHAR.

For my projects, I always use main() as entry to be portable. This works for
me under both the desktop and CE variants of MS Windows OSs. However, I think
I only tried to use SDL under win32 once, so there might be an additional
catch that I don’t know about.

UliOn Monday 07 May 2007 13:35:52 Peter Ketting wrote:

I use Visual Studio Express 2005, and I have had no problem with using SDL
in a console application. In fact, the only thing I found was that you have
to start a project as a console-project for output like printf() to work,
other than that, no problems.

2007/5/6, Manuel Garc?a Cabrera :

It’s not working.

rule number 1 )
explain what error you got

How can I help you if I don’t know what and how it’s not working ?
:slight_smile:

rule number 2 )
have you read the document / tutorial about compilation under VC++ 6 ?

It explains any setting in VC++6 that must be changed
(as explained by John in another reply)–
SkunkGuru.