I figured out that I needed to include dylib1.o or crt1.o to resolve the
error stated below. I then hit the fact that the MSL C++ libraries seem to
require the MSL C libraries. What I am trying to do is build against the
BSD headers and use the MSL C++ library. Is this possible? If so how can
it be done? If this is not possible how can I use function in Libc that are
not found in MSL C. Things like bzero, bcopy, index, and nanosleep etc? Am
I stuck with lifting the prototype and needed structures from the BSD header
files and placing them where I need them?
> I have converted my projects to build against the BSD C headers but cannot
> link. I am getting the following error:
[quoted text clipped - 9 lines]
> http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
> -----== Over 80,000 Newsgroups - 16 Different Servers! =-----
Hi All,
I have a similar project setup - and have a lot of trouble to get
iostreams, wchars and more running.
Firstly, i want to focus only on one problem with iostreams:
The project is using the BSD C library and MSL C++ library. The access
paths are:
System:
R {Compiler}MacOS X Support/Headers/(wchar_t Support fix)
{OS X Volumn}usr/include
{OS X Volumn}usr/lib
R {Compiler}MacOS X Support
R {Compiler}MSL/MSL_C
R {Compiler}MSL/MSL_C++
F {OS X Volumn}System/Library/Frameworks
R {BOOST}
I have linked against MSL_All_Mach-O.lib.
Note: there were link errors when linked against
MSL_Runtime_Mach-O.lib and MSL_C++_Mach-O.lib only because of
undefined code (e.g. __get_char())- so I used the MSL_All lib and had
no link errors anymore.
Native wchar_t is ON, and the MSL wchar_t fix is used.
Problem: the program crashes during operator<< with a wfstream.
Here is the code were the problem occures: (note: this is just the
example for using codecvt in the MW manual, however it looks like the
actual problem has nothing to do with locales!)
std::locale loc(std::locale(), new std::__utf_8<wchar_t>);
std::wofstream out;
out.imbue(loc);
out.open("test.dat");
if (out)
out << L"This is a test \x00DF";
The program successfully opens the file.
However it crashes during writing, namely in basic_filebuf<wchar_t,
traits>::write2() when it reaches the putc macro the first time:
for (int i = 0; i < n; ++i)
--> if (putc(extern_buf[i], file_) == EOF)
return traits::eof();
return traits::to_int_type(intern_buf);
The problem is (obviously) a macro used in this function: putc
This macro is defined in BSD (in stdio.h) and in MSL (in cstdio).
Because of the order of the include paths, the macro will be found in
the BSD headers:
in /user/include/stdio.h
#define putc(x, fp) __sputc(x, fp)
and __sputc is defined in stdio.h as:
/*
* This has been tuned to generate reasonable code on the vax using
pcc.
*/
#define __sputc(c, p) \
(--(p)->_w < 0 ? \
(p)->_w >= (p)->_lbfsize ? \
(*(p)->_p = (c)), *(p)->_p != '\n' ? \
(int)*(p)->_p++ : \
__swbuf('\n', p) : \
__swbuf((int)(c), p) : \
(*(p)->_p = (c), (int)*(p)->_p++))
#endif
Certainly, the MSL putc macro is defined differently. If i take a
closer look to the macro definition above, i doubt that this expansion
was really the intention.
So, my (first) question is:
More general: how to get MSL C++ running with BSD C lib?
Specific: is this a bug? How can I fix it?
Is this another example why we should NOT using macros ;) ?
Regards
Andreas Grosam
Kirk Haderlie - 22 Jul 2003 14:38 GMT
Andreas,
After exchanging numerous question with Ron we determined that the MSL C++
libraries MSL_Runtime_Mach-O.a and MSL_C++_Mach-O.a are what need to be used
hwen building against BSD headers. If you look at the library build projects
these libraries are built against the BSD headers. The problem is that
MSL_All_Mach-O.lib is built against the MSL C headers. Although using
MSL_ALL_Mach-o.lib works most of the time small mismatches like you have
found can cause very serious bugs which can be hard to track down. There is
an issue with BSD, that it does not have wchar_t support, so many routines
for wchar_t support found in the MSL are not available in BSD. There is an
Apple technote that tell you to use CFStrings.
Any further question let me know.
> Hi All,
>
[quoted text clipped - 76 lines]
> Regards
> Andreas Grosam
MW Ron - 22 Jul 2003 17:06 GMT
>Hi All,
>
[quoted text clipped - 15 lines]
>
>I have linked against MSL_All_Mach-O.lib.
Just to make this official :) Ditto what Kirk said.
I caused some misleading information with my early replies about this
and I apolgoize. Afer some serious discussion and working with Josef
we cleared this up and bottom line is MSL C++ is fine with the BSD C
library but you need to use the .a variants of MSL C++ and runtime
libraries.
Ron

Signature
Metrowerks has moved, our new address is now
7700 West Parmer Lane
Austin, TX 78729
Sales and Support 512-996-5300 800-377-5416
Ron Liechty - MWRon@metrowerks.com - http://www.metrowerks.com
Andreas Grosam - 23 Jul 2003 09:44 GMT
> >Hi All,
> >
[quoted text clipped - 25 lines]
>
> Ron
Thank you Ron and Kirk.
To summarize it, if we have a Mach-O app using BSD C and the MSL C++
lib we have to link against:
crt1.o
(other sources)
MSL_Runtime_Mach-O.a
MSL_C++_Mach-O.a
We MUST NOT link against MSL_All_Mach-O.lib!
I want to mention, that this project must not use native wchar_t
support. (note, my example of the access paths does this!) The wchar_t
is defined in the BSD headers as a typedef (int) and thus "native
wchar_t support" must be (and is) off for all libraries, too.
However, if we want native wchar_t by the MW compiler, we need all
libraries built with native wchar_t type support ON, too. Thus, we
cannot use the libs directly without re-compiling them.
In order to build a lib or app with native wchar_t support, we need to
put the access path "{Compiler}MacOS X Support/Headers/(wchar_t
Support fix)" on top of the list and set the corresponding checkbox in
the compiler prefs to ON.
I did not tried out this - are there any known subtleties? (e.g,
conflicts in system libraries?)
Andreas
MW Ron - 23 Jul 2003 17:05 GMT
>Thank you Ron and Kirk.
>To summarize it, if we have a Mach-O app using BSD C and the MSL C++
[quoted text clipped - 3 lines]
>MSL_Runtime_Mach-O.a
>MSL_C++_Mach-O.a
Right
>We MUST NOT link against MSL_All_Mach-O.lib!
Right,
>I want to mention, that this project must not use native wchar_t
>support. (note, my example of the access paths does this!) The wchar_t
[quoted text clipped - 10 lines]
>I did not tried out this - are there any known subtleties? (e.g,
>conflicts in system libraries?)
Nothing if you use the usr/include for the headers and not MSL C. If
you mix them there can be some things like stream buffers and such but
that is only if you mix them.
Ron

Signature
Metrowerks has moved, our new address is now
7700 West Parmer Lane
Austin, TX 78729
Sales and Support 512-996-5300 800-377-5416
Ron Liechty - MWRon@metrowerks.com - http://www.metrowerks.com