ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I never knew that before (.C is treated as .cpp not as .c) but I both tested it and looked it up and you are correct.
ssvirdi, if you have some reason to want to keep the name Hello.C instead of changing it to Hello.c you could compile it with gcc -xc Hello.C
The -xc option tells gcc the type of the input file is "c". If it knows the type already, it doesn't decide the type based on the extension (the .C).
The confusing error message you got is because the gcc command invokes the linker for a .c program regardless of the type of the input file. So your .C file is compiled as a C++ module but linked as a .c program, resulting in that link time error.
That behavior must seem silly when operating on just one input file. But gcc can compile and link multiple files in one command including mixed language programs. So this behavior that seems silly with one input file makes sense for more complicated commands.
(If you aren't superuser, then you are not supposed to install new versions of gcc, but you can still follow the naming standards and use the extension .c for C-language.)
... If you aren't superuser, then you are not supposed to install new versions of gcc ...
Huh ?
I am routinely compiling from source not as 'root' user more than 370 targets and install them in a non-system directory of mt liking. Even though it's my personal machine and I have root access.
But what does it have to do with a wrong file extension in the first place ?
(If you aren't superuser, then you are not supposed to install new versions of gcc, but you can still follow the naming standards and use the extension .c for C-language.)
But if you are superuser, you should still change it to ".c" instead of ".C", because ".C" is the wrong extension for C code.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.