With my very mostly embedded C knowledge, I've written a little program to automate things when I wake the PC remotely, it'll do stuff based on MQTT messages from my home automation. Had to have /mnt/c/<full-path> in front of any program I want run, no big deal. This little program is compiled using GCC under the Linux shell now available on Windows. It runs nicely when invoked from the Linux shell using the usual Linux method: "./name.exe" But when I double click on the EXE in Explorer, expecting it to work like any Windows program....... nope! How do I run Linux subsystem GCC generated executable in Windows as a normal Windows program? I want to run it on start-up or from start menu, and want to see console printout.
Unless something's changed recently, you don't. You might have given the file a .EXE extension, but what you've compiled is an ELF - a Linux binary, not a Windows binary. You need to compile it for Windows - assuming the underlying code is portable, if not you need to rewrite it for Windows or run it in WSL. You can compile for Windows in WSL like so: Code: sudo apt install mingw-w64 x86_64-w64-mingw32-gcc -o name.exe name.c It won't run in WSL any more, of course!
You can execute Linux binaries from inside WSL using the wsl.exe command. Thus you can create a batch file which runs wsl.exe CmdLine to run CmdLine command inside a WSL instance. See here https://docs.microsoft.com/en-us/windows/wsl/interop
Nice - either that wasn't a thing last time I played, or I just didn't know about it. Compiling the program as an actual Windows executable would mean a lot less overhead, mind - otherwise you're effectively running two operating systems for the sake of one small program.
Perfect, that bath file method is exactly what I'm looking for. Code: wsl ./pc.exe Thank you! Last time I did it, before Windows Linux shell was a thing, I used Cygwin (I think! might have been MinGW) its GCC was able to generate an EXE that I can click on. One mustn't assume. Edit: missed the last part. Resource isn’t an issue on my desktop, there’s soooo much to go around, compared to embedded systems.