Dr. Debasish Jana Dr. Debasish Jana - 18 days ago 6
C++ Question

User defined Extension of C++ file for g++ compilation

For some reason, I would like to use an extension

.cxy
to use as a c++ source code. Say, the filename is
abc.cxy
. But, my
g++
(4.9.2 version) is failing to compile.
I am compiling as:

g++ -o abc.oxy abc.cxy


It's complaining as:
g++: warning: conn.cxy: linker input file unused because linking not done

And, the object file
abc.oxy
is not being made.
Whereas, if I have the extension as
.cxx
, and compile as:

g++ -o abc.oxy abc.cxx


It's making
abc.oxy

Am I not allowed to use extension other than
.c, .cpp, .cxx
?

Answer

Try g++ -o abc.oxy -x c++ abc.cxy

g++ can't deduce the correct language from your custom suffix, and anything that it can't deduce as source, it passes directly to the linker as an object file.

Am I not allowed to use extension other than .c, .cpp, .cxx?

Not if you want GCC to auto deduce the source language. Conventions are in place so we won't have to be explicit, but you can still use the -x option.