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?

Thanks in advance for every reply

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

This:

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

is not correct.

It should be "#include"

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

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.

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 :)

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++.

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.

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?

Thanks in advance for every reply

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.