Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2013-05-14
8
Medium Priority
?
481 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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 2000 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

715 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