Solved

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

Posted on 2013-05-14
8
457 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

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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Printing the elements of a set declared inside a map in C++. 3 59
Dialogbox API leak? 18 109
c++, dynamic object by json 1 60
FMX TEdit KeyUp handler detecting  "enter" key 4 40
When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of this video is to provide viewers with basic examples to understand opening and reading files 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.

733 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