2

这个问题可能听起来有点含糊,但我不知道该如何表达。我想知道你是否可以制作一个C++类似于文件的JAR文件(因此它独立于 eclipse/cmd 运行)。我还想知道C++. 这里没有问题,我只是好奇。

注意:我是一个 C++ 菜鸟,但已经使用 java 编程一年多了。

4

3 回答 3

7

Your Java code is translated into JAR which is bytecode which is translated in run-time to machine code. You can run this file on each platform.

C++ is translated to machine code at the time of compilation. You can't transport compiled executable between platforms. For each platform you need to compile source files again.

于 2012-07-30T07:11:46.477 回答
3

Short answer: No.

Longer answer: No, because C++ is not platform independent. Even if you use only standard library functions like the standard containers, the executable you create can not run on other systems, sometimes not even on other version of the same platform (Linux is known for this).

于 2012-07-30T07:13:18.693 回答
1

Yes of course. C++ is a platform independent programming language, which means that you can compile every simple program on every platform, as long as you don't use platform specific features. This means you can compile it on every platform. But that does not mean that your executable is cross-platform, like a Java JAR.

When you compile it, you create a native executable. In Windows, it compiles to an exe. In Linux / OS X (unix) an extension-free file.

So, it depends on what you really want. (Since your question is a bit vague)

And if you are searching for a single cross-platform solution: the answer is no.
If you are searching for a way to make your application start without terminal: the answer is yes. (But I don't know how, since I never used Windows)

于 2012-07-30T07:09:51.600 回答