0

Not sure if this is the right place to ask this:

How do programs written in c++ run on other computers if you don't write them specifically to do that? I saw something about not just sending the .exe, but also sending other things with it?

Is there a high level programming language that is as fast or nearly as fast (in run speed) as c++ while also being platform independent?

See above.

gd1
  • 1
  • 2
  • You can run compiled programs on other systems by using emulators, such as Wine on Linux. This won't be as fast as using the program on the platform it was compiled for. – VLL Nov 02 '22 at 06:38
  • 1
    I think the question could do with a bit more clarity but C++ itself is platform independent, the C++ runtime will make the translation from (the C++ abstract machine) to the underlying OS. You will still need to compile your code for a specific OS. – Pepijn Kramer Nov 02 '22 at 06:38
  • https://stackoverflow.com/questions/65618221/what-does-platform-independent-languages-really-mean – VLL Nov 02 '22 at 06:42
  • https://www.quora.com/Are-compiled-programs-platform-independent – VLL Nov 02 '22 at 06:44
  • Are you concerned about having to send .dlls with the .exe (you can avoid that), or about the .exe not working on different OSes? – HolyBlackCat Nov 02 '22 at 07:13

2 Answers2

0

You compile your code for all the platforms you target and deploy a number of executables. Hence, Write once, compile anywhere.

Aykhan Hagverdili
  • 28,141
  • 6
  • 41
  • 93
0

C++ allows you to write portable source code. So assuming you write portable code to start with, you can compile it for some target platform, and run the resulting binary on that target.

Now, depending on what your program uses, you may have to package other "stuff" with the executable. What you mention ("I saw something about not just sending the .exe, but also sending other things with it?") would arise if your program used some dynamic link libraries that were not part of the OS (presumably Windows, based on the mention of .exe). But, it's kind of up to you to decide whether to use a library that's packaged as a DLL or not. If you don't want to package DLLs with your executable, don't use them (but sometimes, you may decide it's less trouble to use and package the DLL than do without).

As far as another language goes...doesn't really make a lot of difference as a rule. If you write code that depends on something else, you have to satisfy that dependency on the target computer. Some languages require you to add some DLLs to support the language itself, but most C++ compilers don't. On other OSes, those dependencies won't be called "DLLs", but most reasonably modern OSes provide something similar.

Jerry Coffin
  • 476,176
  • 80
  • 629
  • 1,111