-
Notifications
You must be signed in to change notification settings - Fork 0
/
cross-win64-mingw.ini
125 lines (112 loc) · 6.75 KB
/
cross-win64-mingw.ini
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# --------------------------------------------------------------------------
# cross build definition file for compiling a 64-bit x86_64 executable for windows
#
# prerequisites on fedora linux
#
# sudo dnf install mingw64-gcc
# sudo dnf install wine-core # for testing the windows .exe file on linux
#
# set up a build directory:
#
# meson setup --cross-file cross-win64-mingw.ini build-dir-for-win64-mingw
#
# note: you may name the build directory whatever you want. a popular
# convention is to use 'build' or begin with 'build'. recommended. keeps all
# the build directories grouped together in file listing, and makes it easy to
# blow away all the builds with `rm -r build*/` or, safer, with interactive
# prompt: `rm -ri build*/` or `find . -maxdepth 1 -name 'build*' -type d
# -print0 | xargs -0rp -n 1 rm -r`.
#
# compile:
#
# meson compile -v -c build-dir-for-win64-mingw
#
# run on fedora linux using wine:
#
# winepath='/usr/x86_64-w64-mingw32/sys-root/mingw/bin' wine64 build-dir-for-win64-mingw/shapes_bouncing_ball.exe
#
# run on windows:
#
# build-dir-for-win64-mingw/shapes_bouncing_ball.exe
#
# --------------------------------------------------------------------------
[binaries]
# copied from documentation:
# https://mesonbuild.com/cross-compilation.html
# we only need 'c' and 'strip'. commented out the others.
c = 'x86_64-w64-mingw32-gcc'
#cpp = 'x86_64-w64-mingw32-g++'
#ar = 'x86_64-w64-mingw32-ar'
strip = 'x86_64-w64-mingw32-strip'
#exe_wrapper = 'wine64' # a command used to run generated executables.
# [properties]
# a deprecation warning is printed: c_link_args in the [properties] section of the machine file is deprecated, use the [built-in options] section.
# resolved the deprecation warning by moving c_link_args to new section [built-in options] below.
[built-in options]
# -lssp fixes: undefined reference to `__strcpy_chk'
# -lwinmm fixes: undefined reference to `timeendperiod' and 'timebeginperiod'
# not sure if needed: '-lsdl2main', '-lsdl2'
# would requires sdl2
# on fedora for mingw:
# sudo dnf install mingw64-sdl2, or
# sudo dnf install mingw64-sdl2-static, or
# on windows: maybe download from here https://www.libsdl.org/
# (i'm not sure about linking windows dll's statically)
# update: sdl2 is not needed afterall?!! not sure why i thought it was. i was just trying everything.
# for the record, at one point i had this:
# c_link_args = ['-lssp', '-lsdl2main', '-lsdl2', '-lm', '-luser32',
# '-lgdi32', '-lwinmm', '-limm32', '-lole32', '-loleaut32', '-lversion',
# '-luuid', '-ladvapi32', '-lsetupapi', '-lshell32', '-ldinput8', '-lmingw32',
# '-wl,--no-undefined', '-lmwindows']
# i pieced that together from looking at:
# /usr/x86_64-w64-mingw32/sys-root/mingw/lib/cmake/sdl2/sdl2statictargets.cmake
# and reading:
# https://github.com/msys2/mingw-packages/issues/6857
# note: had to remove -luser32 because it causes error: "multiple definition of closewindow"
# (update: maybe -fcommon would help with that. see known issues here: https://winlibs.com/)
# The following `c_link_args' line works but requires that i bundle libssp-0.dll and libwinpthread-1.dll with
# the .exe in order to execute on a windows machine. After making many attempts at statically linking
# these libraries, i finally gave up.
# Perhaps relevant:
# "This is an unfortunate limitation of Windows. Any dlls used by an executable must
# be in the same directory as the program or they must be in PATH. There are a few ways to work around this [...]"
# [Using zlib dependency on windows results in z.dll not found runtime error](https://github.com/mesonbuild/meson/issues/5385)
# NOTE: linking dynamically to bundled dlls is a legitimate (preferred?) way to
# go, so no big deal, although I'm curious why my attempts to statically link these libraries didn't work.
# NOTE: For a QT app, look into windeployqt. See, for example: https://github.com/FedoraQt/MediaWriter
c_link_args = ['-lssp', '-lwinmm']
# PROBLEM of trying to statically link libssp and libwinpthread:
# The resulting .exe runs fine under Wine, but when I copy to Windows, Windows complains about
# missing libssp.dll and libwinpthread.dll.
# I tried various ways to statically link libssp and libpwinpthread.
# A clue to the problem might be that, even with my attempts at statically linking, I still needed to add
# -lssp because otherwise the compile would get error "undefined reference to `__strcpy_chk'"
# https://sourceforge.net/p/mingw-w64/bugs/818/
# https://winlibs.com/
# https://stackoverflow.com/questions/13768515/how-to-do-static-linking-of-libwinpthread-1-dll-in-mingw
# https://stackoverflow.com/questions/67676088/mingw-gives-my-a-libwinpthread-1-dll-was-not-found-error-when-compiling-code
# https://stackoverflow.com/questions/56570819/gcc-exe-error-missing-libwinpthread-1-dll-but-it-is-not-missing
# I tried various linker flags to link statically. It didn't help.
#c_link_args = ['-lssp_nonshared', '-lwinmm']
#c_link_args = ['-static', '-static-libgcc', '-static-libstdc++', '-l:libwinpthread.a', '-lwinmm', '-lssp']
#c_link_args = ['-static-libgcc', '-static-libstdc++', '-Wl,-Bstatic', '-lstdc++', '-lpthread', '-Wl,-Bdynamic']
#c_link_args = ['-static-libgcc', '-Wl,-Bstatic', '-l:libwinpthread.dll.a', '-l:libssp.dll.a', '-l:libwinmm.a', '-Wl,-Bdynamic']
#c_link_args = ['-static-libgcc', '-Wl,-Bstatic', '-l:libwinpthread.a', '-l:libssp.a', '-l:libwinmm.a', '-Wl,-Bdynamic']
#c_link_args = ['-static-libgcc', '-Wl,-Bstatic', '-l:libwinpthread.a', '-l:libssp.a', '-l:libwinmm.a', '-Wl,-Bdynamic']
#c_link_args = ['-static-libgcc', '-Wl,-Bstatic', '-l:libwinmm.a', '-Wl,-Bdynamic', '-Wl,--start-group', '/usr/i686-w64-mingw32/sys-root/mingw/lib/libwinpthread.a','/usr/i686-w64-mingw32/sys-root/mingw/lib/libssp.a', '-Wl,--end-group', '-lssp']
# Aha! There is a separate package I need to install to get libwinpthread.a!
# $ sudo dnf repoquery --whatprovides '*/libwinpthread.a'
# mingw32-winpthreads-static-0:9.0.0-3.fc36.noarch
# I tried to see if I could remove the SSP dependency completely
#c_link_args = ['-lwinmm']
#c_args = ['-D_FORTIFY_SOURCE=0', '-fno-stack-protector']
#c_link_args = ['-Wl,--as-needed', '-static', '-static-libgcc', '-Wl,-Bstatic', '-l:libwinpthread.a', '-l:libssp.a', '-l:libwinmm.a', '-Wl,-Bdynamic', '-Wl,--as-needed', '-lssp']
#c_link_args = ['-Wl,--as-needed', '-static', '-static-libgcc', '-Wl,-Bstatic', '-l:libwinpthread.a', '-l:libssp.a', '-l:libwinmm.a']
# I give up. I will bundle the .dll dependencies and stop trying to statically link them. Maybe I was thinking about it wrong, or maybe
# maybe MINGW's gcc needs to be built with a special option or something, or maybe Fedora's build of MINGW's gcc has setting that
# implies the -lssp dependency.
[host_machine]
system = 'windows'
cpu_family = 'x86_64'
cpu = 'x86_64'
endian = 'little'