ValveSoftware / halflife

Half-Life 1 engine based games
Other
3.66k stars 616 forks source link

[Linux] Build instructions for Linux? #3133

Open MegaBrutal opened 3 years ago

MegaBrutal commented 3 years ago

How am I supposed to build the server and client .so files (hl.so, client.so) for Linux?

I see there are makefiles in the dlls and linux subdirectories, but they don't work right off the bat; guess I'm supposed to make a special build environment for it. For example, linux/Makefile assumes I have a compiler at /valve/bin/g++-4.6 (yeah, I could symlink gcc, but then I noticed that the other Makefile seems to be newer, so I left it be); while dlls/Makefile seems to assume a much older version of GCC, as modern versions don't know the -m486 argument. I realized that the argument has changed to -march=486 and -m32 is also required to explicitly tell that I want to build 32-bit code (which is again a surprise, I thought Half-Life is on 64-bit already), but then it started to miss various .h files.

Sure I'm not the only one who wants to build the DLLs (SO files) for Linux, so if anyone succeeded so far, please shed some light!

As a personal note, I have customized DLLs from like 2007 for a mod I thought to make but never saw the light. Meanwhile I have completely moved to Linux and only have Windows on VMs and computers I don't care about. Thought it would be fun to resurrect the project and play my own mod on my native operating system. Also it's surprising and wonderful to see that people still make mods for Half-Life 1 even to this day, but sadly they rarely compile their customized DLLs for Linux – actually, I'm yet to see a fan made mod that supports Linux (and has custom server/client libraries to begin with). Maybe it would be nice to start a trend. :)

tschumann commented 3 years ago

Use the one in linux/ as the one in dlls/ is outdated and won't build client.so I updated the path to just use system gcc and that works. Half-Life may have had a 64 bit server but the game is still 32 bit. Which header files are missing? You'll need to install a package with 32 bit headers on newer Linux versions (I can't remember which but it'll depend on your distro anyway).

On Wednesday, 25 August 2021, MegaBrutal @.***> wrote:

How am I supposed to build the server and client .so files (hl.so, client.so) for Linux?

I see there are makefiles in the dlls and linux subdirectories, but they don't work right off the bat; guess I'm supposed to make a special build environment for it. For example, linux/Makefile assumes I have a compiler at /valve/bin/g++-4.6 (yeah, I could symlink gcc, but then I noticed that the other Makefile seems to be newer, so I left it be); while dlls/Makefile seems to assume a much older version of GCC, as modern versions don't know the -m486 argument. I realized that the argument has changed to -march=486 and -m32 is also required to explicitly tell that I want to build 32-bit code (which is again a surprise, I thought Half-Life is on 64-bit already), but then it started to miss various .h files.

Sure I'm not the only one who wants to build the DLLs (SO files) for Linux, so if anyone succeeded so far, please shed some light!

As a personal note, I have customized DLLs from like 2007 for a mod I thought to make but never saw the light. Meanwhile I have completely moved to Linux and only have Windows on VMs and computers I don't care about. Thought it would be fun to resurrect the project and play my own mod on my native operating system. Also it's surprising and wonderful to see that people still make mods for Half-Life 1 even to this day, but sadly they rarely compile their customized DLLs for Linux – actually, I'm yet to see a fan made mod that supports Linux (and has custom server/client libraries to begin with). Maybe it would be nice to start a trend. :)

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/ValveSoftware/halflife/issues/3133, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA34IYRNI7U4IFXPPTOIQKTT6Q72DANCNFSM5CX7ASNQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email .

solidi commented 3 years ago

@MegaBrutal - see my open pull request below. This successfully builds .dll, .so, and .dylib libs and publishes them directly on github on every commit. I hope this helps. https://github.com/ValveSoftware/halflife/pull/3113

MegaBrutal commented 3 years ago

Thanks for the replies! Meanwhile I built the SO files following this tutorial: https://twhl.info/wiki/page/Half-Life_Programming_-_Getting_Started

Although it's using Solokiller's fork: https://github.com/Solokiller/halflife-updated

Now the problem is that Half-Life can't load the libraries and it doesn't give much info why. For the client library, I only get the following message: could not load library .../client.so (In the place of "...", it writes the full path.)

When I try to go only with the server library, the following messages appear in the developer console.

LoadLibrary failed on /home/megabrutal/.steam/steam/steamapps/common/Half-Life/deltasection/dlls/hl.so: /home/megabrutal/.steam/steam/steamapps/common/Half-Life/deltasection/dlls/hl.so: undefined symbol: _ZdlPvj
Last 32 messages parsed.
0 0000 svc_bad
0 0000 svc_bad
0 0000 svc_bad
0 0000 svc_bad
0 0000 svc_bad
0 0000 svc_bad
0 0000 svc_bad
0 0000 svc_bad
0 0000 svc_bad
0 0000 svc_bad
0 0000 svc_bad
0 0000 svc_bad
0 0000 svc_bad
0 0000 svc_bad
0 0000 svc_bad
0 0000 svc_bad
0 0000 svc_bad
0 0000 svc_bad
0 0000 svc_bad
0 0000 svc_bad
0 0000 svc_bad
0 0000 svc_bad
0 0000 svc_bad
0 0000 svc_bad
0 0000 svc_bad
0 0000 svc_bad
0 0000 svc_bad
0 0000 svc_bad
0 0000 svc_bad
0 0000 svc_bad
0 0000 svc_bad
BAD:   -1:svc_bad
Wrote erroneous message to buffer.dat
Host_Error: Couldn't get DLL API from /home/megabrutal/.steam/steam/steamapps/common/Half-Life/deltasection/dlls/hl.so!

Contents of the mentioned buffer.dat:

00000000  00 00 00 00 ff ff ff ff                           |........|

So... the libraries are built but then just don't work.

What's also strange is that my SOs have significant size differences to the originals.

-rwxr-xr-x 1 megabrutal megabrutal 1036632 aug   26 00:23 deltasection/cl_dlls/client.so
-rwxr-xr-x 1 megabrutal megabrutal 4000283 márc  22  2020 valve/cl_dlls/client.so
-rwxr-xr-x 1 megabrutal megabrutal 2261332 aug   26 00:23 deltasection/dlls/hl.so
-rwxrwxr-x 1 megabrutal megabrutal 6773862 jún   21 00:06 valve/dlls/hl.so

Various other differences:

megabrutal@thinkpad:~/.steam/steam/steamapps/common/Half-Life$ file */dlls/hl.so
deltasection/dlls/hl.so: ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), dynamically linked, BuildID[sha1]=217a8c162def419cdbb4b028cccff1e105c7fea8, not stripped
valve/dlls/hl.so:        ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), dynamically linked, with debug_info, not stripped
megabrutal@thinkpad:~/.steam/steam/steamapps/common/Half-Life$ ldd valve/dlls/hl.so
    linux-gate.so.1 (0xf7f3d000)
    libm.so.6 => /lib/i386-linux-gnu/libm.so.6 (0xf7c2a000)
    libstdc++.so.6 => /usr/lib/i386-linux-gnu/libstdc++.so.6 (0xf7a4b000)
    libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0xf7854000)
    /lib/ld-linux.so.2 (0xf7f3f000)
    libgcc_s.so.1 => /lib/i386-linux-gnu/libgcc_s.so.1 (0xf7835000)
megabrutal@thinkpad:~/.steam/steam/steamapps/common/Half-Life$ ldd deltasection/dlls/hl.so
    linux-gate.so.1 (0xf7fbc000)
    libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0xf7b9a000)
    /lib/ld-linux.so.2 (0xf7fbe000)

As of now I have no modifications, aside from that I'm compiling Solokiller's fork (which might be the problem by itself, but as far as I know that should work as well).

ghost commented 2 years ago

I have exactly the same problem as @MegaBrutal, although I'm using this repo codebase instead of Solokiller's.

I had to adjust some defines to allow compiling on modern Linux tools but after the successful build the game refuses to load the compiled binaries, sending the exact same error as described.

Has anyone had any success building this?

MegaBrutal commented 2 years ago

@gabuch2 Yes, but you're definitely better off with Solokiller's (now SamVanheer) fork, because it's updated to compile on modern systems and I think it also has various other fixes.

My problem was that I had HLDS (Half-Life Dedicated Server) installed and it ships outdated versions of the standard C/C++ libraries which overrides the system default libraries your game SO files are (supposedly) built against. So your SO files require newer standard C/C++ libraries than the ones presented for them.

See this issue for details: https://github.com/SamVanheer/halflife-updated/issues/33

Either uninstall HLDS if not absolutely necessary (you can always install it with SteamCMD, I personally use a Docker container); or you can safely delete the problematic libraries as it doesn't do any harm (older applications seem to work with newer libraries, just not the other way around), but then updates may put them back.

Aside from HLDS, you may have built your libraries on a newer system than you're trying to use them.

f1am3d commented 1 year ago

I have similar question but platform independent. What C standard should be used? Compilator throws errors, like error C2668: 'abs': ambiguous call to overloaded function which does mean that some specific version of C++ should be used. But repository has no information about this.

tschumann commented 1 year ago

I think the abs error is just bit-rot - updated it to fabs in the problematic places and that should fix the error.