News:

11 March 2016 - Forum Rules

Main Menu

Porting a windows executable to Linux?

Started by pianohombre, April 22, 2021, 07:28:54 PM

Previous topic - Next topic

pianohombre

I was just curious if you it's pretty easy to port a program (written in c/c++) to linux? If it works in visual studio should it also compile in gcc? Also, if it works in Linux will it automatically work in Mac OS? I know there is virtual programs that emulate windows (such as wine), but obviously that's not ideal.
"Programming in itself is beauty,
whether or not the operating system actually functions." - Linus Torvalds

USC

It depends on the complexity of the program and how much it relies on Window-specific API. A simple PrintF() "Hello World" function? Sure, super easy to port. A GUI level editor that relies on specific Windows behavior? You're going to have to dig through it, swap all the Windows-specific function calls with Linux/Mac equivalents and then test to make sure things don't behave differently.

pianohombre

Quote from: USC on April 23, 2021, 11:13:52 AM
It depends on the complexity of the program and how much it relies on Window-specific API. A simple PrintF() "Hello World" function? Sure, super easy to port. A GUI level editor that relies on specific Windows behavior? You're going to have to dig through it, swap all the Windows-specific function calls with Linux/Mac equivalents and then test to make sure things don't behave differently.

Yea I was just thinking I use a lot of functions/components native to Microsoft Visual Studio, so it would be hard to port, but there's a feature called 'Workload for Linux development with C++' in Visual Studio that allows you to port over code from windows to linux through the shell. Sounds like a lot of work, but that's probably the best method. A lot of compilers are designed for both operating systems so it's probably best to start from scratch with a compiler like GNU Compiler rather than decide at the last second you want to port it.
"Programming in itself is beauty,
whether or not the operating system actually functions." - Linus Torvalds

bmarquis

From what I can see, the Windows Subsystem for Linux allows you to create and debug Linux apps, but it cannot port code magically.

I am confused with what you mean by "Native Windows Functions." Please elucidate.

pianohombre

Quote from: bmarquis on April 25, 2021, 11:09:40 PM
From what I can see, the Windows Subsystem for Linux allows you to create and debug Linux apps, but it cannot port code magically.

I am confused with what you mean by "Native Windows Functions." Please elucidate.

Code Visual Studio uses to create windows in the GUI, etc..
"Programming in itself is beauty,
whether or not the operating system actually functions." - Linus Torvalds