News: 11 March 2016 - Forum Rules
Current Moderators - DarkSol, KingMike, MathOnNapkins, Azkadellia, Danke

Author Topic: Porting a windows executable to Linux?  (Read 980 times)

pianohombre

  • Sr. Member
  • ****
  • Posts: 336
    • View Profile
    • My personal website of short stories and comics
Porting a windows executable to Linux?
« on: April 22, 2021, 07:28:54 pm »
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

  • Submission Reviewer
  • Sr. Member
  • *****
  • Posts: 342
  • Obviously Outdated
    • View Profile
Re: Porting a windows executable to Linux?
« Reply #1 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.

pianohombre

  • Sr. Member
  • ****
  • Posts: 336
    • View Profile
    • My personal website of short stories and comics
Re: Porting a windows executable to Linux?
« Reply #2 on: April 24, 2021, 05:23:35 pm »
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

  • Jr. Member
  • **
  • Posts: 1
    • View Profile
Re: Porting a windows executable to Linux?
« Reply #3 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.

pianohombre

  • Sr. Member
  • ****
  • Posts: 336
    • View Profile
    • My personal website of short stories and comics
Re: Porting a windows executable to Linux?
« Reply #4 on: April 28, 2021, 05:21:56 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