I am trying to get started with programming in C++ with the Eclipse Galileo IDE. I havnt had much luck with using it as more than a glorified text editor thus far. I really enjoyed using Eclipse Ganymede for Java in the past.
I am using OS X 10.5 Leopard. Eclipse reports that it is using "MacOSX GCC" toolchain.
What I would like to do is create a new project, supply source .h and .cpp files and also a makefile that I've written. I have had little luck getting to the finished binary stage. I am aware of the process that goes into compiling and linking a c++ program as I have done this process with a makefile utilizing g++ previously.
I'm not sure what Eclipse wants me to do, and I've scoured the web searching for a tutorial that has up to date information.
Say I have the following files and I'd like them to compile and link into a binary:
(foo.cpp)
class foo{
public:
foo(){
x = 5;
}//end constructor function
private:
int x;
};
(runfoo.cpp)
#include "foo.cpp"
#include <iostream>
using namespace std;
int main(){
foo youFoo();
cout << youFoo.x <<endl;
return 0;
}
Then using the makefile I wrote:
FooApplication: foo.o runfoo.o
g++ foo.o runfoo.o -o FooApplication
foo.o: foo.cpp
g++ -c foo.cpp
runfoo.o: runfoo.cpp
g++ -c runfoo.cpp
I have tried to use the new project wizard. When I use an executable type, I have only had luck with their supplied "Hello World" example. Making an empty project and then importing source files does not work. I believe I am not familiar with the process eclipse wants me to go through to "build" and "create a binary."
I am still learning c++, so I have tried to keep my example very minimal so as hopefully not to embarrass myself. I would really appreciate any advice from anyone who understands the steps i'm missing!
Hi isthan, well i'm also learning c++ but I had a similar problem...but I'm using Windows OS
anyway I write the steps I follow:
This are the steps for Executable Projects
File >> New >> C++Project
Write the Project Name
Then select Empty Project and a ToolChain
Choose Debug and Release
Click on Advanced Settings
C/C++ Build >> Settings >> ErrorParsers
Select
CDT GNU C/C++ Error Parser
CDT GNU Linker Error Parser
CDT GNU Make Error Parser
CDT GNU Assembler Error Parser
Click Apply >> OK >> Finish
To add a new source (.cpp) file the project:
Select the project (Project Explorer), then New >> Source File
To add a Header File (.h) select the project, New >> Header File
Enjoy it!
PS: In your runFoo.cpp are you sure you can access to x ....it isn't private? To access to "x" you should
create a function
and I think your parenthesis in your youFoo object are not necessary...and would be better if you put
your class in two files(.h and .cpp) Eclipse can`t create the Binaries without foo.h