Solved

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

Posted on 2013-05-14
8
449 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
  • 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
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…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

839 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