FWGS / hlsdk-portable

Portable Half-Life SDK. GoldSource and Xash3D. Crossplatform.
https://xash.su
Other
272 stars 124 forks source link

unresolved external symbol, opfor x64 vs2019 #101

Closed noabody closed 5 years ago

noabody commented 5 years ago

This is more of a comment than an issue because, AFAIK, building on Windows 10 64-bit with Visual Studio 2019 is not supported. It can, however, be built. See my brief blog post: build xash3d 64-bit Win10 vs2019.

The only issue I discovered relates to this error while building the "opfor" branch:

  Generating Code...
     Creating library D:/Dev/xash3d/gearbox/build/dlls/Release/opfor64.lib and object D:/Dev/xash3d/gearbox/build/dlls/
  Release/opfor64.exp
ctf_items.obj : error LNK2019: unresolved external symbol "char * __cdecl GetTeamName(int)" (?GetTeamName@@YAPEADH@Z) r
eferenced in function "private: void __cdecl CItemFlag::Capture(class CBasePlayer *,int)" (?Capture@CItemFlag@@AEAAXPEA
VCBasePlayer@@H@Z) [D:\Dev\xash3d\gearbox\build\dlls\server.vcxproj]
    Hint on symbols that are defined and could potentially match:
      "char const * __cdecl GetTeamName(int)" (?GetTeamName@@YAPEBDH@Z)
D:\Dev\xash3d\gearbox\build\dlls\Release\opfor64.dll : fatal error LNK1120: 1 unresolved externals [D:\Dev\xash3d\gearb
ox\build\dlls\server.vcxproj]

I understand it's related to ANSI/Unicode strings as mentioned here: Working with Strings

This patch resolves the issue:

diff --git a/dlls/gearbox/ctf_items.cpp b/dlls/gearbox/ctf_items.cpp
index ab38378..8f6bcb3 100644
--- a/dlls/gearbox/ctf_items.cpp
+++ b/dlls/gearbox/ctf_items.cpp
@@ -34,7 +34,7 @@ This contains the Flag entity information for the Half-Life : Opposing force CTF

 extern int gmsgCTFMsgs;

-extern char* GetTeamName(int team);
+const char* GetTeamName(int team);

 /*****************************************************

I have no idea why that works but only found one instance of extern char* and numerous const char* so it ended up being a guess. I suspect the change would be compatible with both GCC and the Microsoft compiler but don't really know.

I've built with VS2019 and GCC8 so this code is rolling forward nicely.

mittorn commented 5 years ago

It is related to return type. MSVC mangle respects return type, but gcc's not, so wrong declaration worked with gcc

nekonomicon commented 5 years ago

Fixed in https://github.com/FWGS/hlsdk-xash3d/pull/102/commits/7ad7133267f6cdf2957c343d5c70e3478fd54368