Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trying (and failing) to run Hello World 32-bit C++ program on 64-bit Ubuntu on Windows 10

I configured my new Ubuntu on Windows 10 from scratch in the following way:

# apt-get update
# apt-get install build-essential
# # Am able to compile now using "g++ -Wall -o Hello-World Hello-World.cpp", the binary is working.

# # To check versions, and that both packages were indeed installed
# gcc -v
    # make -v

# apt-get install g++-multilib
# # This also installs gcc-multilib as a dependency
# # Now able to compile using "g++ -m32 -Wall -o Hello-World Hello-World.cpp
# # However the binary Hello-World can't be run. Error message "bash: ./Hello-World: cannot execute binary file: Exec format error

# apt-get install lib32gcc1 lib32stdc++6
# # Those two packages are at this time already both installed and well

# dpkg --add-architecture i386
# apt-get update
# apt-get install libc6:i386 libncurses5:i386 libstdc++6:i386
# # Still getting the same error when wanting to ./Hello-World

I guess I'm still missing an xyz:i386 library, I just couldn't figure it out by myself which one's still missing. Also I'm not sure if this is an "Ubuntu on Windows"-specific thing, or if this would also have occured when procceeding the same way on a normal Ubuntu 64-bit OS. Do you have any suggestions?

And for completion, this is the content of the Hello-World.cpp file:

#include <iostream>

using namespace std;

int main (int argc, char **argv)

{

    cout << "Hellobaby" << endl;

return 0;
}
like image 279
Mandel Brot Avatar asked Apr 16 '16 14:04

Mandel Brot


People also ask

How can I run 32-bit software on 64 bit Ubuntu?

As far as I know, the same approach should work for 32 on 64 and for 64 on 32. Just change dpkg --add-architecture i386 to dpkg --add-architecture amd64 .

Can I run Ubuntu 32-bit on a 64 bit computer?

32-bit CPUs can only run 32-bit operating systems, but 64-bit architecture can run both 32-bit and 64-bit operating systems. It's preferable to utilize the 64-bit version of the OS to get the most out of the upgraded hardware technologies (64-bit CPU) (64-bit Ubuntu OS in our case).

How do I run a 32bit program on a 64 bit system?

WOW64 is the x86 emulator that allows 32-bit Windows-based applications to run seamlessly on 64-bit Windows. This allows for 32-bit (x86) Windows applications to run seamlessly in 64-bit (x64) Windows, as well as for 32-bit (x86) and 32-bit (ARM) Windows applications to run seamlessly in 64-bit (ARM64) Windows.

Does WSL support 32-bit?

WSL doesn't support 32-bit apps! No, we don't support x86 32-bit at this time: We currently depend on x64-only instructions and mechanisms to ensure fast & stable performance.


Video Answer


2 Answers

I think you didn't installed all the g++ related dependencies. Execute the below mentioned commands for installing the dependencies.

sudo apt-get install g++

enter image description here

enter image description here

like image 128
Nithin K Anil Avatar answered Oct 14 '22 13:10

Nithin K Anil


It seems to me that Sam Varshavchik was right, and Ubuntu on Windows doesn't currently support 32-bit architectured programs. I installed a virtual Ubuntu 64-bit on VirtualBox, and there - using the exact same commands as described in my initial post - the program compiles and runs.

Thanks everybody for your comments

like image 41
Mandel Brot Avatar answered Oct 14 '22 13:10

Mandel Brot