Solved

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

Posted on 2013-05-14
8
470 Views
Last Modified: 2013-07-08
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.
0
Comment
Question by:pvinodp
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 32

Expert Comment

by:phoffric
ID: 39165836
Does changing main.c to main.cpp help (and fixing any C++ issues that may arise)?
0
 

Author Comment

by:pvinodp
ID: 39167175
yes that works.. but there should be some option eclipse..
I want to know that configuration.
0
 
LVL 32

Expert Comment

by:phoffric
ID: 39167820
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?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:pvinodp
ID: 39170575
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.
0
 
LVL 32

Accepted Solution

by:
phoffric earned 500 total points
ID: 39173675
Since changing .c to .cpp allows you to run properly, the problem may be in your code and not in Eclipse. You didn't mention what compilers (for both C and C++) you are using. (I'll take a WAG - gnu.) Try to compile the .c and .cpp files outside of Eclipse and see whether you are getting errors.

>> a main.c file which creates teh obj of the two classes
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?
    http://www.parashift.com/c++-faq/mixing-c-and-cpp.html
0
 

Author Comment

by:pvinodp
ID: 39173782
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.
0
 
LVL 32

Expert Comment

by:phoffric
ID: 39176553
>> 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?
    http://www.parashift.com/c++-faq/mixing-c-and-cpp.html
0
 

Author Closing Comment

by:pvinodp
ID: 39306466
Thanks
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question