using XLW and QuantLib library

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

using XLW and QuantLib library

Adjriou Belak
Hi,
 
I'm trying to use quantlib library on the XLWExample file :
I am using Visual C++ 6.0.
 
LPXLOPER EXCEL_EXPORT xlDate(XlfOper day,XlfOper Month,XlfOper Year)
  {
    EXCEL_BEGIN;
    // Converts d to a double.
    int d=day.AsInt();
 int m=Month.AsInt();
 int y=Year.AsInt();
 
 Date today(d, November, y);
 double ret=today.lastDayOfMonth();
   
    // Returns the result as a XlfOper.
    return XlfOper(ret);
    EXCEL_END;
  }
 
And I can't compile  this file. I have got this error message :
 
msvcprtd.lib(MSVCP60D.dll) : error LNK2005: "public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::~basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(void)" (??1?$basic_strin
[hidden email]) already defined in QuantLib-vc6-mt-0_3_7.lib(mathf.obj)
 
Does somebody use the quantlib library with XLW library ?
Do you have any idea to fix that problem ?
 
I compiled QuantLib library as Win32 debug project and my current project as Win32OntheEdgeRelease.
 
 
Regards and thanks for your help.



Découvrez le nouveau Yahoo! Mail : 250 Mo d'espace de stockage pour vos mails !
Créez votre Yahoo! Mail

Avec Yahoo! faites un don et soutenez le Téléthon !
Reply | Threaded
Open this post in threaded view
|

Re: using XLW and QuantLib library

erik-44
On Tue, 2004-12-14 at 10:44 +0100, Adjriou Belak wrote:
> Hi,

Hello
 

> I'm trying to use quantlib library on the XLWExample file :
> I am using Visual C++ 6.0.
>  
> LPXLOPER EXCEL_EXPORT xlDate(XlfOper day,XlfOper Month,XlfOper Year)
>   {
>     EXCEL_BEGIN;
>     // Converts d to a double.
>     int d=day.AsInt();
>  int m=Month.AsInt();
>  int y=Year.AsInt();
>  
>  Date today(d, November, y);
>  double ret=today.lastDayOfMonth();
>    
>     // Returns the result as a XlfOper.
>     return XlfOper(ret);
>     EXCEL_END;
>   }

I realize the above is just a quick test function, but it looks slightly
odd - for future reference -
- a function called xlDate would usually be exported to Excel as "DATE"
which would be bad because Excel already has a function by that name
- QuantLib's Date class constructor accepts an Excel-style serial date
as input so you wouldn't normally split the input date into D/M/Y unless
you had some special reason to do so
- Date member function lastDayOfMonth returns an int so you should
declare the return value ret as int not double

So you could rewrite the function as

  LPXLOPER EXCEL_EXPORT xlLastDay(XlfOper xlInputDate)
  {
    EXCEL_BEGIN;

    short ret=Date(xlInputDate.AsInt()).lastDayOfMonth();

    return XlfOper(ret);
    EXCEL_END;
  }
 
> And I can't compile  this file. I have got this error message :
>  
> msvcprtd.lib(MSVCP60D.dll) : error LNK2005: "public: __thiscall
> std::basic_string<char,struct std::char_traits<char>,class
> std::allocator<char> >::~basic_string<char,struct
> std::char_traits<char>,class std::allocator<char> >(void)" (??1?
> $basic_strin
> g@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ) already
> defined in QuantLib-vc6-mt-0_3_7.lib(mathf.obj)

- Linking to msvcprtd.lib implies that you're compiling one of the debug
builds of xlw
- Linking to QuantLib-vc6-mt-0_3_7.lib implies that you're linking to
the "Win32 Release MTDLL" build of QuantLib
(see below)

> Does somebody use the quantlib library with XLW library ?

The QuantLib project includes Excel addin QuantLibXL which is an example
of using QuantLib and xlw.

> Do you have any idea to fix that problem ?
>  
> I compiled QuantLib library as Win32 debug project and my current
> project as Win32OntheEdgeRelease.

xlw Win32OnTheEdgeRelease does not use the msvcprtd.lib library
mentioned in your output above and if linked to QuantLib in the usual
way would depend on the Win32 Release MTDLL build of QuantLib not Win32
debug.

I've succeeded in compiling a working xlw addin including both your test
function above (renamed to date2) and my version of the function.  

I have a feeling you've set some project settings incorrectly and that
you're mixing debug and release.  I list below how I built the project,
maybe you could try the same thing, and let me know if you're still
having trouble?  You might want to reinstall xlw to fix any settings
that may have been messed up.  I suggest debug rather than release for
now -

- compile QuantLib as Win32 Debug MTDLL
- compile xlw as Win32 OnTheEdgeDebug (with RTTI)
- at the top of xlwExample.cpp you should have
#include <ql/quantlib.hpp>
- you need to amend xlAutoOpen to register your new function if you
haven't done that
- in xlwExample project settings, for Win32 OnTheEdgeDebug,

1) add the top level QuantLib directory
(e.g. QL_DIR or C:\Program Files\QuantLib)
to your additional include directories

2) add the path to the QuantLib lib directory
(e.g. C:\Program Files\QuantLib\lib)
to your additional library path

3) do NOT specify any QuantLib library to link to - this is handled
automatically

4) enable RTTI under C/C++, C++ Language

- compile & let me know if you're still having trouble.

> Regards and thanks for your help.

Hope we can figure it out.

Regards
Eric