Newbie - configuration woes

Hi all,
I’m trying to set up SDL 1.2.6 with Microsft Visual Studio 6. I’m using
Windows 2000 Pro SP4 and I’ve installed the DX9 SDK “summer update”.

I’m attempting to get my first SDL program to compile. I’ve created a VS6
Console Application, called “Joystick2” and a file main.cpp, where the
main() function resides. I’ve copied the downloaded SDL.dll, SDL.lib and
SDLmain.lib into the project’s directory and added the two .lib files to
the project as instructed by the VisualC.html helpfile supplied with the
SDL download. I’ve set the project’s “Use run-time library” to
"Multithreaded DLL" and given it the SDL include files directory for
"Additional Include Directories".

My first program is this:-------------------------------------------------------------------------------------
/* Experimenting with SDL and CPP */

#include <iostream.h>
#include “SDL.h”

int main( void )
{
int numJoysticks = 1;
//char name[101];

cout << "!";

if (SDL_Init( SDL_INIT_TIMER | SDL_INIT_JOYSTICK ) == -1) {
	cout << "Failed to initialise SDL.";
	return(-1);
}

numJoysticks = SDL_NumJoysticks();

cout << "There are " << numJoysticks << " joysticks.";


SDL_Quit();
return(0);

}

When I try to compile the program, I get this output:

--------------------Configuration: Joystick2 - Win32
Debug--------------------
Compiling…
main.cpp
Linking…
SDLmain.lib(SDL_main.obj) : error LNK2001: unresolved external symbol
_SDL_main
Debug/Joystick2.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

Joystick2.exe - 2 error(s), 0 warning(s)

It does compile if I comment out all the SDL related stuff, however having
no SDL stuff except the #include gives these errors.

I am using the downloaded .libs and .dll because my attempt at compiling
sdl.lib on my system failed as it couldn’t find “afxres.h”. sdlmain.lib
compiled and the resulting lib is exactly the same numberof bits as the
downloaded one so it appears there is no version related problem here but
I can’t be sure.

I’ve never used .lib or .dll files before so be warned I could be missing
something really obvious in regards to these.

Thanks,
Rob Cunningham

int main( void )

Try instead:
int main(int argc, char *argv[])

There is an entry about this in the FAQ on the SDL webpage (section
Windows). I remember having stumbled over the same problem.

PeterOn Tue, 13 Jan 2004 15:11:44 -0000, Rob Cunningham wrote:

int main( void )

Try instead:
int main(int argc, char *argv[])

There is an entry about this in the FAQ on the SDL webpage (section
Windows). I remember having stumbled over the same problem.

Peter


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Ah ha, thank you.

I now have a different problem - I get no output, despite a line that is
just:
cout << “!”;

This line was inserted purely to provoke a response. Could Stdout be
redirected somewhere obscure?

RobOn Tue, 13 Jan 2004 17:08:26 +0100, Peter Strempel wrote:

On Tue, 13 Jan 2004 15:11:44 -0000, Rob Cunningham <@Rob_Cunningham> wrote:

This line was inserted purely to provoke a response. Could Stdout be
redirected somewhere obscure?

Look for stdout.txt and stderr.txt files in the current directory. Current
directory might be somewhere obscure if you execute the program from
Visual Studio. Maybe try with a DOS shell to make sure “current” really is
current.

PeterOn Tue, 13 Jan 2004 16:55:00 -0000, Rob Cunningham wrote:

This line was inserted purely to provoke a response. Could Stdout be
redirected somewhere obscure?

Look for stdout.txt and stderr.txt files in the current directory.
Current directory might be somewhere obscure if you execute the program
from Visual Studio. Maybe try with a DOS shell to make sure "current"
really is current.

Peter


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

No luck with that - I always execute from a command prompt anyway. I tried
executing it and sending it’s output to a text file (I’ve forgotten the
name for this but it’s the command “joystick2 > textfile”). I inserted a
printf() which displayed fine, so it appears the problem is nothing to do
with SDL. Mystifying anyway. This is going off topic somewhat, but could
be causing this? Also, is there an article around on the pros and cons of
printf and cout in C++? I’ve always found cout to be ugly and ineffecient
to code while printf much more familar and effecient.

RobOn Tue, 13 Jan 2004 19:10:21 +0100, Peter Strempel wrote:

On Tue, 13 Jan 2004 16:55:00 -0000, Rob Cunningham <@Rob_Cunningham> wrote:

d fine, so it appears the problem is nothing to do with SDL. Mystifying
anyway. This is going off topic somewhat, but could be causing this? Also,
is there an article around on the pros and cons of printf and cout in C++?
I’ve always found cout to be ugly and ineffecient to code while printf
much more familar and effecient.

Essentially there are two types of windows app - console and
graphical. Console handles IO fine, but graphical pretty much sends it
into the abyss (essentially because graphical stuff doesnt need a DOS
prompt to load from, so where would it go anyway). Use files if you want
to output text is the rule of thumb.

As for the other bit. printf isn’t type safe. Try printf("%s",3) and
you’ll see that it will compile, whether it crashes is a bit of pot
luck. It certainly isnt safe anyway. Where as cout << 3 is. cout does
seem ugly to me, the boost libraries have some good similar/related stuff
as I remember.

HTH,

Neil.

This line was inserted purely to provoke a response. Could Stdout be
redirected somewhere obscure?

Look for stdout.txt and stderr.txt files in the current directory. Current
directory might be somewhere obscure if you execute the program from
Visual Studio. Maybe try with a DOS shell to make sure “current” really is
current.

Peter

If I remember correctly (been a year or two since I’ve played with MSVC6 –
this behavior is present in v5 and v7, though, so it’s fairly safe to
assume…), MSVC will exectute the program in the project’s root directory.
If you haven’t gone and created the /src and /include directories and
what-not yourself, the directory will be where you find all your source
files at (.cpp, .h, .rc, etc). In any case, chances are you don’t have too
many “stdout.txt” files on your disk, so a simple disk search can do the
trick.

  • Silicon

Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.552 / Virus Database: 344 - Release Date: 12/15/2003

----- Original Message -----
From: zotan@web.de (Peter Strempel)
To:
Sent: Tuesday, January 13, 2004 11:10 AM
Subject: Re: [SDL] Newbie - configuration woes
On Tue, 13 Jan 2004 16:55:00 -0000, Rob Cunningham wrote:

No luck with that - I always execute from a command prompt anyway. I tried
executing it and sending it’s output to a text file (I’ve forgotten the
name for this but it’s the command “joystick2 > textfile”). I inserted a
printf() which displayed fine, so it appears the problem is nothing to do
with SDL. Mystifying anyway. This is going off topic somewhat, but could
be causing this? Also, is there an article around on the pros and cons of
printf and cout in C++? I’ve always found cout to be ugly and ineffecient
to code while printf much more familar and effecient.

This is a shot in the dark, but did your cout include a newline?
cout << whatever << endl;

JPOn Tuesday 13 January 2004 11:01 am, Rob Cunningham wrote: