Author Topic: Project building problem  (Read 3504 times)

Offline ishu161

  • Multiple posting newcomer
  • *
  • Posts: 12
Project building problem
« on: January 17, 2011, 08:31:33 pm »
Okay, so I created a new project.I created 2 files in it. The first one, ran well and good. The second one's code has no errors, and it compiles alright. But when I try to run it, it switches back to the previous file and gives error.
Code of the second file:
Code
#include<iostream>
float temp(float);
int main()
{
    using namespace std;
    float celsius;
    cout<<"Enter the temperature in celsius: ";
    cin>>celsius;
    cout<<celsius<<" degree celsius is equal to "<< temp(celsius) << " degree fahrenheit.";
    return 0;
    }
float celsius(float a)
{
    return 1.8*a + 32.0;
}


Build Log after I run it. (No error in compiling it)

Code
-------------- Build: Debug in Learning C++ ---------------

Linking console executable: bin\Debug\Learning C++.exe
obj\Debug\stone_lb.o: In function `main':
D:/Documents and Settings/Manish/My Documents/CodeBlocks/Learning/Project_Learning/Learning C++/stone_lb.cpp:4: multiple definition of `main'
obj\Debug\temp_convrt.o:D:/Documents and Settings/Manish/My Documents/CodeBlocks/Learning/Project_Learning/Learning C++/temp_convrt.cpp:4: first defined here
obj\Debug\temp_convrt.o:temp_convrt.cpp:(.text+0x3e): undefined reference to `temp(float)'
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 0 seconds)
3 errors, 0 warnings
 

Why is it trying to link this new file to the previous one. The build message is saying that I have 'multiple definitions of main()' I'm assuming that because they are in the same project, C::B is trying to compile and run them together or something?
When this happened a few hours back, the second file was compiling without errors, but the O/P was of the file. I restarted, and then the above mentioned problem started. I've searched and found an old thread with the same problem, but no solution.

Again, don't think there's any problem with the code. Earlier I simply used to open empty files. Now I started putting them in a project and this happens.

Any help is appreciated.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Project building problem
« Reply #1 on: January 17, 2011, 10:42:50 pm »
The projects are made so you can have projects that comprise multiple files.
This is useful for larger projects, where there are many functions, structs, classes and types.

If you want to build to separate executables use multiple targets or multiple projects.
« Last Edit: January 18, 2011, 04:15:45 pm by oBFusCATed »
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline ishu161

  • Multiple posting newcomer
  • *
  • Posts: 12
Re: Project building problem
« Reply #2 on: January 18, 2011, 02:02:45 pm »
Thanks for helping me out. I suspected it was something like that, but couldn't find the proper answer anywhere. Rookie mistake.