Skip to content

[Rcpp-devel] [Rd] FW: Question on 5.6 Interfacing C++ code

4 messages · Sean Robert McGuffee, Dirk Eddelbuettel

#
Hi All,

Just to follow up, I finally figured out a way to make a simple test project
I'm working on to compile and install and have access the code inside of R.
It turns out it was related to this "foo" name. I had to make the name of my
dynamic library output have the same name as the "foo" from the DESCRIPTION
file (and useDynLib(foo) ). I had made changes from a sample Rcpp program
where I liked the way args were passed. However, I didn't keep the name of
my dynamic library the same as the name of my directory and the name of my
functions and the name of my code files and the name of my project, and it
seems to me that it matters in about three places that need to match.
Eventually, after weeks of guessing incorrectly that I was doing something
else wrong altogether, I tried renaming the files and got one permutation to
work. After fiddling around with it to get to the bottom of what was going
on, I got one of my old original directories out and simply changed the
dynamic library name between the src/ and the .so part to match with the
name in the DESCRIPTION and the name inside the useDynLib() inside the
NAMESPACE file. Was this obvious to everyone else from reading the manual?
There were so many things I didn't understand that I missed that part.
Anyway, I've learned something about autoconf out of the whole ordeal, so
sometimes it pays off for me to be so silly. Anyway, I'd just like to
confirm that this is correct:

If I want to name a package "MY_PACKAGE_NAME"
then I have to do three things with this name to get Rcpp and/or my package
calling c++ to install and run correctly. I'll call my package directory TOP
1) put the line "Package: MY_PACKAGE_NAME" inside of TOP/DESCRIPTION
2) put the line "useDynLib(MY_PACKAGE_NAME)" inside of TOP/NAMESPACE
3) make sure the final dynamic library is named TOP/src/MY_PACKAGE_NAME.so
Do the experts agree that this is correct and necessary?

I happen to have named TOP to be MY_PACKAGE_NAME too, is that important too?
I also happen to be naming my function MY_PACKAGE_NAME too, is that
important? If I want to add more functions, I assume I can do that as long
as I link them into the TOP/src/MY_PACKAGE_NAME.so file. Is that correct?

Thanks in advance, 

Sean
On 4/21/11 10:57 AM, "Simon Urbanek" <simon.urbanek at r-project.org> wrote:

            
http://cran.r-project.org/doc/manuals/R-exts.html#Linking-GUIs-and-other-fr>>>>
o
#
Sean,

Please STOP CROSSPOSTING. Pick one of rcpp-devel or r-devel. I used the
former here but there is nothing really specific to Rcpp in your quests to
build a package.
On 23 April 2011 at 04:03, Sean Robert McGuffee wrote:
[...]
| NAMESPACE file. Was this obvious to everyone else from reading the manual?

Yes.

| If I want to name a package "MY_PACKAGE_NAME"
| then I have to do three things with this name to get Rcpp and/or my package
| calling c++ to install and run correctly. I'll call my package directory TOP
| 1) put the line "Package: MY_PACKAGE_NAME" inside of TOP/DESCRIPTION
| 2) put the line "useDynLib(MY_PACKAGE_NAME)" inside of TOP/NAMESPACE
| 3) make sure the final dynamic library is named TOP/src/MY_PACKAGE_NAME.so
| Do the experts agree that this is correct and necessary?

Yes.

Also note that package.skeleton() could have created all that for you, or in
the Rcpp context, Rcpp.package.skeleton().   See the Rcpp-package vignette.

| I happen to have named TOP to be MY_PACKAGE_NAME too, is that important too?

No.  

(It used to be, though, so it is often by convention. Does no harm.)

| I also happen to be naming my function MY_PACKAGE_NAME too, is that
| important? If I want to add more functions, I assume I can do that as long
| as I link them into the TOP/src/MY_PACKAGE_NAME.so file. Is that correct?

Yes.

If you let R do its way, then a package with 'Package: foo' will end up with
src/foo.so nomatter what the function names in src/*cpp are.


Hth, Dirk
#
Hi, sorry about the cross post thing--I just wanted to let both lists
know that my problem was solved since both list originally found out
about it.
With regard to the Rcpp.package.skeleton(), it worked really well for
me and easily to start a package.
What I couldn't figure out was how to add to a package once I already
started one.
Say for example, if I add a new class with source.cpp and header.h
file, what is the syntax to add them via Rcpp.package.skeleton()?
Thanks,
Sean
On Sat, Apr 23, 2011 at 7:37 AM, Dirk Eddelbuettel <edd at debian.org> wrote:
#
On 23 April 2011 at 18:54, Sean Robert McGuffee wrote:
| Hi, sorry about the cross post thing--I just wanted to let both lists
| know that my problem was solved since both list originally found out
| about it.
| With regard to the Rcpp.package.skeleton(), it worked really well for
| me and easily to start a package.
| What I couldn't figure out was how to add to a package once I already
| started one.
| Say for example, if I add a new class with source.cpp and header.h
| file, what is the syntax to add them via Rcpp.package.skeleton()?

You just drop source.cpp and header.h into src/.  R then builds with them. 

Remember that R uses an implicitly Makefile collecting all sources in src/*
and producing src/$(PACKAGE).so

Dirk