Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
How to compile C++ using terminal?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to compile C++ using terminal?



Hi guys,

First of all, I'm sorry for posting this here. It would more appropriated for C++/Terminal list, I think. But, since I started post here you have helped me a lot and, as my doubt is somehow related to objective-c as well, I'll give it a try.

My primary objective was to learn how to write programs for iPhone. Then I found the need of a deep knowledge of Cocoa developing. So, I started to study Objective-C and I'm already trying some stuff in XCode. But, again, I found another big need for programming in objective-C: to master C++. So, I decided to learn C++.

I'm using "Sam's Teach Yourself C++ in 21 days" and "Thinking in C++" as a reference. Nevertheless, I'm stumbling in the very beginning. Trying to make the classic "Hello, World!", I got no problems if I do that in XCode ambient. However, just for curiosity, I decided to compile it using terminal. Here my problems begin:

Source file (as in the book):

#include <iostream.h>

int main()
{
	cout << "Hello, World!\n";
		return 0;
}

note: when building this file using xcode, i get a message saying that it includes at least one deprecated or antiquated header. If I follow XCode's suggestion and replace iostream.h by iostream then I get an error message: 'cout' was not declared in this scope. So, I add "using namespace std;" after #include line and everything goes right.

In terminal, using original file:

>gcc hello.cpp

I got this:
In file included from /usr/include/c++/4.0.0/backward/iostream.h:31,
from hello.cpp:1:
/usr/include/c++/4.0.0/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno- deprecated.
Undefined symbols:
"___gxx_personality_v0", referenced from:
___gxx_personality_v0$non_lazy_ptr in ccBpdfrr.o
"std::ios_base::Init::~Init()", referenced from:
___tcf_0 in ccBpdfrr.o
"std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)", referenced from:
_main in ccBpdfrr.o
"std::ios_base::Init::Init()", referenced from:
__static_initialization_and_destruction_0(int, int)in ccBpdfrr.o
"std::cout", referenced from:
__ZSt4cout$non_lazy_ptr in ccBpdfrr.o
ld: symbol(s) not found
collect2: ld returned 1 exit status



Using the modified version (that builds and runs smoothly under XCode):

>gcc hello.cpp

I got:
Undefined symbols:
"___gxx_personality_v0", referenced from:
___gxx_personality_v0$non_lazy_ptr in ccsC5YBv.o
"std::ios_base::Init::~Init()", referenced from:
___tcf_0 in ccsC5YBv.o
"std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)", referenced from:
_main in ccsC5YBv.o
"std::ios_base::Init::Init()", referenced from:
__static_initialization_and_destruction_0(int, int)in ccsC5YBv.o
"std::cout", referenced from:
__ZSt4cout$non_lazy_ptr in ccsC5YBv.o
ld: symbol(s) not found
collect2: ld returned 1 exit status


I also tried some stuff I found googling around, like "gcc -o hello hello.cpp", but got the same result.

So, can anyone tell me what am I missing?

Thanks

Adriano

note: I'm using an Intel iMac 2.66 with Mac OS X 10.5.5 and XCode 3.1.1
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Objc-language mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden




Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.