Are C++ applications cross-platform?

前端 未结 6 1489
北荒
北荒 2020-12-07 15:35

One of the first things I learned as a student was that C++ applications don\'t run on different operating systems. Recently, I read that Qt based C++ applications run every

6条回答
  •  半阙折子戏
    2020-12-07 16:26

    Standard C++ is cross platform in the "write once, compile anywhere" sense, but not in the "compile once, run anywhere" sense.

    That means that if you write a program in standard C++, you can compile and then run it on any target environment that has a standard conforming implementation of C++.

    You can however not compile your program on your machine, ship the binary and then expect it to work on other targets. (At least not in general. One can of course distribute binaries from C++ code under certain conditions, but those depend on the actual target. This is a broad field.)


    Of course, if you use extra, non-standard features like gcc's variable length arrays or third party libraries, you can only compile on systems that provide those extensions and libraries.

    Some libraries like Qt and Boost are available on many systems (those two on Linux, Mac and Windows at least I believe), so your code will stay cross platform if you use those.

提交回复
热议问题