I'm a new C language learner and for facility. I downloaded Ubuntu 20.04 LTS WSL on my PC for compiling the code in gcc
. The problem is, that the code compiled in Ubuntu runs well, but when I send it to the Windows it says that the program can't run because there is no version compatible with x64 bits Windows. I compiled it with the -m64 flag to ensure is x64 bits but it still does not run on the Windows. What is the reason for that?
Binaries (compiled programs) are meant to be used on a specific system: when you install gcc in Ubuntu it automatically defaults to the Linux version of gcc and this version is only capable of creating a Linux binary.
Just as Linux can't use .exe
files out of the box, Windows can't use Linux binaries out of the box, that's why you have that "there is no version compatible with x64 bits Windows", it's because the file you're trying to use is compatible with x64 Linux .
Knowing that, there's multiple ways to go forward from here:
I'd probably go for 1 or 5, WSL2 is a nice tool but since you're limited to the terminal it's not really beginner friendly, I'd choose an OS, install a nice beginner friendly IDE on it (I started with Code::Blocks 10 years ago and I think it's still the most beginner friendly IDE there is) and start developing without the added complexity of WSL or even worse, cross-compiling.
I would suggest better compile your c program on the Windows system. Cross-compilation do work but you said you are new to this I would suggest install c compiler on the windows system and compile your code natively
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.