What Is a CXX File? How to Open, Compile and Fix C++ Source
A CXX file is C++ source code saved as text. Jump to your question below, or work through it in order.
What Is a CXX File? C++ source code, and a name some tools do not know
Short answer
CXX files are C++ source code: text that compilers read to build programs. The ending is only a label, and every tool decides for itself what that label means.
GCC lists .cxx among its C++ endings, and so does Microsoft. But our tests found that GCC built our .cxx file and could not link it, and GNU make had no built-in rule for it. A capital .CXX file built in Clang and was ignored by GCC.
We tried 17 endings in four compilers, plus GNU make, CMake and Chromium. If your CXX file will not build, read what the compiler tests showed before you edit any code.
CXX files are C++ source code saved as text. Compilers read them and build programs, and the .cxx ending only shows your tools which language rules to use.
Picture a folder from an open source project. Next to main.cpp is viewer.cxx. Double-clicking it opens the wrong program or nothing at all, and your build says it has no rule for the CXX file. Most CXX file questions start right there.
C++ is the language. Bjarne Stroustrup created it, and it was first released in 1985, says Wikipedia. The .cxx ending is one of several names programmers give to its source files. The GCC manual lists seven for C++: .cc, .cp, .cxx, .cpp, .CPP, .c++ and .C.
Microsoft agrees on the idea. Its compiler treats .c files as C and .cpp and .cxx files as C++ by default, says Microsoft Learn.
FileInfo calls the type a C++ Source Code File and lists no other meaning. FILExt gives the media type text/x-c++src and files it mostly under Eclipse. Neither page gives counts, so we could not check how many .cxx files in the wild are something else.
CXX file facts at a glance
| Property | Value |
|---|---|
| File extension | .cxx |
| Type | C++ source code, saved as text |
| Language | C++, first released in 1985 |
| Made by | Programmers, in text editors or development environments |
| Contains | Include lines, functions, classes and statements |
| Opens in | Any text editor, plus development environments and a browser tab |
| Builds with | A C++ compiler: GCC, Clang or Microsoft cl |
| Media type | text/x-c++src, says FILExt |
| Related endings | .cpp, .cc, .C, .c++ and the header ending .hxx |
| Other meaning | None found by FileInfo. See the section on other meanings. |
Wrong page? Programs that end in .exe are in the EXE program file guide. Object files from a build are in the ELF file guide.
Which Kind of File Is Your CXX File? Read the first bytes before you read the code
Real CXX files are readable text. Read the first bytes: words like #include mean source code. The bytes 7f 45 4c 46, 4d 5a or 50 4b 03 04 mean an ELF file, a Windows program or a ZIP archive with the wrong name.
You do not need a compiler for this. The short script below prints one line. Save it as check_cxx.py and replace prog.cxx with your CXX file name.
import sys
KINDS = {b"\x7fELF": "an ELF program or object file", b"MZ": "a Windows program or object file",
b"PK\x03\x04": "a ZIP archive", b"%PDF": "a PDF file", b"\x89PNG": "a PNG picture"}
BOMS = {b"\xef\xbb\xbf": "UTF-8 with BOM", b"\xff\xfe": "UTF-16 (compilers refuse it)",
b"\xfe\xff": "UTF-16 (compilers refuse it)"}
data = open(sys.argv[1], "rb").read()
for sig, name in KINDS.items():
if data.startswith(sig):
sys.exit("Not source code: this is " + name + ". First bytes: " + data[:4].hex(" "))
bom = next((n for b, n in BOMS.items() if data.startswith(b)), "")
if b"\x00" in data and not bom.startswith("UTF-16"):
sys.exit("Not plain text: it contains null bytes")
text = data.decode("utf-16" if bom.startswith("UTF-16") else "utf-8-sig", errors="replace")
HINTS = ["#include", "int main", "std::", "namespace", "template", "class ", "struct "]
found = [h for h in HINTS if h in text]
print("Text,", bom or "UTF-8 or ASCII", "-", len(text.splitlines()), "lines -",
("looks like C or C++ (found " + ", ".join(found) + ")") if found else "no C++ keywords found")
python check_cxx.py prog.cxx
Text, UTF-8 or ASCII - 8 lines - looks like C or C++ (found #include, int main, std::)
We tried the script on 14 test files. It spotted the object file, the ZIP header, the Windows program header and both files with null bytes. It told us when a text file had no C++ words in it. It cannot say whether text is C or C++, and it did not name our HTML file as HTML. The table shows what it and the compilers made of the files that matter most.
| Kind | First bytes or sign | What happened in our test |
|---|---|---|
| Ordinary C++ source |
Readable text with #include
|
g++ and clang++ compiled it |
| UTF-8 with a BOM |
ef bb bf, then text
|
g++ and clang++ compiled it |
| Windows line ends |
Text with 0d 0a at every line end
|
g++ and clang++ compiled it. The CXX file grew by 8 bytes, one for every line. |
| UTF-16 text |
ff fe at the start
|
g++ and clang++ both refused it |
| An object file renamed |
7f 45 4c 46
|
g++ stopped at the first byte. Read about these in the ELF object file page. |
| A ZIP archive renamed |
50 4b 03 04
|
The script named it. An unzip program opens it, as in the ZIP file guide. |
| Null bytes inside |
A 00 byte in the text
|
Both compilers warned "null character ignored" and went on |
Three more clues besides the bytes
file command, version 5.45 in our test, read our hello program by its content and printed "C source". It printed "C++ source" for a header-only class file, and "ELF 64-bit" for the renamed object file.
ef bb bf for UTF-8 and ff fe for UTF-16. Our UTF-8 file with BOM bytes built. Our UTF-16 file did not.
What Is Inside a CXX File? Eight lines of text and four build steps
CXX files are lines of C++ text: include lines, a main function and statements that end in semicolons. Compilers read them in stages, and our 153-byte example grew to 907,768 bytes before the compiler even began.
Think of a recipe card. The first lines name the other cards you need. Then come the steps, in order. Compilers follow the same idea, and the include lines point them at other files.
#include <iostream>
#include <string>
int main() {
std::string name = "CXX";
std::cout << "Hello from a " << name << " file\n";
return 0;
}
| Line | What it does |
|---|---|
#include <iostream>
|
Pulls in the standard header for printing text |
#include <string>
|
Pulls in the string type |
int main() {
|
Opens the main function, where every program starts |
std::string name = "CXX";
|
Makes a string called name and stores the word CXX in it |
std::cout << ... << "\n";
|
Prints the greeting, with the name in the middle |
return 0;
|
Reports to the system that the program finished with no error |
}
|
Closes the main function |
Build it and start it, and it prints one line: Hello from a CXX file. The text is all the compiler gets, so the file has no header, no signature and no version marker of its own.
From text to program in four steps
| Stage | Output | Size |
|---|---|---|
| Source | prog.cxx | 153 bytes |
Preprocess with g++ -E
|
prog.ii | 907,768 bytes |
Compile with g++ -c
|
prog.o | 11,096 bytes |
Link with g++ -o prog
|
prog | 19,408 bytes |
The first step pastes every header into your text, so prog.ii has 36,589 lines. The next step makes the object file prog.o, and the last makes the program prog. Clang++ made 36,271 lines and 956,150 bytes from the same file. GCC lists .ii as preprocessed C++, and compiling our prog.ii worked.
CXX files and header files
C++ programs also use header files. GCC lists .hxx among its header endings, next to .hh, .H, .hp, .hpp, .HPP, .h++ and .tcc. We made util.hxx and included it from a CXX file. It built and printed the right text.
A header is not meant to be compiled alone. When we compiled util.hxx directly, GCC only warned "#pragma once in main file". Two files named Case.cxx and case.cxx lived side by side on our Linux machine. We did not test other systems.
What Did Our Compiler Tests Show About CXX Files? Seventeen endings, four compilers and one capital letter
We tried 17 file endings in four compilers, plus GNU make, CMake and Chromium. Seven endings built everywhere and eight were ignored by all four. One capital letter split the answers.
We wrote one 8-line CXX file and copied it under 17 names. We compiled every copy with gcc, g++, clang and clang++ using the -c option, which compiles and does not link. Then we linked it, built it with make and CMake and opened it in a browser.
The versions were GCC 13.3.0, Clang 18.1.3, GNU Make 4.3, CMake 3.28.3, file 5.45, Pygments 2.21 and Chromium 141, all on one Linux machine. We did not test Microsoft cl, Visual Studio, Eclipse, Xcode, Windows or a Mac. The results show how these tools behave, not how common any case is.
How the four compilers read 17 endings
| Ending | gcc | g++ | clang | clang++ |
|---|---|---|---|---|
| .cxx, .cpp, .cc, .C | Built | Built | Built | Built |
| .cp, .c++, .CPP | Built | Built | Built | Built |
| .CXX | Ignored | Ignored | Built | Built |
| .c | Failed | Built | Failed | Built |
| .Cxx, .cXX, .cx | Ignored | Ignored | Ignored | Ignored |
| .cxxx, .ixx, .txt | Ignored | Ignored | Ignored | Ignored |
| .cxx.txt, no ending | Ignored | Ignored | Ignored | Ignored |
Built means the compiler made an object file. Failed means gcc and clang stopped at the iostream include, because the .c ending switches on the C rules. In the .c row, g++ and clang++ built the file as C++. Ignored means it printed a warning, exited with code 0 and made no object file. The warning said "linker input file unused because linking not done" in GCC and "linker input unused" in Clang.
The GCC manual explains the .CXX result. It says the last two letters of .cxx must both be a lowercase x. It hands any ending it does not know to the linker, and with -c the linker never starts. A build script that checks only the exit code will report success for files that were never compiled.
One command builds a CXX file and another cannot link it
| Command | Compile | Link | Result |
|---|---|---|---|
gcc prog.cxx
|
Built as C++ | Failed | 17 undefined references, including std::cout |
clang prog.cxx
|
Built as C++ | Failed | 19 undefined references |
g++ prog.cxx -o prog
|
Built | Linked | Printed "Hello from a CXX file" |
clang++ prog.cxx -o prog
|
Built | Linked | Printed "Hello from a CXX file" |
gcc prog.cxx -lstdc++
|
Built | Linked | Printed "Hello from a CXX file" |
clang prog.cxx -lstdc++
|
Built | Linked | Printed "Hello from a CXX file" |
The .cxx ending told gcc and clang to treat the CXX file as C++, so the compile step worked. But they do not add the C++ library when they link. The fix is g++ or clang++, or the -lstdc++ option.
C code in a CXX file
The ending also switches on the C++ rules. The line int *p = malloc(4 * sizeof(int)); built in .c files with gcc and with clang. In .cxx files both refused it. GCC said "invalid conversion from void* to int*", and Clang said it cannot initialize an int pointer with a void pointer.
The language standard decides what builds
Both g++ 13.3 and clang++ 18.1 start in C++17 mode, which showed as 201703L in the built-in __cplusplus value. A CXX file that uses std::integral failed by default and with -std=c++17. It built with -std=c++20. GCC said "std::integral has not been declared", and Clang said "use of undeclared identifier std".
What make, CMake and Pygments know
GNU make has built-in rules that build prog.cpp into a program without a makefile. We put the same file under six endings and typed make prog with LDLIBS set to -lstdc++.
| Ending | make prog |
|---|---|
| .cpp |
Built with g++ prog.cpp -lstdc++ -o prog
|
| .cc | Built with g++ |
| .C | Built with g++ |
| .cxx | No rule to make target prog |
| .c++ | No rule to make target prog |
| .cp | No rule to make target prog |
The GNU make catalog of rules names .cc, .cpp and .C for C++ and advises .cc or .cpp over .C. It does not name .cxx. Four fixes worked in our test, and the ways to fix make list them.
CMake 3.28.3 knows more. Its list of C++ source endings includes cxx, cpp, cc, c++ and C. A project with main.cxx built and printed the greeting. A project with main.CXX failed with "CMake can not determine linker language for target".
Pygments 2.21, the code colorer behind many docs sites, colored files ending in .cxx, .cpp, .cc, .C, .c++ and .hxx as C++. It had no lexer for .CXX.
What a browser does with a CXX file
We served the CXX file from a local web server to Chromium 141. It showed the text when we opened it from disk, when the server sent text/plain, when it sent text/x-c++src and when it sent no type at all. It downloaded the CXX file when the server sent application/octet-stream.
Which file contents compiled
| Content | Size | g++ | clang++ |
|---|---|---|---|
| UTF-8 | 153 bytes | Built | Built |
| UTF-8 with a BOM | 156 bytes | Built | Built |
| Windows line ends | 161 bytes | Built | Built |
| Old Mac line ends | 153 bytes | Built | Built |
| A Latin-1 comment | 169 bytes | Built | Built |
| UTF-8 accents | 154 bytes | Built | Built |
| One null byte inside | 154 bytes | Built with a warning | Built with a warning |
| UTF-16 with a BOM | 308 bytes | Failed, stray byte | Failed, UTF-16 |
| UTF-16 without a BOM | 306 bytes | Failed, nulls | Failed, nulls |
What the results say about CXX files
Read the results with care. These results come from one Linux machine, one set of tool versions and one small file. Real CXX files from big projects may behave differently. We did not test Microsoft cl or any program on Windows or Mac.
Repeat the check on your own file
The first bytes script reads any file you give it. The compile commands show how to build a CXX file in four ways.
What Does Our Expert Say About CXX Files? A note from Neeraj Singh on which tool reads the ending
Check which tool is reading the ending, then check the command, then check the code. The same CXX file built in one tool and was ignored by another.
Expert insight
“Most CXX problems are not about the code. The ending, the command or the build tool applies the wrong rules. In our test, GCC compiled a .cxx file but could not link it, and GNU make had no rule for it. So before you edit the code, check which tool is reading the ending.”
What one error cannot show
A build error names the first thing that failed, not the cause. Our gcc link error listed std::cout, and the code was fine. The fix was to call g++.
So the first move costs nothing. Compile with g++ and read the first error. If the CXX file builds there, the CXX file is fine and your build setup is the problem.
Keep the original. If you rename CXX files to make tools happy, work on copies. The steps to rename a CXX file show the safe way.
How Do You Open a CXX File? A text editor, a browser tab or a terminal
Open CXX files in any text editor. They are text, so code editors, browser tabs and terminals show them. To build one you also need a C++ compiler.
Double-click the CXX file first. If nothing happens or the wrong program starts, use one of the routes below. The first bytes check shows whether the CXX file is text at all.
Open CXX files in a text editor
- Right-click the CXX file and choose Open with.
- Select a text editor or code editor. Any program that reads text will do.
-
Look at the top of the CXX file. Lines that start with
#includemean C++ source code. - If you see unreadable symbols, read the causes that stop a build.
Open CXX files in a browser tab
Drag the CXX file into a Chrome or Edge tab. Both use the Chromium engine, and we tested Chromium 141 itself. It showed our CXX file as text when we opened it from disk, and when a server sent text/plain, text/x-c++src or no type. It downloaded the CXX file when the server sent application/octet-stream.
Open CXX files from the command line
On Linux the file command names the type of a file by its content. In our test it called the hello program "C source", even though it is C++. Use head or less to read the first lines.
file prog.cxx
prog.cxx: C source, ASCII text
Programs that open CXX files
FileInfo also lists File Viewer Plus, FileHelper.com and File Viewer for Android as viewers. The file-extensions.org page for .cxx adds Windows Notepad, TextEdit, gedit, GNU Emacs, Sublime Text and Notepad++. We did not test any of them. We tested Clang 18.1.3 too, which FileInfo does not list, and it built our CXX file as well.
Why Will a CXX File Not Compile? Six causes, and only two of them blame the file
When a CXX file will not build, check the contents, the ending, the build rule, the link step, the language standard and the language itself. Only two of those six blame the CXX file.
Most failures are mismatches. The code is fine, and the tool does not fit it. Work through six checks before you edit a line. The red ones are the two where the CXX file or its code must change.
-x c++. See the ending results.
-lstdc++. See the link results.
std::integral failed until we added -std=c++20. See the standard results.
int *p = malloc(4 * sizeof(int)); built as .c and failed as .cxx. Fix the cast or give the CXX file a .c ending. See the C code results.
A six-step check
- Read the first bytes with the Python script. If the CXX file is not text, stop here.
- Show file extensions and confirm the ending is a lowercase .cxx. A capital .CXX is ignored by GCC.
-
Compile with
g++ -c prog.cxxand read the first error line. -
Link with
g++ prog.cxx -o prog, not with gcc. -
If the error names a C++20 feature, add
-std=c++20. - If the build is make or CMake, check that the tool knows .cxx. Then follow the make fixes.
Four ways to make GNU make build a CXX file
Typing make prog with only prog.cxx in the folder failed in GNU Make 4.3. All four fixes below worked in our test. The pattern rule is the shortest, because one line covers every CXX file in the folder.
CXX = g++
CXXFLAGS = -Wall
%: %.cxx
$(CXX) $(CXXFLAGS) $< -o $@
prog: prog.cxx
g++ prog.cxx -o prog
.SUFFIXES: .cxx
.cxx.o:
$(CXX) $(CXXFLAGS) -c $< -o $@
prog: prog.o
$(CXX) $^ -o $@
Fix 4 is a copy: save prog.cxx as prog.cpp and let the built-in rule find it. Make has no rule for .cxx because its list of C and C++ endings has .c, .cc, .C and .cpp.
Test with a second tool. Compilers and build tools word the same problem differently. A CXX file that fails in one should go through g++ before you give up on it.
How Do You Compile or Rename a CXX File? Four commands that worked in our test
Compile a CXX file with g++ or clang++. Both built our test CXX file and printed its greeting. To use a tool that does not know .cxx, copy the CXX file to .cpp or name the language with -x c++.
A compiler compiles. It reads the CXX file and writes an object file or a program, and your source stays as it was. Choose the route by what you need next.
| You want | Route | Status |
|---|---|---|
| A program |
g++ prog.cxx -o prog or clang++
|
Tested, both worked |
| An object file |
g++ -c prog.cxx
|
Tested, both worked |
| A .cpp copy that make knows |
cp prog.cxx prog.cpp
|
Tested, make built it |
| A file with an odd ending |
g++ -x c++ -c file
|
Tested, worked |
| A build with Microsoft cl |
cl /TP prog.cxx
|
Not tested |
| A desktop converter | We found no SysTools or Freeviewer tool for C++ source | Not available |
Compile a CXX file to a program
- Install a C++ compiler. GCC and Clang are free.
- Open a terminal in the folder with the CXX file.
- Enter one command from the box below. Replace prog.cxx with your CXX file name.
- Start the program and read what it prints.
g++ prog.cxx -o prog
clang++ prog.cxx -o prog
./prog
Hello from a CXX file
Add -std=c++20 if the code needs a newer standard. Add -Wall to see more warnings. Both compilers made a working program from our CXX file with no warning.
Rename a CXX file to CPP
Renaming changes only the label. The text inside stays the same. Copy the CXX file first, so the original stays safe, then give the copy the ending your tool knows.
cp prog.cxx prog.cpp
make prog
In our test, make built prog from prog.cpp with its built-in rule once LDLIBS was set to -lstdc++. The copy cost nothing. The better long-term fix is a rule for .cxx, as in the pattern rule.
Compile a file with an odd ending
Compilers read the ending to choose the language. The -x option overrides that. With -x c++, gcc compiled a .txt file and g++ compiled a file with no ending. Clang compiled the .txt file too. Without it, gcc and g++ only warned and made nothing.
g++ -x c++ -c note.txt
g++ -c note.txt
g++: warning: note.txt: linker input file unused because linking not done
Put -x before the CXX file. At the link step the option does not rescue the CXX file: g++ note.txt failed with "syntax error", because the linker took the text for a linker script. Compile with -c first.
Compile with Microsoft cl
Microsoft says its cl compiler treats .cpp and .cxx files as C++ by default, and that /TP forces C++ for any ending. Its documentation of source file types compiles a file named TEST2.CXX as C++ with /TP. We did not test cl or any Windows setup.
Why there is no converter on this page
SysTools and Freeviewer make tools for mail, databases, backups and viewers. Neither lists a product for C++ source, so this page has no tool card. CXX files need a compiler, and compilers are free.
Be careful with upload sites. Online converters receive your code. For private or work source files, compile on your own computer.
Why Does a Small CXX File Give a Big Program? 153 bytes of text, 19,408 bytes of program
A CXX file is small text, and the program built from it is far bigger. Our 153-byte file gave an 11,096-byte object file, a 19,408-byte program, 100,240 bytes with debug data and 2,341,376 bytes linked statically.
Think of an order slip and the meal it brings. The slip is a few lines. The meal needs a kitchen. Programs need the library code your include lines point at, and the build adds it.
Output sizes from one 153-byte file
| Output | Made with | Size |
|---|---|---|
| The CXX file | You write it | 153 bytes |
| Preprocessed text, g++ |
g++ -E
|
907,768 bytes |
| Preprocessed text, clang++ |
clang++ -E
|
956,150 bytes |
| Object file, g++ |
g++ -c
|
11,096 bytes |
| Object file, clang++ |
clang++ -c
|
9,040 bytes |
| Object file with optimization |
g++ -O2 -c
|
3,296 bytes |
| Object file with debug data |
g++ -g -c
|
100,240 bytes |
| Program, g++ |
g++
|
19,408 bytes |
| Program, clang++ |
clang++
|
18,912 bytes |
| Program with symbols removed | g++ then stripped | 14,568 bytes |
| Program linked statically |
g++ -static
|
2,341,376 bytes |
The numbers come from GCC 13.3.0 and Clang 18.1.3 on Linux. Your sizes will differ with other versions and systems, but the order stays the same. Debug data and static linking make the biggest jumps.
How to make the output smaller
Optimizing with -O2 cut our object file from 11,096 to 3,296 bytes. Stripping the program removed 4,840 bytes, from 19,408 to 14,568. Skip -g and -static unless you need them. The CXX file itself is tiny, so the savings are in the build.
Is It Safe To Open a CXX File? Reading is safe, and the care starts at the build
CXX files are text, so opening one in an editor is safe. Building it and starting the result is not: source code can do anything a program can. Read the CXX file before you build it.
The CXX file does nothing while you read it. The risk starts when you build it and start the program. We did not test any editor or compiler for security flaws, so keep them updated.
What can go wrong
7f 45 4c 46. Read the guide to Windows programs for the other kind.
A safety check before you build
- Show file extensions. A name that ends in .exe or .zip is not source code.
- Check the source. A file from your own project is expected. One in an unexpected message needs care.
- Read the first bytes. That step is safe, because nothing starts.
-
Open the CXX file in a text editor and read it. Search for
system,execandpopen, which start other programs. - Build unknown code in a folder you can delete, or in a virtual machine.
- Do not upload private source to websites. Compile it on your own computer.
Safe to read, careful to build. Reading a CXX file is safe, and so is checking its first bytes. The care starts when you build and start the program.
How Does a CXX File Differ From CPP, CC and C Files? Same language, different labels
CXX, CPP, CC and C++ endings all mean C++ source code. The .c ending means C, and .hxx marks a header. The real difference is how your tools treat the label.
The same program can be saved under any of the C++ endings. The text inside does not change. The table shows what every ending means and what happened to it in our tests.
| Ending | What it means | Our results |
|---|---|---|
| .cxx | C++ source | Built in all four compilers. GNU Make 4.3 had no built-in rule. |
| .cpp | C++ source | Built in all four compilers. GNU Make 4.3 built it. Microsoft treats it as C++ by default. |
| .cc | C++ source | Built in all four compilers. GNU Make 4.3 built it. |
| .C | C++ source, with a capital C | Built in all four compilers. GNU Make 4.3 built it, though the make manual advises .cc or .cpp. |
| .c++ and .cp | C++ source | Built in all four compilers. GNU Make 4.3 had no built-in rule. |
| .c | C source | gcc and clang used C rules and failed on iostream. g++ and clang++ built it as C++. |
| .hxx | A C++ header | Included from a CXX file with no problem. Compiled alone, it only warned. |
In our tests the .cpp ending was the one every tool knew. That makes it the easy choice for a new project. Some projects choose .cxx on purpose.
A ParaView forum thread on VTK modules shows why. A Kitware developer wrote in March 2025 that the VTK module system prefers .cxx as its source ending, so projects that list classes there need .cxx files.
If you meet CXX files, you can treat them as CPP files with a rarer label. Rename a copy if your tool refuses one, and leave the original alone.
Wrong page? Programs that end in .exe are in the Windows executable page. Qt resource files that end in .qrc are in the Qt resource collection page.
What Else Does the CXX Ending Mean? Nothing else we could confirm
Three directories give the .cxx ending one meaning: C++ source code. We found no other confirmed use, but any file can have any name, so check the bytes.
If your .cxx file does not look like code, the label may be wrong. The table shows what every source says about the ending.
| Source | What it says | Other meanings listed |
|---|---|---|
| FileInfo | Names the type C++ Source Code File. Updated 10 March 2023. | None |
| FILExt | Names the type CXX File, gives the media type text/x-c++src and says it mostly belongs to Eclipse. | None |
| file-extensions.org | Calls it the C++ main source code file format and says it is much like .cpp. Updated 31 December 2024. | None |
| GCC manual | Lists .cxx as one of seven C++ source endings | Not a directory |
| Microsoft Learn | Says .cpp and .cxx files are C++ by default | Not a directory |
| Our tests | Four compilers, make, CMake and Chromium all treated our .cxx file as C++ text | None found |
None of the three directories gives counts, so we could not check how many .cxx files in the wild are something else. FILExt also keeps registry entries for Visual Studio, Visual C++ Express and Code::Blocks, which only show the programs that claim the ending.
Our own renamed files back up the main point. A real object file with the .cxx name stopped g++ at its first byte, 7f 45 4c 46. The script that reads the first bytes names such files before you waste time on them.
What Is the CXX File Format Made Of? The facts we could check
A CXX file is C++ text with no signature and no header. What gives it meaning is the ending, which tools match against their own lists, and the language rules that follow.
| Item | What we could check |
|---|---|
| Name | C++ Source Code File, says FileInfo |
| Language | C++, created by Bjarne Stroustrup and first released in 1985, says Wikipedia |
| Extension | .cxx, one of seven C++ endings in the GCC manual: .cc, .cp, .cxx, .cpp, .CPP, .c++ and .C |
| Signature | None. A CXX file is text and starts with whatever its author typed. |
| Encoding | Text. UTF-8 built in g++ and clang++, and UTF-16 did not. |
| Line ends | LF, CRLF and CR all built in our test |
| Structure | Free-form: include lines, declarations, functions and classes. No header and no version marker. |
| Preprocessed form | .ii, which GCC reads as preprocessed C++ |
| Header endings | .hh, .H, .hp, .hxx, .hpp, .HPP, .h++ and .tcc in the GCC manual |
| Standard | The ISO standard for C++. Wikipedia lists ISO/IEC 14882:2024, called C++23, published on 19 October 2024. |
| Media type | text/x-c++src, says FILExt |
| Specification | The ISO standard covers the language, not the .cxx ending. We did not read the standard itself. |
About the missing file signature
Binary formats start with magic bytes. CXX files do not, so programs guess from the words inside. The file command called our C++ hello program "C source" and a header-only class file "C++ source". Treat that label as a guess.
What we left out
We did not read the ISO standard or the source code of any compiler. We tested GCC 13.3.0, Clang 18.1.3, GNU Make 4.3, CMake 3.28.3, file 5.45, Pygments 2.21 and Chromium 141, all on Linux, with one 8-line program.
We did not test Microsoft cl, Visual Studio, Visual Studio Code, Eclipse, Xcode or Code::Blocks. We also did not test Windows or Mac behavior or other versions of make and CMake. Real CXX files from large projects like VTK are untested too. So we say nothing about those beyond what the cited pages state.
We could not check any count of how many .cxx files in the wild are something else, because no page we read gives one. We also did not test the SysTools or Freeviewer products, because none reads C++ source.
Sources checked
For the language and its endings, the Wikipedia entry on C++, the GCC manual on overall options and the Microsoft Learn page on source file types.
For build tools, the GNU make manual on built-in rules and the CMake variable for source endings. For the ending, the FileInfo entry for CXX files, the FILExt page and the file-extensions.org listing. Every test count came from our own tests in October 2026.
Frequently Asked Questions About CXX Files
What is a CXX file?
A CXX file is C++ source code saved as text. Compilers read it and build programs. The GCC manual lists .cxx as one of seven endings for C++.
What does CXX stand for?
CXX is a file ending that marks C++ source. It is not an official abbreviation, and we found no source that explains the name. The two x letters look like the two plus signs in C++.
How do I open a CXX file?
Open it in any text editor, or drag it into Chrome or Edge. It is text, so you need no special program to read it. To build it you need a C++ compiler like g++ or clang++.
What program opens a CXX file?
FileInfo lists Visual Studio Code, Visual Studio 2022, Eclipse IDE for C Developers, Code::Blocks, Apple Xcode and GCC. We tested only GCC 13.3.0, Clang 18.1.3 and Chromium 141, so we say nothing about the others.
Why will my CXX file not compile?
Check the contents, the ending, the build rule, the link step, the language standard and whether the code is really C. In our test, GCC ignored a .CXX file with exit code 0, and gcc built our .cxx file but could not link it. Try g++ first.
How do I compile a CXX file?
Enter g++ prog.cxx -o prog or clang++ prog.cxx -o prog, then start ./prog. Both compilers built our test CXX file and printed its greeting. Add -std=c++20 if the code needs a newer standard.
Is a CXX file the same as a CPP file?
Both contain C++ source code, and all four compilers we tried built both. The difference is in the tools. GNU Make 4.3 has a built-in rule for .cpp and none for .cxx.
Why does make say no rule to make target?
GNU Make 4.3 has built-in rules for .cc, .cpp and .C, and none for .cxx. Add a pattern rule that maps %.cxx to a g++ command, or copy the CXX file to .cpp. All four fixes we tried worked.
Can I rename a CXX file to CPP?
Yes. Both are C++ source, and renaming changes only the label. In our test, make built prog from a copy named prog.cpp. Work on copies so the original stays safe.
Is a CXX file safe to open?
Yes, in a text editor. It is text, and reading it starts nothing. The care starts when you build the CXX file and start the program, because source code can do anything a program can do.
Does the capital in .CXX matter?
It did in our test. GCC ignored our .CXX file with exit code 0 and made no object file, and Clang built it. The GCC manual says the last two letters of .cxx must both be a lowercase x.
Is every .cxx file C++ code?
It should be. FileInfo, FILExt and file-extensions.org all name C++ source as the only meaning. But any file can have any name, and our script named a renamed object file by its first bytes, 7f 45 4c 46.
Still Stuck With a CXX File? Eight routes out, depending on what went wrong
Start with the six checks. The contents, the ending and the compiler command explain most cases.
Go to the g++ commands. One copy to .cpp or one -x option often fixes it.
Is it a program that ends in .exe? The Windows EXE program guide covers it.
Is it a build output from Linux? The ELF program and library guide explains object files and programs.
Is it a Qt project file? The Qt resource file guide shows how those files work.
Did a build leave a libtool script? The Libtool archive guide explains it.
Is it a zipped folder of source code? The guide to unzip source archives shows how to open it.
Is it a file type you do not know? Browse the file extension resource library, or send it to us on the submit a file type page.