SUBMIT A FILE TYPE CONTACT US SUPPORT ABOUT US
How To tutorial

CXX vs CPP File: What Is the Difference?

A CXX file and a CPP file are the same kind of file. Both hold C++ source code and both GCC and Microsoft treat them as C++. Tools and project rules decide which ending you use.

By Neeraj Singh 4 min Published November 2026 Updated November 2026
On this page
  1. Is a CXX File Different From a CPP File?
  2. How Do GCC and Microsoft Treat CXX and CPP Files?
  3. Where Do the Two Endings Behave Differently?
  4. Should You Use CXX or CPP?
  5. Which Other File Endings Does C++ Use?
  6. How to Build a CXX File
  7. How to Open a CXX File
  8. What We Checked and What We Left Out
  9. Frequently Asked Questions
Quick Summary
  • CXX and CPP files both contain C++ source code.
  • GCC and the Microsoft compiler both treat .cxx and .cpp as C++ by default.
  • GNU Make has a implicit rule for .cpp and none for .cxx in our test.
  • Choose one ending for a project and use it everywhere.

Is a CXX File Different From a CPP File?

No. A CXX file and a CPP file both contain C++ source code as text. The ending only tells tools which language rules to use.

The GCC manual lists seven endings for C++ source, among them .cc, .cxx, .cpp and .c++. Wikipedia lists the same family in its C++ article.

Our CXX file guide explains the format and the tests behind this post.

How Do GCC and Microsoft Treat CXX and CPP Files?

Both compilers treat a CXX file and a CPP file as C++.

ToolTreats .cpp as C++Treats .cxx as C++
GCCYesYes
Microsoft CLYes, by defaultYes, by default
GNU Make (our test)Implicit ruleNo implicit rule

The GCC manual lists .cxx and .cpp as C++ source suffixes. Microsoft states that CL treats files with a .cpp or .cxx extension as C++ source files by default. See the GCC overall options page and the Microsoft CL page.

Where Do the Two Endings Behave Differently?

The CXX vs CPP difference lies in the tools around the compiler and not in the code.

  • GNU Make. In our test on GNU Make 4.3, a file named with .cpp built with the implicit rule. A file named with .cxx did not so you need your own rule.
  • Capital letters. GCC treats .C as C++ and .c as C so case matters there. In our test GCC ignored a file named .CXX.
  • Linking. Executing gcc on a .cxx file compiled it and the link step failed until we used g++ or added the C++ library. The GCC manual says only g++ links the C++ library automatically.

The test notes are on our CXX page. They used GCC 13.3.0, Clang 18.1.3 and GNU Make 4.3 on Linux.

Should You Use CXX or CPP?

Use the ending your project already uses for every CXX file and CPP file. Mixed endings in one project confuse build rules, search patterns and new team members.

For a new project, .cpp is the safer choice because GNU Make knows it without extra rules. Choose .cxx when your build system or a library asks for it. Some projects require it. The VTK module system prefers .cxx according to the ParaView community.

Headers follow the same idea. The GCC manual lists .hh, .hpp, .hxx and others so match the family of your sources.

Which Other File Endings Does C++ Use?

CXX and CPP are two of several endings. The GCC manual treats every ending in the first row as C++ source and every ending in the second row as a C++ header.

KindEndings in the GCC manual
C++ source.cc, .cp, .cxx, .cpp, .CPP, .c++ and .C
C++ header.hh, .H, .hp, .hxx, .hpp, .HPP, .h++ and .tcc

The G++ page adds that GCC compiles these names as C++ even when you call it as gcc. Only g++ links the C++ library for you.

Choose the source ending first and match the header ending to it. A CXX file pairs with .hxx and a CPP file pairs with .hpp or .h.

How to Build a CXX File

Building a CXX file takes four steps and the same steps build a CPP file. We tested them on Linux with GCC 13.3.0.

  1. Open a Terminal

    Open a terminal and go to the folder with your file.

  2. Compile With g++

    Enter g++ prog.cxx -o prog. The g++ command compiles the file as C++ and links the C++ library.

  3. Execute the Program

    Enter ./prog to execute the result.

  4. Check the Link Step

    If you used gcc and not g++, the link step fails. Switch to g++ or add the C++ library to the command.

Microsoft states that its CL compiler treats .cxx as C++ by default. We did not test Windows so match the commands to your own compiler.

How to Open a CXX File

A text editor opens a CXX file because a CXX file is text. Visual Studio Code, Visual Studio, Eclipse, Code::Blocks and Xcode also open it.

To build the file, use a C++ compiler. The command g++ prog.cxx -o prog worked in our test.

If the file looks like random symbols, it is not source code. Our guide shows how to check the first bytes before you build.

What We Checked and What We Left Out

Compiler facts come from the GCC manual, the G++ page and the Microsoft CL page. The extension list also appears on Wikipedia.

The Make, link and case results come from our own tests on Linux. We did not test Windows, macOS or the Microsoft compiler. We left out the story that the x in .cxx is a rotated plus sign because we found no source for it.

Frequently Asked Questions

Is a CXX file the same as a CPP file?

Yes in content. Both contain C++ source code as text and GCC and the Microsoft compiler both treat them as C++. The difference is in tool support.

Which is better, CXX or CPP?

Neither is better. Use the ending your project already uses. For a new project, .cpp works with GNU Make's implicit rule and .cxx needs your own rule.

Does GCC compile a CXX file?

Yes. The GCC manual lists .cxx among its C++ source suffixes. Use g++ to link a CXX file, because gcc alone left the link step failing in our test.

Does GNU Make build a CXX file?

Not with its implicit rule in our test. GNU Make 4.3 built a .cpp file with the implicit rule and needed your own rule for .cxx.

How do I open a CXX file?

Open it in a text editor or an editor like Visual Studio Code. The file is text so any editor shows the code.

Can I rename a CXX file to CPP?

Yes. The two endings contain the same kind of code and GCC and the Microsoft compiler open both as C++. Update your build rules and any include lists after the rename.

Does the Microsoft compiler treat CXX files as C++?

Yes. Microsoft states that CL treats files with a .cpp or .cxx extension as C++ source files by default.

Neeraj Singh

Neeraj Singh
Manager, Tech Support & Operations, with 19+ years of experience fixing Windows and system errors.

More Tech Tutorials

Still Stuck on This Problem?

Share your error with our team. We research the problem, test the steps and add a guide.