Jump to content
  • Announcements

    • Allan

      Forum Rules   04/13/2018

      Hello folks! As some things are being fixed, we'll keep you updated. Per hour the Forum Rules don't have a dedicated "Tab", so here is the place that we have our Rules back. New Users Lounge > [READ] - InsanelyMac Forum Rules - The InsanelyMac Staff Team. 
djacobs

simple C++ program refuses to build

5 posts in this topic

Recommended Posts

Hi,

 

First of all i am new to developing under mac through use of xcode 4.0.

I've had experience coding for linux using emacs and gcc, and microsoft visual studio (for windows).

 

The problem that i'm facing now is the following, whenever i try to run the code below i get the following warning and error.

I kind of have a feeling xcode doesnt accept my main() function or so.

 

Can anyone shine some light upon this dark mystery?

 

With kind regards,

Djacobs.

 

***Code***

//

// main.cpp

//

 

#include <iostream>

#include "genlib.h"

 

int main()

{

cout << "Hello, World!\n" << endl;

return 0;

}

 

 

 

***Warning***

warning: no previous prototype for function 'Main' [-Wmissing-prototypes,3]

int main ()

 

 

***Error***

Undefined symbols for architecture x86_64:

"_main", referenced from:

start in crt1.10.6.o

ld: symbol(s) not found for architecture x86_64

clang: error: linker command failed with exit code 1 (use -v to see invocation)

Share this post


Link to post
Share on other sites

what about using the classic main prototype?

 

int main(int argc, char **argv)

 

just give it a try

 

ciao,

cili0.

Share this post


Link to post
Share on other sites
what about using the classic main prototype?

 

int main(int argc, char **argv)

 

just give it a try

 

ciao,

cili0.

I assume you mean "int main(int argc, char *argv[])", but no i've allready tried that.

Share this post


Link to post
Share on other sites

I think you need std:: in front of cout and endl.

 

#include <iostream>

int main (int argc, char * const argv[]) {
   std::cout << "Hello, World!" << std::endl;
   return 0;
}

 

OR, use the std namespace:

 #include <iostream>

using namespace std;
int main (int argc, char * const argv[]) {
 cout << "Hello, World!" << endl;
 return 0;
}

Share this post


Link to post
Share on other sites
I think you need std:: in front of cout and endl.

 

#include <iostream>

int main (int argc, char * const argv[]) {
   std::cout << "Hello, World!" << std::endl;
   return 0;
}

 

OR, use the std namespace:

 #include <iostream>

using namespace std;
int main (int argc, char * const argv[]) {
 cout << "Hello, World!" << endl;
 return 0;
}

 

Hi Airr,

 

I've just wanted to thank you to solve this issue.

It seems like i have to deepen myself into using the standard namespacing.

Once again thanks for the help.

 

With kind regards,

DJacobs.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Recently Browsing   0 members

    No registered users viewing this page.

×