<HTML>
<HEAD>

</HEAD>
<BODY>
<FONT SIZE="2"><FONT FACE="Consolas, Courier New, Courier"><SPAN STYLE='font-size:10pt'>Hi Dirk and/or List,<BR>
<BR>
Thanks for the help!<BR>
<BR>
First &nbsp;of all, let me apologize for somehow sending this to a Windows related discussion--I'm actually on a mac. I'm completely oblivious to how email-interfaced discussion groups work. <BR>
<BR>
Regarding:<BR>
&gt; Can you reduce the problem to something simpler?<BR>
Not easily. Basically, what I'm doing is trying to connect a functional command-line-argument based C++ program/library to an R interface. My first step was to simply make a C++ function that gets two strings from R to use as file names. I got that to work just fine, so my next step was to try to pass those to the library--which is where the problem arises. Dissecting out part of the library is a mess because I have a tangled web of cross-functionality in that library. <BR>
<BR>
Somewhat related to that:<BR>
Honestly, I'm very new to R and have an extremely difficult time understanding most of it's documentation. I think a lot of times the people who write it are close to it and know what they mean, but I tend not to. The skeleton thing didn't come with libraries, so I think that is the key to my problem. I have to link to my library, and so far I'm attempting that by literally copying all the source files into the src directory. I'd much rather just link to the already compiled and functional library with small functions but haven't found any way to do that. If you could help me with that, I would very much appreciate it. I need to link to my library, I assume there might be some need for my headers, and also to the headers and libraries referenced by it. If you could give me a generic mechanism for doing that, I'd very much appreciate it.<BR>
<BR>
Regarding:<BR>
&gt; We would need to see what you do in file R/zzz.R and the .onLoad() function<BR>
&gt; (assuming you use a NAMESPACE). &nbsp;Else we'd need the equivalent .First.lib()<BR>
&gt; function. <BR>
<BR>
starting by going to my package directory (which worked prior to attempting to attach a library)<BR>
<BR>
cd R_PACKAGES/alignR/<BR>
<BR>
cat NAMESPACE <BR>
useDynLib(alignR)<BR>
export(colorSpaceToSequenceSpace)<BR>
<BR>
ls R/<BR>
README &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;colorSpaceToSequenceSpace.R<BR>
<BR>
cat R/colorSpaceToSequenceSpace.R <BR>
colorSpaceToSequenceSpace &lt;- function(colorSpace,sequenceSpace){<BR>
params &lt;- list(colorSpaceFile=colorSpace,sequenceSpaceFile=sequenceSpace)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.Call( &quot;colorSpaceToSequenceSpace&quot;,params, PACKAGE = &quot;alignR&quot; )<BR>
}<BR>
<BR>
That's all I have that is unique from the skeleton in that directory. Regarding other configuration:<BR>
<BR>
cd /Library/Frameworks/R.framework/Resources/etc/x86_64<BR>
<BR>
grep srm Makeconf<BR>
SHLIB_LIBADD = /WHITEHOUSE_LAB/WHITEHOUSE_LAB_PROGRAMS/LIBSRM/LIB/libsrm.SeanBenchGcc.so &nbsp;<BR>
<BR>
I started off by using a static library <BR>
/WHITEHOUSE_LAB/WHITEHOUSE_LAB_PROGRAMS/LIBSRM/LIB/libsrm.SeanBenchGcc.a<BR>
which I would prefer to use because making the dynamic one was a pain and I'm so unfamiliar with that process I don't know if I'm doing it correctly, but neither way works so far. I haven't tried including other libraries such as libpng14 and shark and some other curve fitting libraries, but it seemed to me that if I'm compiling and linking okay and they aren't being called *YET*, that should be okay. I would like to know how to link to those in R eventually though. Also, I might be wrong about them not mattering if they don't get called and wonder if that could be a source of my problem. What I do to use my library from the command line is compile interface code with headers from my libaries and libaries it references and statically link to it and other libraries. I get the feeling that there must be a way to do this in an R interface, I'm just not clear as to how.<BR>
<BR>
I hope this paints a clearer picture of what my problem is.<BR>
<BR>
Thanks again for any help,<BR>
<BR>
Sean<BR>
<BR>
<BR>
<BR>
On 3/23/11 7:49 AM, &quot;Dirk Eddelbuettel&quot; &lt;<FONT COLOR="#0000FF"><U><a href="edd@debian.org">edd@debian.org</a></U></FONT>&gt; wrote:<BR>
<BR>
&gt; <BR>
&gt; Hi Sean,<BR>
&gt; <BR>
&gt; On 23 March 2011 at 00:20, Sean Robert McGuffee wrote:<BR>
&gt; | Hi,<BR>
&gt; | I&#8217;m new to using C++ inside of R. I got a test program to work, so<BR>
&gt; | it&#8217;s time for me to attach some function to it. I seem to be having<BR>
&gt; | some issues though. I wonder if anyone out there can help me<BR>
&gt; | understand the results I am getting. I&#8217;ve got to a point where it<BR>
&gt; | seems to me that everything is installing but then afterwards it<BR>
&gt; <BR>
&gt; Everything is _compiling_ and _linking_ which is good but...<BR>
&gt; <BR>
&gt; | segmentation faults. In particular the following are the parts where<BR>
&gt; | the problem comes up:<BR>
&gt; | ** testing if installed package can be loaded<BR>
&gt; | &nbsp;*** caught segfault ***<BR>
&gt; | address 0x20, cause 'memory not mapped'<BR>
&gt; <BR>
&gt; ...when the build process tries to load the package you are building you get<BR>
&gt; a run-time error as is clearly shown by the traceback. Some initalization<BR>
&gt; goes nelly-up, could be your C++ code or your other library<BR>
&gt; (libsrm.SeanBenchGcc ?).<BR>
&gt; <BR>
&gt; Can you reducde the problem to something simpler?<BR>
&gt; <BR>
&gt; | If anyone has any suggestions, please let me know. The full version of<BR>
&gt; | the installation command and results is below:<BR>
&gt; <BR>
&gt; We would need to see what you do in file R/zzz.R and the .onLoad() function<BR>
&gt; (assuming you use a NAMESPACE). &nbsp;Else we'd need the equivalent .First.lib()<BR>
&gt; function. <BR>
&gt; <BR>
&gt; Dirk<BR>
&gt; <BR>
</SPAN></FONT></FONT>
</BODY>
</HTML>