12 Replies - 478 Views - Last Post: 28 February 2011 - 04:51 PM

#1 papori  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 53
  • Joined: 02-December 10

same kind of CPU

Posted 03 February 2011 - 07:23 AM

Hey,
if i wrote a program in c++ that compiled at windows and run in cmd.
can i take the compiled program and run it on my linux machine , that work with the same CPU?

thanks :)
Is This A Good Question/Topic? 0
  • +

Replies To: same kind of CPU

#2 Kilorn  Icon User is offline

  • XNArchitect
  • member icon




Reputation: 1325
  • View blog
  • Posts: 3,504
  • Joined: 03-May 10

Re: same kind of CPU

Posted 03 February 2011 - 07:26 AM

I believe it depends on which compiler you use.
Was This Post Helpful? 0
  • +
  • -

#3 papori  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 53
  • Joined: 02-December 10

Re: same kind of CPU

Posted 03 February 2011 - 07:29 AM

View PostKilorn, on 03 February 2011 - 02:26 PM, said:

I believe it depends on which compiler you use.

But if i took the compiled code?
that have been compiled at windows..
Was This Post Helpful? 0
  • +
  • -

#4 Kilorn  Icon User is offline

  • XNArchitect
  • member icon




Reputation: 1325
  • View blog
  • Posts: 3,504
  • Joined: 03-May 10

Re: same kind of CPU

Posted 03 February 2011 - 07:58 AM

If you compile the code using certain compilers on Windows, specifically Visual C++, the compiled program definitely will not run on a linux machine.
Was This Post Helpful? 0
  • +
  • -

#5 papori  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 53
  • Joined: 02-December 10

Re: same kind of CPU

Posted 03 February 2011 - 08:05 AM

View PostKilorn, on 03 February 2011 - 02:58 PM, said:

If you compile the code using certain compilers on Windows, specifically Visual C++, the compiled program definitely will not run on a linux machine.

Thank u very much.
can u explain me what is exactly the problem?
what is the difference between exe in windows to a.out in linux, that prevent me to switch the OS?
Was This Post Helpful? 0
  • +
  • -

#6 Kilorn  Icon User is offline

  • XNArchitect
  • member icon




Reputation: 1325
  • View blog
  • Posts: 3,504
  • Joined: 03-May 10

Re: same kind of CPU

Posted 03 February 2011 - 08:17 AM

Each OS has different ways of handling applications. Windows has a specific way of sending and receiving information to and from a program that is completely different from how it would be handled on Linux. During the compilation of the code, this information is built into the program. You will have to compile the code on each machine using the proper compilers that are designed to work on those operating systems in order for the program to run on that operating system. There is a Windows emulator that runs on Linux that can run some Windows programs on Linux called WINE, but there's still no guarantee that it will work with any program that you create.
Was This Post Helpful? 2
  • +
  • -

#7 papori  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 53
  • Joined: 02-December 10

Re: same kind of CPU

Posted 03 February 2011 - 08:30 AM

thank u very much!
was helpfully!
Was This Post Helpful? 0
  • +
  • -

#8 oscode  Icon User is offline

  • D.I.C Regular

Reputation: 109
  • View blog
  • Posts: 257
  • Joined: 24-October 10

Re: same kind of CPU

Posted 04 February 2011 - 04:37 AM

The main issue is the binary file format. At a simplified level, Linux uses ELF and Windows uses PE.

Look here for more detail: http://stackoverflow...ats-terminology
Was This Post Helpful? 1
  • +
  • -

#9 ishkabible  Icon User is offline

  • spelling expret
  • member icon





Reputation: 1526
  • View blog
  • Posts: 5,514
  • Joined: 03-August 09

Re: same kind of CPU

Posted 04 February 2011 - 01:40 PM

the compiler isn't the issue the issue is the OS, file format, and OS specific functions needed to create a window. take the Linux program Wine it loads windows binary's so that they can be run on a Linux OS. i have played a number of games with DirectX, and XNA as well as ones that come with VC++ redistributables so it's more than a safe bet that they where compiled on windows with MSVC++ so just because it was compiled on windows dose not mean that i wont just not though normal means. just because code is cross platform doesn't mean the binary are, even if the code isn't cross platform doesn't mean that can't be run though some means.

This post has been edited by ishkabible: 04 February 2011 - 01:42 PM

Was This Post Helpful? 0
  • +
  • -

#10 ButchDean  Icon User is offline

  • Ex-Pro Games Programmer
  • member icon


Reputation: 875
  • View blog
  • Posts: 3,327
  • Joined: 26-November 10

Re: same kind of CPU

Posted 04 February 2011 - 02:00 PM

They compile into different instruction sets depending on platform - both the OS and the CPU. The program needs to be able to talk to the OS which in turn must be able to talk to the hardware. These are the differences.
Was This Post Helpful? 0
  • +
  • -

#11 ishkabible  Icon User is offline

  • spelling expret
  • member icon





Reputation: 1526
  • View blog
  • Posts: 5,514
  • Joined: 03-August 09

Re: same kind of CPU

Posted 04 February 2011 - 03:19 PM

ya i didn't touch on that, if where talking about windows then we are talking about x86/x64 and most Linux distros are x86 as well(i havn't seen any that aren't x86/x64)
Was This Post Helpful? 0
  • +
  • -

#12 janotte  Icon User is offline

  • code > sword
  • member icon

Reputation: 988
  • View blog
  • Posts: 5,135
  • Joined: 28-September 06

Re: same kind of CPU

Posted 05 February 2011 - 05:34 AM

View Postishkabible, on 05 February 2011 - 08:19 AM, said:

most Linux distros are x86 as well(i havn't seen any that aren't x86/x64)


Here's one
http://www.yellowdoglinux.com/

This post has been edited by janotte: 05 February 2011 - 05:37 AM

Was This Post Helpful? 0
  • +
  • -

#13 perfectly.insane  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 70
  • View blog
  • Posts: 644
  • Joined: 22-March 08

Re: same kind of CPU

Posted 28 February 2011 - 04:51 PM

View Postpapori, on 03 February 2011 - 10:23 AM, said:

Hey,
if i wrote a program in c++ that compiled at windows and run in cmd.
can i take the compiled program and run it on my linux machine , that work with the same CPU?

thanks :)


As stated before, PE binaries won't run under Linux without some help. WINE would allow you to run these binaries. Remember, WINE is not an emulator.

One major difference that I've thought of off hand besides the general binary file format:
Windows x86 DLLs do not use position independent code (PIC). If a DLL cannot be loaded in the virtual address range that it was designed to be, the OS has to update all references to areas that have to be relocated in the code itself. There's a section in the PE executable called .reloc that helps out with this. This lists offsets of all address references that need to be changed if the DLL is rebased at runtime by the OS so the OS doesn't have to interpret the machine code to figure this out. To my knowledge, Linux uses a global offset mechanism to support position independent code on x86. In x64 long mode, addressing relative to the instruction pointer (RIP) is allowed, eliminating the need for a separate offset mechanism (at least within module boundaries).

This post has been edited by perfectly.insane: 28 February 2011 - 05:06 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1