HolyBlackCat / quasi-msys2

Cross-compile C/C++ from Linux to Windows using MSYS2 packages
zlib License
97 stars 6 forks source link

.exe suffix #1

Closed lockie closed 3 years ago

lockie commented 3 years ago

Hi! Thanks for an awesome tool, booted it up with no problems. Unfortunately there's a problem with a program I'm trying to build, namely, it compiles and runs some binaries in the process, and the thing is GCC adds .exe suffix to the binary, but the build scripts are trying to start it without the suffix and failing with "No such file or directory". When using Wine, it does add the suffix automatically when you skip it. Do you think this can be circumvented?

HolyBlackCat commented 3 years ago

@lockie I've added wrappers for C/C++ compilers that duplicate the resulting binaries without the .exe extension, this could help. Activate them with source env/duplicate_exe_outputs.src.

lockie commented 3 years ago

Thank you! I've tried using that, there was a hiccup with the win-dupebin-cc script (I had to add env/wrappers to PATH to fix it), and then I got this:

win-dupebin-cc -Wunused-parameter -fno-omit-frame-pointer -momit-leaf-frame-pointer -I../src/runtime   determine-endianness.c  -ldl -o determine-endianness
/tmp/quasi-msys2/env/wrappers/win-dupebin-cc: 3: -Wunused-parameter: not found
make: *** [<builtin>: determine-endianness] Error 127

I guess it has something to do with parameter escaping in that script?..

HolyBlackCat commented 3 years ago

env/wrappers will be in the PATH if you work in the shell launched by env/shell.sh. That script sets up several other env variables to the same values as MSYS2, and compilation should probably be done from that shell.

This problem was caused by missing shebags in the shell scripts. :facepalm: .

It should be fixed now, but you need to manually delete env/fake_bin after updating and before running env/shell.sh.

lockie commented 3 years ago

Now with this wrapper script launched, my build breaks in a weird way. Without duplicating wrapper:

gcc  -g -W -Wall -Wno-unused-function -Wno-unused-parameter -Wno-cast-function-type -fno-omit-frame-pointer -O5 -m64 -DWINVER=0x0501 -D__W32API_USE_DLLIMPORT__ -I../src/runtime   determine-endianness.c  -l ws2_32 -ladvapi32 -o determine-endianness
make: Leaving directory '/tmp/sbcl-2.1.7/tools-for-build'
make-config.sh: 703: tools-for-build/determine-endianness: not found

With the wrapper:

win-dupebin-cc -g -W -Wall -Wno-unused-function -Wno-unused-parameter -Wno-cast-function-type -fno-omit-frame-pointer -O5 -m64 -DWINVER=0x0501 -D__W32API_USE_DLLIMPORT__ -I../src/runtime   determine-endianness.c  -l ws2_32 -ladvapi32 -o determine-endianness
warning: unknown warning option '-Wno-cast-function-type'; did you mean '-Wno-bad-function-cast'? [-Wunknown-warning-option]
warning: optimization level '-O5' is not supported; using '-O3' instead
2 warnings generated.
/usr/bin/ld: unrecognised emulation mode: i386pep
Supported emulations: elf_x86_64 elf32_x86_64 elf_i386 elf_iamcu elf_l1om elf_k1om
clang-12: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [<builtin>: determine-endianness] Error 1
make: Leaving directory '/tmp/sbcl-2.1.7/tools-for-build'

I was able to fix this by writing my own wrapper script which just calls gcc directly instead of ${WIN_DUPEBIN_CC-$CC} (whatever that means :sweat_smile: ). And with this fix, I was able to complete my seemingly impossible build! Thank you man, you're genius :smiley: If I'd be able to launch your amazing tool under Docker, this would be a complete game-changer :laughing:

HolyBlackCat commented 3 years ago

@lockie You're welcome!

${WIN_DUPEBIN_CC-$CC} means $WIN_DUPEBIN_CC if it's set, and otherwise $CC. So instead of creating a wrapper, you can just export CC=gcc.

Though env/shell.sh should've set CC automatically, it looks like you're not running it.