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 4918 - SDL failed to build due to error LNK2019: unresolved external symbol memset referenced in function SDL_SetJoystickIDForPlayerIndex with MSVC x64 on Windows
Summary: SDL failed to build due to error LNK2019: unresolved external symbol memset r...
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: build (show other bugs)
Version: HG 2.1
Hardware: x86 Windows 10
: P2 major
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-12-26 08:49 UTC by LinGao
Modified: 2019-12-30 21:19 UTC (History)
1 user (show)

See Also:


Attachments
log_x64_build (27.08 KB, text/plain)
2019-12-26 08:49 UTC, LinGao
Details

Note You need to log in before you can comment on or make changes to this bug.
Description LinGao 2019-12-26 08:49:34 UTC
Created attachment 4139 [details]
log_x64_build

Hi,

We build SDL with Visual studio 2017 compiler on Windows Server 2016, but it failed to build due to error LNK2019: unresolved external symbol memset referenced in function SDL_SetJoystickIDForPlayerIndex with MSVC x64 on Windows on latest default branch. And we found that it can be first reproduced on 6c431d30a6df changeset. Could you please help have a look about this issue? Thanks in advance!

Steps to Reproduce:
1.hg clone https://hg.libsdl.org/SDL D:\SDL\src
2.Open a VS 2017 x64 command prompt as admin and browse to D:\SDL
3.msbuild /p:Configuration=Release /p:Platform=x64 /p:WindowsTargetPlatformVersion=10.0.17134.0 VisualC\SDL.sln /t:Rebuild

Actual result:
 Creating library D:\SDL\src\VisualC\x64\Release\SDL2.lib and object D:\SDL\src\VisualC\x64\Release\SDL2.exp
SDL_joystick.obj : error LNK2019: unresolved external symbol memset referenced in function SDL_SetJoystickIDForPlayerIndex [D:\SDL\src\VisualC\SDL\SDL.vcxproj]
D:\SDL\src\VisualC\x64\Release\SDL2.dll : fatal error LNK1120: 1 unresolved externals [D:\SDL\src\VisualC\SDL\SDL.vcxproj]
Done Building Project "D:\SDL\src\VisualC\SDL\SDL.vcxproj" (Rebuild target(s)) -- FAILED.
Comment 1 Ozkan Sezer 2019-12-26 09:33:27 UTC
Here is a possible fix:

diff --git a/src/joystick/SDL_joystick.c b/src/joystick/SDL_joystick.c
--- a/src/joystick/SDL_joystick.c
+++ b/src/joystick/SDL_joystick.c
@@ -158,9 +158,8 @@ SDL_SetJoystickIDForPlayerIndex(int play
         }
 
         SDL_joystick_players = new_players;
-        while (SDL_joystick_player_count <= player_index) {
-            SDL_joystick_players[SDL_joystick_player_count++] = -1;
-        }
+        SDL_memset4(SDL_joystick_players, (Uint32)(-1),
+         player_index + 1 - SDL_joystick_player_count);
     }
 
     SDL_joystick_players[player_index] = instance_id;
Comment 2 Ozkan Sezer 2019-12-27 20:31:52 UTC
(In reply to Ozkan Sezer from comment #1)
> Here is a possible fix:
My patch is obviously bad. Ignore.
Comment 3 Sam Lantinga 2019-12-30 21:19:16 UTC
Fixed, thanks!
https://hg.libsdl.org/SDL/rev/d06fbb1b5b78