Iam a beginner to learn c programing, use eclipse cdt in linux.
now i create a project and helloworld.cpp, debug successed.
but when i do the next exercise, create a new file.cpp, it cannot compile because of multi- main function defined(yeah, i donot delet the helloworld.cpp)
i need some help, how can i to select the new file to compile, because i want to do more exercise, i must create different cpp files in a project(i donot want to create new project, one exercise one project is too tired!)
who can help me? thx a lot.
You can right-click the file you want to ignore (not build) on the left side (Project Explorer).
Resource Configurations
-> Exclude from Build...
After this just select the configurations (Debug, Release) which should ignore this file.
This should fix your problem.
Alternativ you can try something which might help you to improve yourself in c/c++. You can try to write functions for every new exercise you start and include it into your first helloworld.cpp.
Example:
Source:
simpleMath.c
#include"simpleMath.h"
int addition(int val1, int val2)
{
return (val1 + val2);
}
int substraction (int val1, int val2)
{
return (val1 - val2);
}
Header:
simpleMath.h
int addition(int val1, int val2); //Prototype
int substraction (int val1, int val2); //Prototype
Main:
helloworld.c
#include"simpleMath.h"
int main()
{
//some code
int newVar = 0;
newVar = addition(5, 10) //Function call -> newVar will be 15
//some code
}
The example is simple c code (not c++) and is just for visualisation. If you want to do it with c++ you can try to implement every new excercise as a so called "class".