Link to home
Create AccountLog in
Avatar of pvinodp

asked on

I cannot build a eclipse C++ project as teh main function is in c file

I have 5 files in my eclipse c++ proj:
A.h , A.cpp , B.h,  B.cpp  and main.c

Build it is building  c instead of C++..
So  I get this error:
/A.h:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘A’
In file included from ../main.c:1:
../B.h:13: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘B’

What settings would I have to change in eclipse for this ? I tried to change the make manually  file but it does not help.
Avatar of phoffric

Does changing main.c to main.cpp help (and fixing any C++ issues that may arise)?
Avatar of pvinodp


yes that works.. but there should be some option eclipse..
I want to know that configuration.
It may help to know your OS, Eclipse version, and C/C++ compiler Eclipse is using.
It may help if you post the simplest example of your 5 files.

Are you able to build outside of Eclipse the mixed C/C++ project from a command line without problems?
Avatar of pvinodp


I am running it on centos 5.5
eclipse version : Eclipse IDE for C/C++ Developers
                           Version: Helios Release
I did not try to build outside eclispe.

I have 5 simple files: ClassA containing a constructor and destructor and printA() function.
Same with ClassB .
And a main.c file which creates teh obj of the two classes and calls teh function printA() respectively.
Avatar of phoffric

Link to home
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of pvinodp


I am not aware how eclipse is building the code internally.
I run eclipse on a centos system and the eclipse version is Helios Release.

I usually have all files in .cpp and everything was fine. But in this project there is a combination of c and c++  files. ANd the main function is in a c file. THats is what is causig the problem.
>> the eclipse version is Helios Release
Yep, you said that earlier. I will guess that you are using gnu compiler/linker.
FYI - Eclipse does not come with a compiler.

>> ANd the main function is in a c file. THats is what is causig the problem.
Yep, you said that earlier.

Not sure how you are doing this since C language doesn't know about C++ classes. Mixing C and C++ can be done. Are you following the directions in this link?
Avatar of pvinodp