1.11M Members

Objective c++, std namespace

 
0
 

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

 
0
 

This:

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

is not correct.

It should be "#include"

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

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

 
0
 

works fine for me with the mentioned changes

 
0
 

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.

 
0
 

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

 
0
 

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

 
0
 

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

 
0
 

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

 
0
 

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

 
0
 

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

 
0
 

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.

 
1
 

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

You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article