-
Notifications
You must be signed in to change notification settings - Fork 855
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
g++ failing to compile #1370
Comments
Is there a way for me to compile a binary my 64-bit windows machine can execute outside of WSL? |
Okay now I follow what you did (had to double take). Disregard my last post. Yes, you can create a PE binary on Linux (WSL or the real thing) by cross-compiling, but I'm going to go out on a limb and bet that's not what you're after. Download a copy of Visual Studio Community and create PE binaries on Windows for fun and profit. If you are really trying to create Windows PE binaries on Linux, you can use the mingw-w64 cross compiler package. None of this is a WSL thing, mind. Same answer would apply if you asked the question on a Linux forum. |
@Christian-Hill You have to understand what WSL is. It is not a simple shim layer with fake binaries that work the same as the native ones but are actually windows binaries behind the curtains. WSL runs an ACTUAL ubuntu distribution with the exact same binaries you would run on a normal ubuntu machine. When you run gcc, you're running the native linux gcc, the same you would run on an actual ubuntu distribution. So imagine the following, you're running that command It wouldn't work. And that's because you compiled it on one OS and ran on another (that is not binary compatible). The same thing applies here. Inside WSL you're running an authentic Ubuntu distribution, the only difference being that at kernel level, the system calls are translated to their equivalent NT kernel system calls (though certainly the translation is not always one-to-one). To compile something on WSL that you want to run on windows, you will have to cross-compile, as @therealkenc said. Same thing you would have to do to compile something on your hypothetical separated Ubuntu PC to be able to run it afterwards on your Windows PC. |
Is there a way to compile and build a project with make using mingw compiler on Windows, so that it would work on Windows afterwards? |
This is probably possible, but it could easily get complicated. One way would be to simply call Another way would be to use a cross-compiler: There are builds of gcc for native Ubuntu that will produce Windows binaries. The general term for building binaries on platform A but for platform B is "cross compilation". There are lots of guides to doing this online. Also -- if all you need is a replacement for nmake, Linux make (aka "gmake") has actually been ported to Windows: http://gnuwin32.sourceforge.net/packages/make.htm If all you need from Linux is its make command, that's probably the easiest solution. |
@aseering Thank you for answering! |
@EgZvor -- no problem! I'm curious, though -- how would a virtual machine help in this case? If it's a Windows VM, then you're still stuck with nmake. If it's a Linux VM, then you still have the problem that your UNIX dependencies won't be available when you copy your executable over to Windows in order to run it. |
@aseering |
@EgZvor -- yeah, I would just use Python in WSL. It's just a Python process, running natively on your processor; it should handle CPU-intensive stuff at least as well as a VM. Maybe better in some cases. There are limitations for other types of performance. For example, WSL doesn't expose graphics cards to Linux applications, so you can't do GPU-accelerated computation. Also, disk operations can be slower than in a VM, depending on what you're doing. But simple CPU-intensive workloads should be fast and should work well. |
The OP here ended up being a question about g++ usage. |
g++ fails to compile
Every time I compile a program using g++ on WSL and try to run it in my desktop, it provides an error, on further inspection it produced 16 bit code instead of 64 bit. I've tweaked g++ to compile 64 bit specific code and I'm still getting this error.
Expected to spit out a working .exe binary file.
Spits out a file that cannot execute
g++ -o example.exe example.cpp
gcc, gcc multilib , g++
See our contributing instructions for assistance.
The text was updated successfully, but these errors were encountered: