How to link with microsoft program?

I have built sdl in msys/mingw and get a sdl.dll it seems to work. Now I need
to link sdl with a microsoft visual c++ program. How can I get a sdl.lib file?
Can the msys/mingw scripts generate one? I plan to use sdl.dll but need a sdl.lib
file for linking.

Another question. I see a SDL-1.2.11.tar.gz and a SDL-dev-1.2.11-mingw32.tar.gz.
I have only used SDL-1.2.11.tar.gz. When do you need to use the devel version?
Should you unpack that on top of the non-devel version or is it a stand-alone
replacement for the non-devel version?

thanks,
Bob

I found a VisualC.zip file in the root directory and tried to build that with msvc++.

Most of it builds, but I get warnings about snprintf, strcasecmp and strtoull,
and errors about _DX5_SoundFocus being multiply defined. Does anyone know the fix
for this?

BobOn Fri, Jul 06, 2007 at 11:02:24AM -0400, Bob Self wrote:

I have built sdl in msys/mingw and get a sdl.dll it seems to work. Now I need
to link sdl with a microsoft visual c++ program. How can I get a sdl.lib file?
Can the msys/mingw scripts generate one? I plan to use sdl.dll but need a sdl.lib
file for linking.

Another question. I see a SDL-1.2.11.tar.gz and a SDL-dev-1.2.11-mingw32.tar.gz.
I have only used SDL-1.2.11.tar.gz. When do you need to use the devel version?
Should you unpack that on top of the non-devel version or is it a stand-alone
replacement for the non-devel version?

thanks,
Bob


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

I found a VisualC.zip file in the root directory and tried to build that with msvc++.

Most of it builds, but I get warnings about snprintf, strcasecmp and strtoull,
and errors about _DX5_SoundFocus being multiply defined. Does anyone know the fix
for this?

What version of SDL are you using?
Try the latest snapshot here:
http://www.libsdl.org/tmp/SDL-1.2.zip

See ya!
-Sam Lantinga, Lead Software Engineer, Blizzard Entertainment

What version of SDL are you using?
Try the latest snapshot here:
http://www.libsdl.org/tmp/SDL-1.2.zip

I was trying SDL-1.2.11. I also just tried the snapshot and get the same
errors. Is there a way to set up an environment or macros that will let this
build in visual c++ (the project inside VisualC.zip).

thanks,
Bob

I was trying SDL-1.2.11. I also just tried the snapshot and get the same
errors. Is there a way to set up an environment or macros that will let this
build in visual c++ (the project inside VisualC.zip).

That’s odd. What version of Visual C++ are you using? I just built it under
Microsoft Visual C++ 2005 Express Edition with no problems…

Also make sure you’re copying include/SDL_config_win32.h to include/SDL_config.h before you start.

See ya,
-Sam Lantinga, Lead Software Engineer, Blizzard Entertainment

That’s odd. What version of Visual C++ are you using? I just built it under
Microsoft Visual C++ 2005 Express Edition with no problems…

I’m using SDL-1.2.11

Also make sure you’re copying include/SDL_config_win32.h to include/SDL_config.h before you start.

This was the missing step. I had not done that. It builds fine now.> See ya,

-Sam Lantinga, Lead Software Engineer, Blizzard Entertainment


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

Now that I was able to get the .lib files for visualc to build, everything links
except that I get one last build error:

Compiling…
main.cpp
Linking…
MSVCRTD.lib(crtexe.obj) : error LNK2001: unresolved external symbol _main
Debug/main.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
Creating browse info file…

main.exe - 2 error(s), 1 warning(s)

I have checkecked that the sdl debug targets were built with debug multithreaded dll
settings. This must be something about sdlmain.lib. If I link with that I don’t
get the error, but my main() function doesn’t execute, so nothing happens when I
run it. My main function is declared as:

int main(int argc, char **argv) {…

Any ideas?

Bob

“Any ideas?”

I got one: try

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

I had already tried that and it made no difference. I was thinking though: my
source file is main.cpp not main.c. Would that make a difference? This used to
link with sdl versions about a year ago.

thanks,
BobOn Sun, Jul 08, 2007 at 12:37:47PM -0500, Adam Stevenson wrote:

“Any ideas?”

I got one: try

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

Right now, I am using visualc++ with no problems. Maybe if I sent you my
project file, you could try compiling that. You’re using 2k5?

The problem described deals with something called CRT…I had to
remember to do this when creating plugins for a program I enjoy using.

Go to Project>>Settings Menu items.

Then in the C/C++ tab under preprocessor remove any entries with
MIN_CRT in them and that should work just fine.On 7/8/07, Adam Stevenson wrote:

Right now, I am using visualc++ with no problems. Maybe if I sent you my
project file, you could try compiling that. You’re using 2k5?


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

The main.cpp file was from a year ago. There was a ‘CONFIG_WIN32’ that used to be
defined in one of the headers that I’m using. This was no longer defined. That was
causing ‘#undef main’ to not be seen. So, I defined CONFIG_WIN32 and it works
fine now.

BobOn Sun, Jul 08, 2007 at 01:01:47PM -0400, Bob Self wrote:

Now that I was able to get the .lib files for visualc to build, everything links
except that I get one last build error:

Compiling…
main.cpp
Linking…
MSVCRTD.lib(crtexe.obj) : error LNK2001: unresolved external symbol _main
Debug/main.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
Creating browse info file…

main.exe - 2 error(s), 1 warning(s)

I have checkecked that the sdl debug targets were built with debug multithreaded dll
settings. This must be something about sdlmain.lib. If I link with that I don’t
get the error, but my main() function doesn’t execute, so nothing happens when I
run it. My main function is declared as:

int main(int argc, char **argv) {…

Hello !

Also make sure you’re copying include/SDL_config_win32.h to
include/SDL_config.h before you start.

As the mails on this list show, many people
forget this.

Is it possible to include an #error, so that when compiling with
VisualC and not using SDL_config_win32.h it prints out an error
message saying: "Hey you need to copy … "

CU

Is it possible to include an #error, so that when compiling with
VisualC and not using SDL_config_win32.h it prints out an error
message saying: "Hey you need to copy … "

That’s a great idea. I’ll add that.

Thanks!
-Sam Lantinga, Lead Software Engineer, Blizzard Entertainment

Is it possible to include an #error, so that when compiling with
VisualC and not using SDL_config_win32.h it prints out an error
message saying: "Hey you need to copy … "

Just as a proposal, we could try this:

  • SDL_config.h.default becomes SDL_config.h
  • The #else in that file #includes SDL_config_generated.h
  • The current SDL_config.h.in becomes SDL_config_generated.h.in

This way people that are expecting to just hit the build button in
Windows or Xcode or whatever can do so, and the Unix systems that have
to generate a header from autoconf anyhow pick up the slack.

Right now the #else statement #includes SDL_config_minimal.h, but I
think anything that falls into that case, that isn’t bootstrapping a new
platform port, is probably misbuilt anyhow.

I have a feeling that, going forward, “copy SDL_config.default.h by
hand” is going to be a constant FAQ, and this solution should make
everyone happy.

–ryan.

I have a feeling that, going forward, “copy SDL_config.default.h by
hand” is going to be a constant FAQ, and this solution should make
everyone happy.

Actually the default case is already taken care of nicely. The problem
happens when people use ./configure to do a cygwin build and then try to
build that source tree with Visual C++.

See ya,
-Sam Lantinga, Lead Software Engineer, Blizzard Entertainment

Actually the default case is already taken care of nicely. The problem
happens when people use ./configure to do a cygwin build and then try to
build that source tree with Visual C++.

  • Do a fresh svn checkout of branches/SDL-1.2
  • Unpack VisualC.zip so VisualC directory is in the root of the source tree.
  • Double-click the SDL.sln file to launch (in this case) VC++ 2005 Express.
  • Hit F7 to build.
  • This produces:

1>c:\documents and
settings\ryan\desktop\sdl12\src\video\sdl_yuv_sw.c(22) : fatal error
C1083: Cannot open include file: ‘SDL_config.h’: No such file or directory
1>c:\documents and settings\ryan\desktop\sdl12\src\video\sdl_yuv.c(22) :
fatal error C1083: Cannot open include file: ‘SDL_config.h’: No such
file or directory

(…plus 64 more of those.)

Copying SDL_config.default.h or SDL_config_win32.h to SDL_config.h fixes
it, of course.

Am I doing this the wrong way?

–ryan.

Actually the default case is already taken care of nicely. The problem
happens when people use ./configure to do a cygwin build and then try to
build that source tree with Visual C++.

  • Do a fresh svn checkout of branches/SDL-1.2
  • Unpack VisualC.zip so VisualC directory is in the root of the source tree.
  • Double-click the SDL.sln file to launch (in this case) VC++ 2005 Express.
  • Hit F7 to build.
  • This produces:

1>c:\documents and
settings\ryan\desktop\sdl12\src\video\sdl_yuv_sw.c(22) : fatal error
C1083: Cannot open include file: ‘SDL_config.h’: No such file or directory

Am I doing this the wrong way?

Well, make dist and make snapshot both copy SDL_config.h.default into place.
We should probably add the copy step to VisualC.html. I’ll do that now.

Thanks!
-Sam Lantinga, Lead Software Engineer, Blizzard Entertainment

Well, make dist and make snapshot both copy SDL_config.h.default into place.
We should probably add the copy step to VisualC.html. I’ll do that now.

I don’t want to keep harping on it, but I don’t understand why this
should work differently for people using Subversion vs those working
from a tarball. Is there a good reason to not just have it set up to
build correctly immediately from Subversion?

It seems like a trivial change that simplifies a few things, unless I’m
misunderstanding something. Which, of course, is my usual state. :slight_smile:

–ryan.

Just as a proposal, we could try this:

  • SDL_config.h.default becomes SDL_config.h
  • The #else in that file #includes SDL_config_generated.h
  • The current SDL_config.h.in becomes SDL_config_generated.h.in

The reason that doesn’t work is there are platforms which have both a
default SDL_config_XXX.h and a more specific one if configure is used.
Windows is one - cygwin and mingw both use configure and VC++ use the
pre-built one.

I racked my brain for about a week on this one, but let me know if I
missed anything. :slight_smile:

See ya,
-Sam Lantinga, Lead Software Engineer, Blizzard Entertainment