iostream and sstream

iostream and sstream

Post by Russell Hanneke » Sat, 03 Nov 2001 05:53:40



I recently installed Codewarrior 7 on my iBook.  When I try to build this
program:

    #include <sstream>
    int main ()
    {
        std::ostringstream oss;
        return 0;
    }

it compiles, but I get link errors.  But if I add #include <iostream>, it
builds just fine.  (With the PC version of Codewarrior, #include <iostream>
is not necessary.)

I'm not an experienced programmer, but I had always assumed that #include
<sstream> was sufficient for using string stream classes.  Am I wrong, or
have I found a bug?

Regards,

Russell Hanneken

 
 
 

iostream and sstream

Post by Howard Hinnan » Sat, 03 Nov 2001 06:23:05



| I recently installed Codewarrior 7 on my iBook.  When I try to build this
| program:
|
|     #include <sstream>
|     int main ()
|     {
|         std::ostringstream oss;
|         return 0;
|     }
|
| it compiles, but I get link errors.  But if I add #include <iostream>, it
| builds just fine.  (With the PC version of Codewarrior, #include <iostream>
| is not necessary.)
|
| I'm not an experienced programmer, but I had always assumed that #include
| <sstream> was sufficient for using string stream classes.  Am I wrong, or
| have I found a bug?

Hi Russell,

Welcome to Stump the Expert!  And I gotta' admit, I stumped!  But if
you'll copy and paste the first couple of link errors into your next
post, I'll take another crack at it.  It is probably something to do
with precompiled headers (everytime something looks really mysterious,
I blame precompiled headers).  BTW, if you're using one (a file listed
as "prefix file" in your languge prefs panel), let me know that too.

--
Howard Hinnant
Metrowerks

 
 
 

iostream and sstream

Post by Russell Hanneke » Sat, 03 Nov 2001 06:43:42


Thanks for your reply, Howard.  I just noticed something else that might
help solve the mystery: I have the problem only when I use the command-line
tools, or if I choose to create a "Mach-O" project using the IDE.  My code
builds just fine as a Carbon console application.

Anyway, here is the link error I get from the command-line tools:

<begin command-line tools linker error>

### mwldppc Linker Error:
#   ___register_global_object is undefined

Errors caused tool to abort.
### mwccppc Driver Error:
#   linker '/usr/local/bin/mwldppc' returned with exit code 1

Errors caused tool to abort.

<end command-line tools linker error>

And here's what I get when I use the IDE:

<begin IDE linker errors>

prebinding disabled because of undefined symbols
Link Error   : ___vt__Q23std8ios_base is undefined
Link Error   : _id__Q23std8ctype<c> is undefined
Link Error   : _id_count_s__Q33std6locale2id is undefined
Link Error   : ___dl__FPv is undefined
Link Error   : ___dt__Q23std8ios_baseFv is undefined
Link Error   : _global__Q23std6localeFv is undefined
Link Error   : _init__Q23std8ios_baseFPv is undefined
Link Error   : ___end__catch is undefined
Link Error   : ___nw__FUl is undefined
Link Error   : ___ct__Q23std8ctype<c>FPCUcbUl is undefined
Link Error   : ___unexpected is undefined
Link Error   : ___throw is undefined
Link Error   : ___nwa__FUl is undefined
Link Error   : ___dla__FPv is undefined

<end IDE linker errors>

I confess that the whole Mac platform is pretty new to me.  I'm not even
clear on what Mach-O is exactly.  Maybe I should just stay away from it.

Regards,

Russell Hanneken

 
 
 

iostream and sstream

Post by MWRo » Sat, 03 Nov 2001 13:09:39




Quote:>Thanks for your reply, Howard.  I just noticed something else that might
>help solve the mystery: I have the problem only when I use the command-line
>tools, or if I choose to create a "Mach-O" project using the IDE.  My code
>builds just fine as a Carbon console application.

Thanks for posting this,

You get these errors if you don't include the MSL_Runtime_Mach-O.a  
runtime library in your project.

Ron

Quote:>I confess that the whole Mac platform is pretty new to me.  I'm not even
>clear on what Mach-O is exactly.  Maybe I should just stay away from it.

Mach-O is the exeuctable file format.  OS X can run PEF or Mach-O as
native but the Cocoa Framework is Mach-O, and you'd need Mach-O to get
the low level i/o stuff.

There may be a much greater source of help and knowledge using the PEF
carbon format that almost all Macintosh programmers are familiar with.

Ron

--
 CodeWarrior for Macintosh, v7 and CodeWarrior for Windows, v7
                 are shipping now !!  
      Call  1-800-377-5416 US and Canada Only


 
 
 

iostream and sstream

Post by Russell Hanneke » Mon, 05 Nov 2001 04:01:56





> >Thanks for your reply, Howard.  I just noticed something else that might
> >help solve the mystery: I have the problem only when I use the
> >command-line tools, or if I choose to create a "Mach-O" project using the
> >IDE.  My code builds just fine as a Carbon console application.

> You get these errors if you don't include the MSL_Runtime_Mach-O.a
> runtime library in your project.

I don't think that's what's going on.  When I use the IDE,
MSL_Runtime_Mach-O.a appears in the Libraries folder in the Project Manager.

Here's another clue: when I create a Mach-O C++ Console project using the
IDE, a default source file called HelloWorld.cp appears in the Sources
folder of the Project Manager.  If I change that file so that it contains my
test program, it builds without incident.  But if I "Clear" the
HelloWorld.cp file from the project, create a new file called osstest.cp
that contains my test program, and then add that file to the project, I get
the aforementioned link errors.

I also notice that, while the program is building, the text "helloworld_d"
flashes on the screen.  It goes by too quickly for me to see what the
message is.

Regards,

Russell Hanneken

 
 
 

iostream and sstream

Post by Howard Hinnan » Mon, 05 Nov 2001 04:44:20



| I don't think that's what's going on.  When I use the IDE,
| MSL_Runtime_Mach-O.a appears in the Libraries folder in the Project Manager.
|
| Here's another clue: when I create a Mach-O C++ Console project using the
| IDE, a default source file called HelloWorld.cp appears in the Sources
| folder of the Project Manager.  If I change that file so that it contains my
| test program, it builds without incident.  But if I "Clear" the
| HelloWorld.cp file from the project, create a new file called osstest.cp
| that contains my test program, and then add that file to the project, I get
| the aforementioned link errors.

Ahh... That's the critical info.  I was having trouble duplicating your
symptoms before now.   Josef *erl has written in the Mach-O release
notes:

| *   Link order is important.  Archive object files (those that end with
| the .a
|     extension) are only scanned once.  This means that if the ordering
| of an
|     archive object file is not correct, an "undefined symbol" link
| error will be
|     reported.
|    
|     An object file can make use of symbols defined in an archive library
|     downstream, but not vice versa, as all references are immediately
| resolved
|     by the linker.  Note that regular object files (those that end with
| the .o
|     extension) are not limited in this fashion.
|    
|     The correct link order for the libraries is as follows:
|    
|        [Third party libraries]
|        MSL_C++.a
|        MW_Runtime.a
|        crt1.o or dylib1.o or bundle1.o

You can change the link order by clicking on the "Link Order" tab in
the project window and then dragging files/libs around (items at top
are linked first).

Also, just reading through more of the release notes... there's a
wealth of info in here.  I highly recommend the read if you're going to
work with Mach-O.  I think I'll review them myself now...

--
Howard Hinnant
Metrowerks

 
 
 

1. Please Help - HP Scanjet 4c ands NT

I have a HP Scanjet 4c which I would like to connect to a Windows NT
machine - The machine keeps reporting that the scanner is not connected,
though the scsi driver recognises the device.
Any Ideas?
Many thanks

2. Preserving Query's

3. Enter SStreams' Link of the Month Contest

4. pb4.0 dw update db through stored procedures

5. List yourself in SStreams?

6. Help on Remote Notification ?? ( Beeper/Voice mail)

7. iostreams

8. vxl-ram32 question

9. T2 Thread Safe iostream library

10. iostreams: cout <<

11. IOSTREAMS

12. Freeware version of Iostreams library?

13. iostreams for g++ for MC68030 with GNU C++