We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 2540 - "Symbol already defined in object" with static library of SDL2 compiled by Visual Studio
Summary: "Symbol already defined in object" with static library of SDL2 compiled by Vi...
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: *don't know* (show other bugs)
Version: 2.0.3
Hardware: x86_64 Windows 7
: P2 normal
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-05-12 07:37 UTC by oliverrheinhardt
Modified: 2015-02-19 05:48 UTC (History)
1 user (show)

See Also:


Attachments
SDL 2.0.3 source code in static library configuration with MSVC. (2.70 MB, application/x-7z-compressed)
2014-05-12 09:21 UTC, oliverrheinhardt
Details

Note You need to log in before you can comment on or make changes to this bug.
Description oliverrheinhardt 2014-05-12 07:37:02 UTC
Version : SDL 2.0.3
Platform: Windows (x86/x64)
Compiler: Microsoft Visual Studio 2008 / 2012 Express Edition

I wanted to use "SDL2.lib" compiled as a static library in Microsoft Visual Studio, since the license of SDL was changed from LGPL to zlib license.

However, I faced an problem of LNK2005 "Symbol already defined in object".
The conflicting functions are written in line 236 to 943 in "SDL_stdlib.c" as follows.

[In case of x86]
__fltused
__ftol2_sse
__allmul
__alldiv
__aulldiv
__allrem
__aullrem
__allshl
__aullshr

[In case of x64]
memcpy
__fltused

I read several articles related to static linking of SDL2 as follows and I found no information about those duplicating functions.

Title: Static linking SDL2 with /MT in MSVC.
Address: http://comments.gmane.org/gmane.comp.lib.sdl/62852

Title: Link SDL2 statically with Visual C++ 2012
Address: http://forums.libsdl.org/viewtopic.php?t=8962&sid=ce2532a182ecbd7f08146f1ca5387b86

Title: Bug 1820 – building SDL as a static library with static runtime doesn't compile/link with visual studio
Address: https://bugzilla.libsdl.org/show_bug.cgi?id=1820

At least, there was no problem when I commented out those functions written in line 236 to 943 in "SDL_stdlib.c".

Therefore, I think these functions are not necessary when we use SDL 2.0.3 compiled with Microsoft Visual Studio, but I'm not sure.

Many thanks,
Comment 1 oliverrheinhardt 2014-05-12 09:21:28 UTC
Created attachment 1646 [details]
SDL 2.0.3 source code in static library configuration with MSVC.

I used "VisualC/VS2012EE.sln" and related projects.
The properties of them are a little bit changed.
Source codes are not changed.

1) For "SDL2" project, all configurations, all platforms.
"Configuration Type" was changed from ".dll" to ".lib".

2) For all projects, "Release" configuration, all platforms.
"Runtime libraries" was changed from /MD to /MT.

3) For all projects, "Debug" configuration, all platforms.
"Runtime libraries" was changed from /MDd to /MTd.

I forgot to mention that there is NO ERROR in "SDL2.lib" build.
It works.
However, when I try to LINK this library, the LNK2005 occurs.
Comment 2 Sam Lantinga 2014-06-22 17:15:50 UTC
If you link SDL statically, you also need to define HAVE_LIBC so it builds with the C runtime that your application uses.

This should probably go in a FAQ.
Comment 3 oliverrheinhardt 2014-06-23 03:33:53 UTC
(In reply to Sam Lantinga from comment #2)
> If you link SDL statically, you also need to define HAVE_LIBC so it builds
> with the C runtime that your application uses.
> 
> This should probably go in a FAQ.

Oh, thank you.
At that time I could not find it. :(

Many thanks,
Comment 4 Ryan C. Gordon 2015-02-19 05:42:19 UTC
Can this bug be closed, then?

--ryan.
Comment 5 oliverrheinhardt 2015-02-19 05:48:57 UTC
Oops, I'm sorry for not telling you about it clearly.
Yes, I think so.
Thanks for your help.