# How to link with microsoft program?

**URL:** <https://discourse.libsdl.org/t/how-to-link-with-microsoft-program/14671>\
**Category:** SDL Development\
**Created:** [July 6, 2007, 3:02pm UTC](https://discourse.libsdl.org/t/how-to-link-with-microsoft-program/14671 "2007-07-06T15:02:24Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bob\_Self](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/b/848f3c/32.png) [@Bob\_Self](https://discourse.libsdl.org/u/Bob_Self)\
**Post date:** [July 6, 2007, 3:02pm UTC](https://discourse.libsdl.org/t/how-to-link-with-microsoft-program/14671/1 "2007-07-06T15:02:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Bob\_Self](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/b/848f3c/32.png) [@Bob\_Self](https://discourse.libsdl.org/u/Bob_Self)\
**Post date:** [July 6, 2007, 8:10pm UTC](https://discourse.libsdl.org/t/how-to-link-with-microsoft-program/14671/2 "2007-07-06T20:10:38Z")

</div>

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)  
> [http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org](http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)

---

<div class="post-metadata">

**Author:** ![slouken](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/s/ec9cab/32.png) [@slouken](https://discourse.libsdl.org/u/slouken)\
**Post date:** [July 6, 2007, 10:45pm UTC](https://discourse.libsdl.org/t/how-to-link-with-microsoft-program/14671/3 "2007-07-06T22:45:19Z")

</div>

> 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](http://www.libsdl.org/tmp/SDL-1.2.zip)

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

---

<div class="post-metadata">

**Author:** ![Bob\_Self](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/b/848f3c/32.png) [@Bob\_Self](https://discourse.libsdl.org/u/Bob_Self)\
**Post date:** [July 7, 2007, 11:13am UTC](https://discourse.libsdl.org/t/how-to-link-with-microsoft-program/14671/4 "2007-07-07T11:13:13Z")

</div>

> What version of SDL are you using?  
> Try the latest snapshot here:  
> [http://www.libsdl.org/tmp/SDL-1.2.zip](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

---

<div class="post-metadata">

**Author:** ![slouken](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/s/ec9cab/32.png) [@slouken](https://discourse.libsdl.org/u/slouken)\
**Post date:** [July 7, 2007, 4:31pm UTC](https://discourse.libsdl.org/t/how-to-link-with-microsoft-program/14671/5 "2007-07-07T16:31:33Z")

</div>

> 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

---

<div class="post-metadata">

**Author:** ![Bob\_Self](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/b/848f3c/32.png) [@Bob\_Self](https://discourse.libsdl.org/u/Bob_Self)\
**Post date:** [July 8, 2007, 12:18pm UTC](https://discourse.libsdl.org/t/how-to-link-with-microsoft-program/14671/6 "2007-07-08T12:18:32Z")

</div>

> 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)  
> [http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org](http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)

---

<div class="post-metadata">

**Author:** ![Bob\_Self](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/b/848f3c/32.png) [@Bob\_Self](https://discourse.libsdl.org/u/Bob_Self)\
**Post date:** [July 8, 2007, 5:01pm UTC](https://discourse.libsdl.org/t/how-to-link-with-microsoft-program/14671/7 "2007-07-08T17:01:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Adam\_Stevenson](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/adam_stevenson/32/673_2.png) [@Adam\_Stevenson](https://discourse.libsdl.org/u/Adam_Stevenson)\
**Post date:** [July 8, 2007, 5:37pm UTC](https://discourse.libsdl.org/t/how-to-link-with-microsoft-program/14671/8 "2007-07-08T17:37:47Z")

</div>

“Any ideas?”

I got one: try

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

---

<div class="post-metadata">

**Author:** ![Bob\_Self](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/b/848f3c/32.png) [@Bob\_Self](https://discourse.libsdl.org/u/Bob_Self)\
**Post date:** [July 8, 2007, 5:54pm UTC](https://discourse.libsdl.org/t/how-to-link-with-microsoft-program/14671/9 "2007-07-08T17:54:07Z")

</div>

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 )

---

<div class="post-metadata">

**Author:** ![Adam\_Stevenson](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/adam_stevenson/32/673_2.png) [@Adam\_Stevenson](https://discourse.libsdl.org/u/Adam_Stevenson)\
**Post date:** [July 8, 2007, 5:58pm UTC](https://discourse.libsdl.org/t/how-to-link-with-microsoft-program/14671/10 "2007-07-08T17:58:39Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Matthew\_Johnson](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/m/3bc359/32.png) [@Matthew\_Johnson](https://discourse.libsdl.org/u/Matthew_Johnson)\
**Post date:** [July 9, 2007, 5:23am UTC](https://discourse.libsdl.org/t/how-to-link-with-microsoft-program/14671/11 "2007-07-09T05:23:11Z")

</div>

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)  
> [http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org](http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)

---

<div class="post-metadata">

**Author:** ![Bob\_Self](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/b/848f3c/32.png) [@Bob\_Self](https://discourse.libsdl.org/u/Bob_Self)\
**Post date:** [July 9, 2007, 8:07pm UTC](https://discourse.libsdl.org/t/how-to-link-with-microsoft-program/14671/12 "2007-07-09T20:07:36Z")

</div>

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) {…

---

<div class="post-metadata">

**Author:** ![Torsten\_Giebl](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/torsten_giebl/32/2804_2.png) [@Torsten\_Giebl](https://discourse.libsdl.org/u/Torsten_Giebl)\
**Post date:** [July 11, 2007, 3:56pm UTC](https://discourse.libsdl.org/t/how-to-link-with-microsoft-program/14671/13 "2007-07-11T15:56:32Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![slouken](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/s/ec9cab/32.png) [@slouken](https://discourse.libsdl.org/u/slouken)\
**Post date:** [July 11, 2007, 4:36pm UTC](https://discourse.libsdl.org/t/how-to-link-with-microsoft-program/14671/14 "2007-07-11T16:36:13Z")

</div>

> 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

---

<div class="post-metadata">

**Author:** ![icculus](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/icculus/32/81_2.png) [@icculus](https://discourse.libsdl.org/u/icculus)\
**Post date:** [July 12, 2007, 4:20am UTC](https://discourse.libsdl.org/t/how-to-link-with-microsoft-program/14671/15 "2007-07-12T04:20:46Z")

</div>

> 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.

---

<div class="post-metadata">

**Author:** ![slouken](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/s/ec9cab/32.png) [@slouken](https://discourse.libsdl.org/u/slouken)\
**Post date:** [July 12, 2007, 4:27am UTC](https://discourse.libsdl.org/t/how-to-link-with-microsoft-program/14671/16 "2007-07-12T04:27:50Z")

</div>

> 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

---

<div class="post-metadata">

**Author:** ![icculus](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/icculus/32/81_2.png) [@icculus](https://discourse.libsdl.org/u/icculus)\
**Post date:** [July 12, 2007, 4:45am UTC](https://discourse.libsdl.org/t/how-to-link-with-microsoft-program/14671/17 "2007-07-12T04:45:54Z")

</div>

> 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.

---

<div class="post-metadata">

**Author:** ![slouken](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/s/ec9cab/32.png) [@slouken](https://discourse.libsdl.org/u/slouken)\
**Post date:** [July 12, 2007, 5:29am UTC](https://discourse.libsdl.org/t/how-to-link-with-microsoft-program/14671/18 "2007-07-12T05:29:29Z")

</div>

> > 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

---

<div class="post-metadata">

**Author:** ![icculus](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/icculus/32/81_2.png) [@icculus](https://discourse.libsdl.org/u/icculus)\
**Post date:** [July 12, 2007, 8:04am UTC](https://discourse.libsdl.org/t/how-to-link-with-microsoft-program/14671/19 "2007-07-12T08:04:50Z")

</div>

> 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. 🙂

–ryan.

---

<div class="post-metadata">

**Author:** ![slouken](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/s/ec9cab/32.png) [@slouken](https://discourse.libsdl.org/u/slouken)\
**Post date:** [July 12, 2007, 8:14am UTC](https://discourse.libsdl.org/t/how-to-link-with-microsoft-program/14671/20 "2007-07-12T08:14:41Z")

</div>

> 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. 🙂

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