From cstrato at aon.at  Thu Feb  8 22:04:14 2007
From: cstrato at aon.at (cstrato)
Date: Thu, 08 Feb 2007 22:04:14 +0100
Subject: [Rd] Problem using ofstream in C++ class in package for MacOS X
In-Reply-To: <20070208203245.GA6397@wheat.betterworld.us>
References: <45C6315F.9020209@aon.at>
	<17862.14169.654577.51179@basebud.nulle.part>
	<45C6400A.3050700@aon.at> <m2d54pob4f.fsf@fhcrc.org>
	<45C65479.30906@aon.at>
	<20070208203245.GA6397@wheat.betterworld.us>
Message-ID: <45CB904E.1020300@aon.at>

Ross Boylan wrote:
> On Sun, Feb 04, 2007 at 10:47:37PM +0100, cstrato wrote:
>   
>> Seth Falcon wrote:
>>     
>>> cstrato <cstrato at aon.at> writes:
>>>   
>>>       
>>>> Thank you for your fast answer.
>>>> Sorrowly, I don?t know how to use a debugger on MacOS X, I am using 
>>>> old-style print commands.
>>>>     
>>>>         
>>> You should be able to use gdb on OS X (works for me, YMMV).  So you
>>> could try:
>>>
>>>       R -d gdb
>>>       run
>>>       # source a script that causes crash
>>>       # back in gdb, use backtrace, etc.
>>>
>>> + seth
>>>
>>>
>>>   
>>>       
>> Dear Seth
>>
>> Thank you for this tip, I just tried it and here is the result:
>>
>> Welcome to MyClass
>>  > writeFileCpp("myout_fileCpp.txt")
>> [1] "outfile =  myout_fileCpp.txt"
>> Writing file myout_fileCpp.txt using C++ style.
>> ---MyClassA::MyClassA()---------
>> ---MyClassA::WriteFileCpp---------
>>
>> Program received signal EXC_BAD_ACCESS, Could not access memory.
>> Reason: KERN_PROTECTION_FAILURE at address: 0x00000006
>> 0x020fe231 in std::ostream::flush (this=0x214f178) at 
>> /Builds/unix/o403/i686-apple-darwin8/libstdc++-v3/include/bits/ostream.tcc:395
>> 395     
>> /Builds/unix/o403/i686-apple-darwin8/libstdc++-v3/include/bits/ostream.tcc: 
>> No such file or directory.
>>         in 
>> /Builds/unix/o403/i686-apple-darwin8/libstdc++-v3/include/bits/ostream.tcc
>> (gdb)
>>
>> It seems that it cannot find ostream.tcc, whatever this extension means.
>>
>> Best regards
>> Christian
>>     
>
> I also don't see what the problem is, but have a couple of thoughts.
> Under OS-X there is an environment variable you can define to get the
> dynamic linker to load debug versions of libraries.  I can't remember
> what it is, but maybe something like DYLD_DEBUG (but probably DEBUG is
> part of the value of the variable).
>
> For that, or the tracing above, to be fully informative you need to
> have installed the appropriate debugging libraries and sources.
>
> You may need to set an explicit source search path in gdb to pick up
> the source files.
>
> Try stepping through the code from write before the crash to determine
> exactly where it runs into trouble.
>
> Does the output file you are trying to create exist?
>
> Unfortunately, none of this really gets at your core bug, but it might
> help track it down.
>
> Ross
>
>
>   
Dear Ross

Thank you, my problem is that I know exactly where the problem is but 
not how to solve it.

I have installed R-2.4.1 on three different machines to test the package:
- Intel-Laptop running Fedora Core 4:         package is OK
- PPC-PowerBook Titanium OS X 10.4.4:         package is OK
- Intel-MacBook Pro Core 2 Duo OS X 10.4.8:   C output OK, C++ output 
crashes R

The following code in method WriteFileCpp() works, but gives no result:
{
  std::ofstream output(outfile);
  output.close();
}

The following code in method WriteFileCpp() crashes R:
{
  std::ofstream output(outfile);
  output << "21" << endl;
  output.close();
}

It seems that on the Intel-MacBook Pro the operator "<<" is not 
recognized, when called
from within my package in R.
In contrast, when compiled as a C++ library, the same code does work on 
my Intel-Mac!

Best regards
Christian



[Rd] Problem using ofstream in C++ class in package for MacOS X
cstrato