Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » Eclipse Mixing C and C++(Project uses a mix of C and C++ compiled files)
Eclipse Mixing C and C++ [message #1720182] Thu, 14 January 2016 23:23 Go to next message
Coleman Moore is currently offline Coleman MooreFriend
Messages: 1
Registered: January 2016
Junior Member
I'm using Eclipse Europa with the TS-7800 embedded linux board.

I know Europa is an old release of Eclipse, but I'd prefer to use it for now.

Projects work if they are all C or all C++, but when mixing C in a C++ project, the C file is not included at link time so errors result.
The same would be the result with a C++ file not being linked in a C project.

I'd like to continue with my development and fix this for now. Later I can switch to another Eclipse version with my linux board if that works better.

Thanks,

Coleman
Re: Eclipse Mixing C and C++ [message #1720262 is a reply to message #1720182] Fri, 15 January 2016 15:40 Go to previous messageGo to next message
Marc-André Laperle is currently offline Marc-André LaperleFriend
Messages: 256
Registered: July 2009
Senior Member
A few questions

Which version of CDT are you using?
What is your host OS (Windows, Linux, etc)?
How do you build your project? Do use your own Makefiles?
Which toolchain are you using?
Can you paste the build output (Console view)?

I doubt you will get much help with such an old version of Eclipse (8 years old?). This is probably an issue that has been fixed.
I gave this a quick try; I added a test.c file to an existing C++ project and it was linked:
g++ -o "testHello" ./src/Base.o ./src/Child.o ./src/test.o ./src/testHello.o

This is using the CDT master branch (CDT 9.0)
Re: Eclipse Mixing C and C++ [message #1720263 is a reply to message #1720182] Fri, 15 January 2016 15:44 Go to previous message
David VavraFriend
Messages: 1426
Registered: October 2012
Senior Member
Did you surround the prototypes for the C code such as below?
// link to a C function
extern "C" {
void PrintHello();
}

If you don't, the linker will be looking for a mangled name despite reporting an error using the unmangled one.

EDIT:

I removed the extraneous ';' after the extern statement.
To further comment, here's the linker output without the extern "C":
Invoking: GCC C++ Linker
g++  -o "GSL_TEST"  ./src/GSL_TEST.o ./src/PrintHello.o   -lgsl -lgslcblas -lm
./src/GSL_TEST.o: In function `main':
/home/dvavra/workspaces/workspace/GSL_TEST/Debug/../src/GSL_TEST.cpp:22: undefined reference to `PrintHello()'
collect2: error: ld returned 1 exit status

Note that PrintHello.o is being linked but the linker says it can't find PrintHello() despite it being contained in PrintHello.c. Is this similar to what you are seeing?

[Updated on: Fri, 15 January 2016 16:00]

Report message to a moderator

Previous Topic:Can't debug a project using Eclipse Luna 4.4.2
Next Topic:C Element filter for a specified path
Goto Forum:
  


Current Time: Mon Sep 23 02:05:28 GMT 2024

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

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

Back to the top