Hi guys!

I want to start learning Objective-C and Id like to use c++ streams, problem is that it is causing error on this hello world example:

#import <iostream>
#import <windows.h>

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

and these are the errors:
undefined reference to std::cout
-||- std::operator <<
etc. etc.

Im programming on Win XP, using gcc compiler
What I have to do to avoid these error messages?

EDIT:
I dont know if I post thiss in the right section but somewhere in C section I saw post about objective-c so I guess I had to post post about objective-c++ in this section

Edited by JuloF26: n/a

6
Contributors
12
Replies
15
Views
5 Years
Discussion Span
Last Post by TPBarnett

This:

#import <iostream>
#import <windows.h>

is not correct.

It should be "#include"

#include <iostream>
#include <windows.h>

Edited by Fbody: n/a

Ive changed it to include but uts still causing the same errors :(

works fine for me with the mentioned changes

With the required change, the code you have written is valid C++. But like I said, I don't know Objective.

It's possible that you are trying to compile C++ code on a C compiler. The C++ language is a "superset" of the C language, which means that is is based on and expands the C language.

In order to compile C++, you need a C++ compiler. A C compiler will not recognize C++ syntax as valid syntax.

Edited by Fbody: n/a

really?? thats strange,
so the problem is in something else...

where should I have the libraries?? I have them in the C:\Dev-Cpp\include
but the code I have in C:\objective-c\hello.mm

EDIT:
Im compiling it on objective-c compiler and it is objective-c++ code nor c++ thats the reason why I had there import instead of unclude :)

Edited by JuloF26: n/a

It's probably an issue with Objective-* then. But I can't help you there.

I remember something about the Objective-C++ compiler not including glibc++ by default as g++ does.

Try including the argument -lstdC++ (along with all of the appropriate switches for the other libraries).

@Fbody #import does work on Objective-C, so I'm not sure what the nuances are for Objective-C++.

Edited by jonsca: n/a

This is not Objective-C forum. Please move it to "other" languages.

@Fbody #import does work on Objective-C, so I'm not sure what the nuances are for Objective-C++.

Like I said, I don't know Objective-*. If that's a "nuance", so be it. :)

wuhu!
I compiled it with g++ instead of gcc :D

and sorry, as I said I saw in C section post about Objective-c that confused me :)

Like I said, I don't know Objective-*. If that's a "nuance", so be it. :)

Not trying to purport any knowledge on my part, as I've only messed around with it a few times. :)

This is not Objective-C forum.

There are a handful of questions on Objective-C that were deemed to be on topic (ipso facto) in the C forum, so this isn't too much of a stretch.

Edited by jonsca: Italics make Latin more zesty

Objective C is not a C or C++ language. C code can be called from Objective C, however OS X and iOS are designed around an Object C API and this is not the best approach. If you are developing software for iOS or OS X use Objective C not C or C++. If you are wanting to develop software for Windows use C or C++ and not Objective C.

Hi guys!

I want to start learning Objective-C and Id like to use c++ streams, problem is that it is causing error on this hello world example:

#import <iostream>
#import <windows.h>

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

and these are the errors:
undefined reference to std::cout
-||- std::operator <<
etc. etc.

Im programming on Win XP, using gcc compiler
What I have to do to avoid these error messages?