Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » Compiling C and C++ code in the same project(Combining C and C++)
Compiling C and C++ code in the same project [message #1850386] Mon, 28 February 2022 20:56 Go to next message
Matthew Gerges is currently offline Matthew GergesFriend
Messages: 2
Registered: February 2022
Junior Member
Does anyone know how to create a project where the compiler compiles c source files with GCC and C++ source files with g++? I don't really need to do it this way. All I'm trying to achieve is to have the main c file (main.c) that calls functions from other files whether they are c or c++ source files. For example, I would like to be able to include a header from a c++ source file so in my int main() I can call add(2,3) and the output would be 5 (the add function would exist in a c++ source file). However, when I try using g++ to compile the entire project, there are many build errors in the c source files. When I try using GCC to compile the project, the c++ source files are ignored. I would love to be able to convert an existing project to be compatible with both c and c++ but I'm also open to creating a new project from scratch to do this as long as I can work with both C and C++. Just in case this matters, I wanted to mention that I am using Eclipse CDT on Xilinx SDK. Thanks!
Re: Compiling C and C++ code in the same project [message #1850409 is a reply to message #1850386] Wed, 02 March 2022 05:00 Go to previous messageGo to next message
David VavraFriend
Messages: 1426
Registered: October 2012
Senior Member
Just add them to your source file directory.
If you are using Managed Build, make will sort them out.
Re: Compiling C and C++ code in the same project [message #1850488 is a reply to message #1850409] Fri, 04 March 2022 17:25 Go to previous messageGo to next message
Matthew Gerges is currently offline Matthew GergesFriend
Messages: 2
Registered: February 2022
Junior Member
I tried doing that but did not get any luck with it. What ended up working was changing the compiler commands (under properties) for the C files from g++ to gcc. Thank you for your reply!
Re: Compiling C and C++ code in the same project [message #1850493 is a reply to message #1850488] Sat, 05 March 2022 03:02 Go to previous message
David VavraFriend
Messages: 1426
Registered: October 2012
Senior Member
g++ was the compiler for C files? Odd. The default is gcc.
Previous Topic:where and how to tell eclipse to add something to moc?
Next Topic:StackOverFlowerror Recursive ProgressMonitorWrapper
Goto Forum:
  


Current Time: Thu Apr 25 22:05:24 GMT 2024

Powered by FUDForum. Page generated in 0.03277 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top