skullernet / openffa

Free-for-all deathmatch mod for Quake 2
GNU General Public License v2.0
22 stars 11 forks source link

Could not cross-compile from Ubuntu 22 host (WSL2) for Windows #15

Closed amokmen closed 1 year ago

amokmen commented 1 year ago

I am noob in compilation and absolute zero at cross-compilation. Lost 2 hours for useless and stupid monkey-copy-pasting.

Installed sudo apt install mingw-w64.

Changes in Makefile:

Tried to set:

WINDRES ?= "x86_64-w64-mingw32-windres"
STRIP ?= "x86_64-w64-mingw32-strip"

Tried to remove (because of errors):

LDFLAGS += -mconsole
LDFLAGS += -Wl,--nxcompat,--dynamicbase

Added search path -L "/usr/x86_64-w64-mingw32/lib/" here:

LIBS += -lws2_32 -L "/usr/x86_64-w64-mingw32/lib/"

Last output:

[CLEAN]
[CC] g_bans.o
[CC] g_chase.o
[CC] g_cmds.o
[CC] g_combat.o
[CC] g_func.o
[CC] g_items.o
[CC] g_main.o
[CC] g_misc.o
[CC] g_phys.o
[CC] g_spawn.o
[CC] g_svcmds.o
[CC] g_target.o
[CC] g_trigger.o
[CC] g_utils.o
[CC] g_vote.o
[CC] g_weapon.o
[CC] p_client.o
[CC] p_hud.o
[CC] p_menu.o
[CC] p_view.o
[CC] p_weapon.o
[CC] q_shared.o
[RC] openffa.o
[LD] gamex86_64.dll
/usr/bin/ld: p_client.o: warning: relocation against `g_start_health' in read-only section `.text'
/usr/bin/ld: g_bans.o: relocation R_X86_64_PC32 against symbol `gi' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: bad value
collect2: error: ld returned 1 exit status
make: *** [Makefile:113: gamex86_64.dll] Error 1
skullernet commented 1 year ago

You don't need to modify Makefile at all. Revert all changes, run make clean, create file named .config with the following contents and recompile.

CPU=x86_64
SYS=Win64

CC=x86_64-w64-mingw32-gcc
STRIP=x86_64-w64-mingw32-strip
WINDRES=x86_64-w64-mingw32-windres

CONFIG_WINDOWS=y
amokmen commented 1 year ago

Thank you!

So, as I see, I did half-way :)

Was wrong compiler - gcc (by default from Makefile). And complete new setting SYS.

Well, should I add PR to create .config file? Or you could add it by yourself?

# Optional configuration file for Makefile
# Any symbol after "=" would initialize variable, in other words would make it "true"

CONFIG_X86_NO_SSE_MATH=
CONFIG_VARIABLE_SERVER_FPS=

# Three mutually exclusive options
CONFIG_SQLITE=
CONFIG_CURL=
CONFIG_UDP=

# Cross-compile section (uncomment all lines if need to compile for Windows)
# For Ubuntu there should be pre-installed: `sudo apt install mingw-w64`

#CONFIG_WINDOWS=y
#CPU=x86_64
#SYS=Win64
#CC=x86_64-w64-mingw32-gcc
#STRIP=x86_64-w64-mingw32-strip
#WINDRES=x86_64-w64-mingw32-windres
amokmen commented 1 year ago

And probably second file - INSTALL.md with smth like this:

Install

Check out .config file for all compiling options and cross-compile info.

skullernet commented 1 year ago

SYS is actually not needed, I forgot about that.

.config file is supposed to be created by user, thus it should not exist by default. Maybe it belongs to examples/. But I plan to ditch legacy Makefile-based build system anyway, so it will become obsolete very soon.

amokmen commented 1 year ago

is supposed to be created by user

Yeap, like this? :)

cat Makefile | grep CONFIG | tail -7 | cut -d" " -f2

Poor user :(

it will become obsolete very soon.

Okay then.