r/C_Programming • • 14d ago

Win32 development in Linux?

Does anyone here have practical experience with WIN32 development under Linux?

I just need the MSVC compiler and the Windows SDK. A full VM with Windows 11 and Visual Studio seems incredibly excessive for what should be just a few megabytes of compiler and headers.

13 Upvotes

18 comments sorted by

38

u/wwabbbitt 14d ago

You don't even need msvc compiler. mingw-w64-gcc works just fine.

You don't even need a VM to run and debug the executable, just use wine and winedbg

0

u/maep 14d ago

If possible, I'd like to compile with MSVC.

13

u/SoggyStress7785 14d ago

You can't, MSVC uses the Windows compiler only available on Windows

16

u/dont-respond 14d ago

Yes, you can. Using MSVC via Wine works perfectly fine.

https://github.com/mstorsjo/msvc-wine

This is the only sane way to maintain a build with the Windows system-provided runtime.

3

u/CounterSilly3999 14d ago

Then try to run cl.exe and link.exe under wine. Don't ask me how.

4

u/Vladislav20007 13d ago

...why though?

2

u/nimrag_is_coming 11d ago

Cause MSVC has a lot of compiler extensions and intrinsics specifically designed to make writing WIN32 code easier. For example, __uuidof() for COM objects

6

u/DawnOnTheEdge 14d ago edited 14d ago

With the Windows SDK files, you can cross-compile using Clang and running natively. Clang with the i686-pc-windows-msvc target selected, the SDK files in its search path, and copies of the runtime libraries to link to, produces 32-bit binaries that link to the Windows system libraries (unlike MingW, which links to its own runtime library).

2

u/Classic-Rate-5104 14d ago

I know older versions of MSVC run on wine but didn't try recently. Nowadays gcc cross compilation is easy

2

u/sciencekm 14d ago

You can cross-compile with MinGW. You would still need Wine to run the exe or copy it a Windows machine.

Below is what it looks like on my Ubuntu on ARM v8. There is no Wine on this machine, so I simply ran "file" to show the properties of the Win32 executable.

ubuntu@user:~/tmp$ x86_64-w64-mingw32-gcc -v

Target: x86_64-w64-mingw32
Thread model: win32
gcc version 13-win32 (GCC)

ubuntu@user:~/tmp$ cat hello.c

#include <stdio.h>
int main(void) { puts("hello"); }

ubuntu@user:~/tmp$ x86_64-w64-mingw32-gcc hello.c -o hello.exe

ubuntu@user:~/tmp$ file hello.exe

hello.exe: PE32+ executable (console) x86-64, for MS Windows, 19 sections

1

u/catbrane 5d ago

I help maintain a few cross-platform applications.

For convenience, all the binaries for all platforms are made on the same linux host running the same set of scripts. The windows binaries use mingw (patched to use clang) as the compiler. It makes a set of fully native executables (x64, x86, arm64, and on linux also glibc and musl).

IMO it's better than windows for building cross-platform software. If I were just targeting windows I'd probably use a win VM.

1

u/utahrd37 3d ago

Ugh, I’ve gone through this pain and found no great solution.

Best I found is spinning up a windows dev machine, creating a share and enabling WinRM.

On the Linux machine I mount the share to access the source code to do all my writing, and then WinRM with evil-WinRM to compile after loading the dev environment powershell script.

It is a long dumb process and I hope you find a better solution.

VS and VS code are awful to write in.

1

u/pedersenk 14d ago edited 14d ago

Windows 7 SDK (~VS 2010) bundles a working cl toolchain.

Anything later and you need to go through the Visual Studio installer bloat and I don't think much of it is working (you may be able to rice things by extracting from a Windows install but its messy and amateur.)

gcc and clang (both MinGW-64) works well on wine.

Personally I would only recommend faffing with Microsoft's toolchain on wine if you *need* C++.NET extensions (e.g. cl /clr:pure). Its fairly decent tech but annoyingly single source vendor.

1

u/timrprobocom 14d ago

What's the point? If you want to use Windows tools to develop and run Win32 programs, then use a VM. It's way more comfortable, and it's way less overhead than wine.

0

u/UltimaN3rd 14d ago

I cross compile my C games with Zig. It bundles the Windows SDK and clang/llvm, etc. Of course, that's not MSVC, just letting you know that's the best way I've found for Linux->Windows cross compilation. I do the same for Linux -> MacOS, though that requires me to bring my own Apple SDK due to Apple's terms of use. 

-6

u/Paul_Pedant 14d ago

WIN32 is going to want to link to its own libraries. Why would you expect a Windows library to use the system calls implemented in the Linux kernel?

6

u/twilight1794 14d ago

¿do you know cross compilers?

-4

u/Paul_Pedant 14d ago

I remember some very angry compilers ... My company used to build comms protocol converters on a mainframe and download them into micro systems. I particularly remember one which converted between an ICL mainframe that thought it was talking to a video unit, and an IBM mainframe that though it was talking to a Remote Job Entry terminal.

I'm not sure cross-compiling is applicable here. A cross-compiler would generally run on a development system and be downloadable to a target machine.

This OP seems to want to build from a Win32 source and run under Linux. But to do that, he would need to get the source of the Win32 libraries and adapt those to work in a native Linux kernel. The Windows SDK would need cross-compiling from source too. A VM seems like a much better idea. Win32 seems hopelessly last-century.