Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The difference between a program in C++ developed under Windows and Linux

Tags:

c++

linux

windows

What's the difference between a program developed in C++ under Windows and Linux?

Why can't a program developed under Windows in C++ be used under Linux?

like image 593
skydoor Avatar asked Feb 28 '10 02:02

skydoor


People also ask

Is C in Linux different from Windows?

The answer is simple: There is no difference!

How Windows programs are different from C programming?

There should be no difference between the C programming language under windows or *nix,cause the language is specified by the ISO standard. Show activity on this post. The C language itself is the portable from Windows to Unix. But operating system details are different and sometimes those intrude into your code.

Is coding in Linux different?

The daily life of a Linux programmer doesn't differ that much from those who are general programmers and use other programming languages besides C. When looking for a career in Linux programming, you can expect to be asked many of the same interview questions as different types of software developers.

What is C Programming with Linux?

C is a foundational programming language taught at engineering schools around the world, and represents one of the building blocks of modern computer information technology. Invented in the 1970's. It is still one of the most stable and popular programming languages in the world.


2 Answers

  • Windows and Linux use different container formats to hold the executable code (PE vs ELF).
  • Windows and Linux have completely different APIs (except for trivial programs that only use the CRT and STL)
  • Windows and Linux have a completely different directory structure

You could write a program that can use either set of APIs (for example, using Qt), and that can handle either directory structure, but you still won't be able to run the same file on both operating systems because of the differing container formats.

This can be solved by using Wine.

like image 65
SLaks Avatar answered Sep 24 '22 18:09

SLaks


In a nutshell,

  • Windows runs PE format executables
  • Linux runs ELF format executables

Furthermore, even if there were a tool to convert between PE and ELF, the program instructions necessary to interface with the operating system are completely different between Windows and Linux. Only the most restricted computation-only code (that only does calculations and doesn't interact with the operating system at all) could be ported between systems without special action. However, this is rarely done.

I believe some versions of Linux allow you to directly load device drivers designed for Windows without recompiling. However, this is an extremely special purpose application and the technique is not generally used.

like image 27
Greg Hewgill Avatar answered Sep 25 '22 18:09

Greg Hewgill