質問

In my windows 8.1 machine, I tried to compile the kprogram

g++ -o helloworld helloworld.cpp

Then an executable file named "helloworle.exe" is created. This is inconsistent with my Cygwin on the windows 7 machine, where the compiled executable is named "helloworld". How do I eliminate the extension generated by the Cygwin g++?

I am trying to keep them consistent so in the git there won't be two files of the same thing. Thanks!

役に立ちましたか?

解決

Yes, it's possible. Here is a link to my answer for the same thing with Cygwin GCC. It works for g++ too.

By telling the linker how to name its output.

$ echo -e "#include <iostream>\nclass myClass { public: myClass() { 
  std::cout << \"Hello here is my class.\\\n\"; } };\nint main(int nbargs, char *args[]) {
  myClass *myInstance = new myClass();
  }" | g++ -pipe  -x c++ - -Wl,-oess2

This will produce an ess PE32 / PE32+ executable file, not a ess.exe. The -pipe option instructs the GCC build chain to not write temporary files but use pipe between stages instead. The -Wl,-o option inhibits the default --force-exe-suffix.

他のヒント

CygWin gcc suite always generates executables with an .exe extension because that's how it runs them in the Windows environment.

If you look into the <cygwin-base>\bin directory, you'll find it's swarming with executables with the .exe extension. The only files in there without it are the scripts like zcat.

It's far more likely that the machine where the extensions don't seem to exist simply has extensions turned off within File Explorer. If you go into cmd and actually run dir on that directory, you'll see them.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top