Re: error loading cxx local model in isis: undefined symbol

From: Thomas Dauser <thomas.dauser_at_email.domain.hidden>
Date: Tue, 19 Nov 2013 11:06:57 -0500
Hi John,

thanks for your reply. Still, I'm confused. I'm trying to understand why 
local models in C are so much more complicated for isis than in xspec.

I got the C++ model running, exactly as you described. Is there a reason 
why one has to write a wrapper for isis, which is done by xspec 
automatically. But not the way I understood it from Maurice, although 
this approach made much more sense in my opinion. Now I have to define a 
C++ model with

extern "C" test void( ... )

and a wrapper converting this to C with

extern "C" C_test void( ... )

Note the C_test. Any other function name else won't work. Why do I have 
to create a wrapper manually in isis, while xspec automatically does it 
perfectly fine?


While I more or less understand the issue with C++ above, I'm totally 
confused with the C case (so, from here on, I'm only talking about a C 
model). Following the heasoft guide for local models 
(http://heasarc.gsfc.nasa.gov/xanadu/xspec/manual/XSappendixLocal.html), 
it should be possible to just define a local model in C, when referring 
to it in the lmodel.dat with "c_test" (not the small "c"). . This is 
basically the test case described in my previous email. There I simply 
create a C function called

extern "C" test void( ... )

(following the manual). This, again, works nicely in xspec, but isis 
complains that the function "c_test" is not defined. If I provide this 
function (simply a C-Wrapper for the C-Function), it works. Why do I 
have to provide two identical functions with different names for one 
actual model? (using C_test or c_test as function name also fails. Then 
isis is looking for a function called "test", which clearly does not exist)


Please tell me, if I'm completely missing something or just completely 
underestimate the complexity of importing local xspec models into isis. 
Thanks!


Cheers,
Thomas

On 11/19/2013 05:44 AM, John Houck wrote:
> I think it's just a matter of providing an additional
> subroutine for a C interface.
>
> For example, have a look at how xspec provides C and Fortran
> interfaces for the xspec internal models. See, e.g.
>   heasoft-6.14/Xspec/src/XSFunctions/funcWrappers.cxx
>
> For a C++ local model that provides a symbol 'test':
>
>     extern "C"
>     void test(const RealArray& energy,
>               const RealArray& parameter,
>               int spectrum,
>               RealArray& flux,
>               RealArray& fluxError,
>               const string& init)
>
> the lmodel.dat file should, by convention, refer to subroutine
> C_test.
>
> The notation "C_test" means that a C++ interface is provided
> through the symbol "test", while a C interface (if it exists)
> should appear under the name "C_test".
>
> Following the examples in funcWrappers.cxx, a C-linkage symbol
> C_test can be defined as in the appended code segment.
>
> Once this C-linkage symbol is provided, libxspeclocal.so will
> contain two symbols through which the local model can be
> evaluated. C++ programs can call 'test' and C programs can call
> 'C_test'.
>
> If you also want to provide a Fortran linkage symbol, then
> funcWrappers.cxx shows one way to do that via cfortran.h. One
> could also use the iso_c_binding module with "modern" Fortran.
>
> Thanks,
> -John
>
> // Here's an example C-linkage wrapper definition for 'test'.
> // An implementation of cppModelWrapper is in funcWrappers.cxx
> // mentioned above.
>
> extern "C"
> void C_test (const double* energy, int nFlux, const double* params,
>            int spectrumNumber, double* flux, double* fluxError, const char* initStr)
> {
>     const size_t nPar = 3;
>     cppModelWrapper(energy, nFlux, params, spectrumNumber, flux, fluxError,
>                     initStr, nPar, test);
> }
>
> ----
> You received this message because you are
> subscribed to the isis-users list.
> To unsubscribe, send a message to
> isis-users-request_at_email.domain.hidden> with the first line of the message as:
> unsubscribe
>
Received on Tue Nov 19 2013 - 11:07:06 EST

This archive was generated by hypermail 2.3.0 : Fri May 02 2014 - 08:35:47 EDT