Using MSVC++ compiler from the command line

Started by
2 comments, last by Clump 15 years, 8 months ago
I'm trying to use the command line tools cl.exe and link.exe from the command line so I can use cygwin makefiles (best not to ask why). I've got it all working except... I'm compiling an SDL application, I'm using main() (rather than winmain()) and compiling a console application. Problem is, when I run it I always get a "Press any key to continue . . ." when my app is exiting (naturally it doesn't happen if I use winmain()). This is if I run it from microsoft visual studio, from the command line, or when double clicking it, however this behaviour gets pretty annoying. Any Idea what I'm doing wrong? I'm using the following command lines: cl.exe /nologo /c /EHsc /MDd /ZI /DEBUG /Fomain.o main.cpp link.exe /nologo /DEBUG user32.lib gdi32.lib SDL.lib /OUT:main.exe main.o Thanks for any help!
Advertisement
Do some research on nmake.

nmake is the "make file" utility that comes with visual studio. Looking into that might give you a good starting point on how to use the msvc compiler/linker in gnu makefiles.
i think you need to add /subsystem:windows to your link command line.

link /NOLOGO /SUBSYSTEM:WINDOWS main.obj SDLmain.lib SDL.lib

is what i use...


link /link will show you the link help, and you'll see:

/SUBSYSTEM:{BOOT_APPLICATION|CONSOLE|EFI_APPLICATION|
EFI_BOOT_SERVICE_DRIVER|EFI_ROM|EFI_RUNTIME_DRIVER|
NATIVE|POSIX|WINDOWS|WINDOWSCE}[,#[.##]]

also, i think on windows SDL you can link against SDLmain.lib, and then SDL will do something like:

#define main sdlmain(..)
and then implements WinMain for you, and wraps your call to standard main(..)

anyways, good luck.
r.
Thanks for the help.

This is a little embarrassing.

After trying out both your ideas, and about an hour or two digging about, I found that a stupid svn merge and some odd defines in the file that has main() in... means that I have a system("pause") at the end of main.

I don't really know where to hide my face.

Ah well, I know a lot more about cl.exe and link.exe than I did a few days ago thanks to this, so that's a plus I guess.

Thanks again.

This topic is closed to new replies.

Advertisement