Question

I'm creating a package that is going to be used by R (the statistical program), I'm not an expert using this application but I have managed to create a very simple package, using the following logic, I have some classes in C++, as the code has to be compiled using the R compiler and it only allows C code, I have a wrapper C code that call the C++ methods, and later I have an R script that call the methods exposed by the C code, so basically is a communication like R <-> C<->C++.

The full tutorial that I used to create this package is found here, I add it as a reference.

Now my problem is that I need to add some functionality to the package that I already created, what I need to do is to add code for late binding to a COM object which is another product that I created and that is registered using regasm tool.

This is the c++ code that I'm using to try to late bind to the COM object, I'm trying to use IDispatch to do so:

{
...
CLSID clsid;    
HRESULT hr = CLSIDFromProgID((WCHAR*)"My Com object ProgId", &clsid);
if(FAILED(hr))                      
  return;   
...     
}

I didn't paste the whole code because only with these lines the compiler is giving me troubles already, the command I use to compile is

R CMD SHLIB Cclass.cc C++class.cc

Where "Cclass.cc" has the C code that call the c++ methods and "C++class.cc" is actually the C++ code.

When I compile these classes the compiler says

"undefined reference to `CLSIDFromProgID@8'collect2: ld returned 1 exit status"

I"m sure I have added all the header files that I need, that's why I believe my problem is that I'm not including ole32.lib and oleaut32.lib which are static libraries.

So, my question is, how can I include this libraries in order to be able to use the methods for late binding, like CLSIDFromProgID(...) or QueryInterface(...). Also if anyone believes that my problem is not linking this libraries, but something else, it would be great if can point me to which my problem may be.

Also have in mind that I need to link with those statics libraries in a way that they can be compiled without problem by the R compiler, which if I'm not wrong is a merely c compiler.

Was it helpful?

Solution

I've not tried doing this with C/C++ but rather with Fortran. I had a similar problem in that some standard IO libraries weren't being included in the library I was created. In the end I just included them all and compiled using the Fortran compiler. I didn't use any of the R compiler utilities, just compiled as if I were compiling a static Fortran library normally for use with anything else. This worked fine.

A debug path might be to compile as a static library using gcc (or whatever you're using) then try to include and call that static library from another C program, then if that works try with R.

Hope this is helpful, writing these R packages is pretty hard unless you're using vanilla C or Fortran as far as I can tell.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top