Thanks, but swig did not help.
After some more experimentation, I have discovered I can get it to work in the following way, but I think it is a bit impractical. If I compile the shared library as: g++ -shared -o libobtest2.so obtest2.o -fpic /usr/lib/openbabel/2.2.3/mdlformat.so -lopenbabel -lR so the name of one of the plugins is specified. Then, in R I run: R>dyn.load("/usr/lib/openbabel/2.2.3/mdlformat.so") R>dyn.load("libobtest2.so") R>.Call("test") format: 0x7fe114c96d20 #this is the correct result NULL So then it works. But this requires that I know the full path to every plugin when the code is compiled and when the library is loaded. Is there a practical way to do this, say, if this were part of an R package? I have also tried compiling the shared library as before, without the plugin, and then just loading the plugin with dyn.load but this does not work. It seems like it should though, does anyone know why it doesn't? Conversely, if you compile with the plugin specified, but don't load it with dyn.load it seg faults. The way it works normally in OpenBabel is that each plugin is its own shared library and then they get loaded at run time with the dlopen function (on linux at least). I have verified that this code is still being executed when called from within R, but it doesn't work for some reason. Kevin On 03/21/2013 05:51 AM, Noel O'Boyle wrote: > This isn't exactly answering your question, but have you considered > creating the R Swig wrapper. This may just simply work out of the box > (or indeed not!) with little effort. > > - Noel > > On 20 March 2013 16:13, Kevin Horan<kevinho...@globalrecordings.net> wrote: >> I would like to make use of open babel from within the R language. >> Initially I just need to do some format conversions, but may expand the >> usage to other parts of OpenBabel as well. I am familiar with embedding >> C/C++ code in R, but I'm having some trouble with the plugin mechanism >> of OpenBabel in this case. The problem is that the formats are not >> available when I run the OpenBabel code from within R. So, for example, >> if I search for the SDF format like so: >> OBFormat *format = conv.FindFormat("SDF"); >> I always get back a 0 value. The same chunk of code executed outside of >> R, as a normal stand-alone program, works fine. So does anyone know how >> I can ensure that the formats get loaded? Thanks. >> One other thing to mention, someone might suggest linking against a >> static version of openbabel which includes all the plugins. I would like >> to avoid that if possible since this needs to work in an R package that >> will be distributed across platforms, so it would be hard to ask people >> to compile a special, static, version of openbabel just to compile this >> R package. Since it needs to work on windows, mac and linux, it would be >> nice if I can make use of any existing installed shared obenbabel >> libraries. If it turns out it can't be done, then I'll go down that >> path. Thanks. >> >> Here is an example of the problem: >> >> test program (obtest2.cc): >> >> #include<iostream> >> #include<openbabel/obconversion.h> >> #include<R.h> >> #include<Rinternals.h> >> >> extern "C" { SEXP test(); } >> >> int main(){ >> test(); >> } >> SEXP test() >> { >> OpenBabel::OBConversion conv; >> OpenBabel::OBFormat *format = conv.FindFormat("SDF"); // >> search for SDF format >> std::cout<<"format:"<<format<<std::endl; >> // print out search result, either 0 >> >> // or an address >> return R_NilValue; >> } >> >> >> compile: >> g++ -I/usr/include/openbabel-2.0 -I/usr/share/R/include -fpic -c >> obtest2.cc -o obtest2.o >> g++ -o obtest2 obtest2.o -fpic -lopenbabel >> -lR # Executable >> g++ -shared -o libobtest2.so obtest2.o -fpic -lopenbabel -lR # R >> library >> >> Run executable: >> $ ./obtest2 >> format: 0x7f1858275d20 #found some result, this is what I expect >> >> Run in R: >> R>dyn.load("libobtest2.so") >> R>.Call("test") >> format: 0 # the format was not found, so 0 was >> returned >> NULL >> >> Kevin >> >> >> ------------------------------------------------------------------------------ >> Everyone hates slow websites. So do we. >> Make your web apps faster with AppDynamics >> Download AppDynamics Lite for free today: >> http://p.sf.net/sfu/appdyn_d2d_mar >> _______________________________________________ >> OpenBabel-Devel mailing list >> OpenBabel-Devel@lists.sourceforge.net >> https://lists.sourceforge.net/lists/listinfo/openbabel-devel ------------------------------------------------------------------------------ Own the Future-Intel® Level Up Game Demo Contest 2013 Rise to greatness in Intel's independent game demo contest. Compete for recognition, cash, and the chance to get your game on Steam. $5K grand prize plus 10 genre and skill prizes. Submit your demo by 6/6/13. http://p.sf.net/sfu/intel_levelupd2d _______________________________________________ OpenBabel-Devel mailing list OpenBabel-Devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openbabel-devel