Jump to content

  • Log In with Google      Sign In   
  • Create Account


wtf???


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
26 replies to this topic

#1 StoNeD_TrOLL   Members   -  Reputation: 122

Like
Likes
Like

Posted 12 January 2002 - 05:19 AM

Im using CodeWarrior Learning Edditon.My project has two files that have no flaws(made sure).When i got to run my project i get a link error about something wrong with main in both files.Whats wrong here?

Sponsor:

#2 jenova   Members   -  Reputation: 122

Like
Likes
Like

Posted 12 January 2002 - 05:22 AM

please list the exact error message, and you''ll probably get a more appropriate response.

To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.

#3 samosa   Members   -  Reputation: 122

Like
Likes
Like

Posted 12 January 2002 - 05:25 AM

did u check to make suere that u have the proper header fies included? u sould also make suer u have the proper .lib files included

,Matt

-= kill one, your a murderer, kill thousands your a conquerer =-

#4 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 12 January 2002 - 05:28 AM

#include <iostream> is a header file right?
and i dont know what .lib files are.
here are the errors:
Link Error : multiply-defined ''main'' (descriptor)
Defined in bkla.cpp
Defined in HelloWorld.cp

Link Error : multiply-defined ''main'' (code)
Defined in bkla.cpp
Defined in HelloWorld.cp



#5 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 12 January 2002 - 05:30 AM

Have you got more than one WinMain or main() function? If so, that''s your problem right there.

#6 StoNeD_TrOLL   Members   -  Reputation: 122

Like
Likes
Like

Posted 12 January 2002 - 05:30 AM

Opps.That was me.

#7 StoNeD_TrOLL   Members   -  Reputation: 122

Like
Likes
Like

Posted 12 January 2002 - 05:32 AM

quote:
Original post by Anonymous Poster
Have you got more than one WinMain or main() function? If so, that''s your problem right there.

wait,i only need one main out of my two files?


#8 Drizzt DoUrden   Members   -  Reputation: 100

Like
Likes
Like

Posted 12 January 2002 - 05:33 AM

Only one main, always remember that.

By the way, anything that is a .h is a header file. Header files basically are used to include the .lib in your program, but you have to add the .lib to your project. If your not using an API like Windows or DX/OpenGL, you don't have to worry about .libs yet.

You only need one main in your whole project, because you are including the other files which are connected to the file that has main in it.
------------------------------
Simple DirectMedia Layer:

Main Site - (www.libsdl.org)
Cone3D Tutorials- (cone3D.gamedev.net)
GameDev.net's Tutorials - (Here)

OpenGL:

Main Site - (www.opengl.org)
NeHe Tutorials - (nehe.gamedev.net)
Online Books - (Red Book) (Blue Book)


Edited by - Drizzt DoUrden on January 12, 2002 12:39:20 PM

#9 StoNeD_TrOLL   Members   -  Reputation: 122

Like
Likes
Like

Posted 12 January 2002 - 05:37 AM

quote:
Original post by Drizzt DoUrden
Only one main, always remember that.
------------------------------------------------------
I know one main per a file, but do you mean one main out of all my files in my project??




#10 jenova   Members   -  Reputation: 122

Like
Likes
Like

Posted 12 January 2002 - 05:45 AM

definitely one "main" per project. the linker looks for a function named "main" and sets the program to start here. thus if there were two "main"''s then it wouldn''t know which one to choose.

To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.

#11 StoNeD_TrOLL   Members   -  Reputation: 122

Like
Likes
Like

Posted 12 January 2002 - 05:49 AM

Thank you!!!So in my other files i just put in the header and go straight to the coding?like this:
#include <iostream>
{
std::cout <<"Hi!\n";
return 0;
}


Edited by - StoNeD_TrOLL on January 12, 2002 12:53:31 PM

#12 Drizzt DoUrden   Members   -  Reputation: 100

Like
Likes
Like

Posted 12 January 2002 - 06:00 AM

No. You make another function, like -

  
int PrintHi()
{
std::cout <<"Hi!\n";
return 0;
}


Remember to use function prototypes. Have you read any books/tutorials on C++ yet?

------------------------------
Simple DirectMedia Layer:

Main Site - (www.libsdl.org)
Cone3D Tutorials- (cone3D.gamedev.net)
GameDev.net''s Tutorials - (Here)

OpenGL:

Main Site - (www.opengl.org)
NeHe Tutorials - (nehe.gamedev.net)
Online Books - (Red Book) (Blue Book)


#13 Martee   Members   -  Reputation: 476

Like
Likes
Like

Posted 12 January 2002 - 06:01 AM

No, you create functions with names other than main.

int myReallyCoolUsefulFunction(void)
{
std::cout << "Hi!\n";
return 0;
}

Edit: Crap! You beat me to it...

Edited by - Martee on January 12, 2002 1:02:27 PM

#14 Drizzt DoUrden   Members   -  Reputation: 100

Like
Likes
Like

Posted 12 January 2002 - 06:04 AM

Sorry.

Stoned Troll, you should check out the book ''sams teach yourself c++ in 21 days.'' It''s a really great book; you''ll learn alot from it.

------------------------------
Simple DirectMedia Layer:

Main Site - (www.libsdl.org)
Cone3D Tutorials- (cone3D.gamedev.net)
GameDev.net''s Tutorials - (Here)

OpenGL:

Main Site - (www.opengl.org)
NeHe Tutorials - (nehe.gamedev.net)
Online Books - (Red Book) (Blue Book)


#15 StoNeD_TrOLL   Members   -  Reputation: 122

Like
Likes
Like

Posted 12 January 2002 - 06:06 AM

Im reading a c++in twenty four hours.And Drizzt,when i do your code my complier gives me this:
Error : undefined identifier 'std'
bkla.cpp line 3 std:: cout <<"Hi!\n";



Edited by - StoNeD_TrOLL on January 12, 2002 1:07:55 PM

#16 StoNeD_TrOLL   Members   -  Reputation: 122

Like
Likes
Like

Posted 12 January 2002 - 06:37 AM

well?

#17 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 12 January 2002 - 07:13 AM

Just leave out the "std::". It''s not supposed to be there.

#18 StoNeD_TrOLL   Members   -  Reputation: 122

Like
Likes
Like

Posted 12 January 2002 - 09:36 AM

cout is unidentified to my complier if i dont put"std::"...................none of this is working.

Edited by - StoNeD_TrOLL on January 12, 2002 4:41:08 PM

#19 Anozireth   Members   -  Reputation: 122

Like
Likes
Like

Posted 12 January 2002 - 09:47 AM

I think you need to #include <iostream.h> at the top of that file for cout to work.

#20 StoNeD_TrOLL   Members   -  Reputation: 122

Like
Likes
Like

Posted 12 January 2002 - 09:53 AM

The #include <iostream.h> worked but now where back to main!!!!How do you guys make a file when you already have a file with main???

Edited by - StoNeD_TrOLL on January 12, 2002 4:57:47 PM




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS