forum.alglib.net

ALGLIB forum
It is currently Sun Aug 14, 2022 4:03 pm

All times are UTC


Forum rules


1. This forum can be used for discussion of both ALGLIB-related and general numerical analysis questions
2. This forum is English-only - postings in other languages will be removed.



Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: C++ Library conflict
PostPosted: Wed Sep 22, 2010 1:57 pm 
Offline

Joined: Wed Sep 22, 2010 1:52 pm
Posts: 5
I am having difficulties of getting ALGIB to work with my program in C++

The problem I am getting is that the library is conflicting with a default library, I did omit the default library but that caused problems with external symbol errors.

Code:
1>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: static unsigned int __cdecl std::char_traits<char>::length(char const *)" (?length@?$char_traits@D@std@@SAIPBD@Z) already defined in libalglib.lib(spline1d.obj)

1>C:\TestModel\Debug\TestModel.exe : fatal error LNK1169: one or more multiply defined symbols found


The compiler I am using is MSVC 2008 Express edition

Any help is greatly appreciated


Top
 Profile  
 
 Post subject: Re: C++ Library conflict
PostPosted: Wed Sep 22, 2010 2:23 pm 
Offline
Site Admin

Joined: Fri May 07, 2010 7:06 am
Posts: 878
Strange, I haven't seen such error before and can't reproduce it. I think that it is machine-specific. Maybe you have several versions of MSVC installed?

However, there is simple solution to your problem - try to use ALGLIB 3.0.

2.x branch includes 104 units. It is intended to be built using build.bat script (which you actually did, I suppose). ALGLIB 3.x includes 14 units (those 104 merged together), and it is very easy to attach these 14 units (in your case - even less, because you seem to need only splines) to your project. You will solve all problems with stdlib conflicts.

You can download Release Candidate 1 from website. Alternatively I can send you last Release Candidate (RC2, which is not publicly accessible yet). It is somewhat better tuned, than RC1.


Top
 Profile  
 
 Post subject: Re: C++ Library conflict
PostPosted: Wed Sep 22, 2010 2:53 pm 
Offline

Joined: Wed Sep 22, 2010 1:52 pm
Posts: 5
I've downloaded the 3.x version, I noticed the .lib file has been removed, my project compiles fine now with the "interpolation.h" header in it - thanks for your help, it is really appreciated

I was wondering, is there a demo of how to build a cubic spline interpolation?


Top
 Profile  
 
 Post subject: Re: C++ Library conflict
PostPosted: Wed Sep 22, 2010 4:48 pm 
Offline
Site Admin

Joined: Fri May 07, 2010 7:06 am
Posts: 878
Demos creation undergone complete rewrite in 3.x branch, so I've to implement demos one more time, but using another set of tools. So there are no demos for splines in 3.x branch, but there are demos in 2.6 release :) You can browse "/examples" directory from 2.6 archive. Demos relates to splines start with "_demo_spline1d" prefix.

There were some subtle changes, so you can't compile them with 3.x. But fix will be easy, and in any way you will get general understanding of spline1d subpackage.

Note: there is some new functionality in 3.x - spline1dgriddiff, spline1dconv and spline1dconvdiff - which is not mentioned in pre-3.x docs. If you don't understand something, feel free to ask here.


Top
 Profile  
 
 Post subject: Re: C++ Library conflict
PostPosted: Mon Sep 27, 2010 10:39 am 
Offline

Joined: Wed Sep 22, 2010 1:52 pm
Posts: 5
I am very new to ALGLIB so I will need some help in starting off, I've added interpolation.h to my project and what I want to do is to interpolate two values from two arrays and get a result

I have been looking through the demos of the old builds and replaced ap:: syntax with alglib::

At the moment I am getting 9 compiler errors like
Code:
>TestModel.obj : error LNK2019: unresolved external symbol "public: virtual __thiscall alglib::real_1d_array::~real_1d_array(void)" (??1real_1d_array@alglib@@UAE@XZ) referenced in function "void __cdecl splinalInterpolation(int,char * *)" (?splinalInterpolation@@YAXHPAPAD@Z)


All the other errors are similar, the editor/compiler I am using is MS Visual C 2008 Express

Here is a snipped of my code as well...

Code:
    alglib::real_1d_array x;
    alglib::real_1d_array y;
    int n;
    int i;
    alglib::spline1dinterpolant c;
    double err;
    double maxerr;


    //
    // Create spline
    //
    n = 3;
    x.setlength(n);
    y.setlength(n);
    for(i = 0; i <= n-1; i++)
    {
        x(i) = alglib::pi()*i/(n-1);
        y(i) = sin(x(i));
    }

alglib::spline1dbuildlinear(x, y, n, c);


Top
 Profile  
 
 Post subject: Re: C++ Library conflict
PostPosted: Mon Sep 27, 2010 4:39 pm 
Offline
Site Admin

Joined: Fri May 07, 2010 7:06 am
Posts: 878
Looks like you've forgot to add some units to your project, in particular ap.cpp. If not, can you post here zip archive with your project?


Top
 Profile  
 
 Post subject: Re: C++ Library conflict
PostPosted: Tue Sep 28, 2010 9:36 am 
Offline

Joined: Wed Sep 22, 2010 1:52 pm
Posts: 5
Thanks, it now compiles, abet without warnings from the compiler...

I added the following for interpolation.h

Code:
#include "ap.cpp"
#include "alglibinternal.cpp"
#include "alglibmisc.cpp"
#include "integration.cpp"
#include "interpolation.cpp"
#include "linalg.cpp"
#include "optimization.cpp"
#include "solvers.cpp"
#include "specialfunctions.cpp"


I thought I give you the heads up on the type of warnings I am receiving, they are not causing me any problems at the moment, there are at least sixteen of the same warnings popping up

Code:
1>c:\testmodel\src\ap.cpp(2979) : warning C4996: 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>        c:\program files\microsoft visual studio 9.0\vc\include\stdio.h(366) : see declaration of 'sprintf'


Thank you for your support, it is greatly appreciated


Top
 Profile  
 
 Post subject: Re: C++ Library conflict
PostPosted: Tue Sep 28, 2010 12:35 pm 
Offline
Site Admin

Joined: Fri May 07, 2010 7:06 am
Posts: 878
Thanks for the report. I've added pragmas to stop these warnings.

Actually, there is nothing wrong in using sprintf() with caution. From the other side, we can't use sprintf_s() because it is Microsoft-specific; it can't be used with GCC or Sun Studio. So the only thing which can be done is suppression of these irrelevant warnings.


Top
 Profile  
 
 Post subject: Re: C++ Library conflict
PostPosted: Wed Sep 29, 2010 2:22 pm 
Offline

Joined: Wed Sep 22, 2010 1:52 pm
Posts: 5
There is one final (I hope) question, I need to output the results into an array, the output parameter is C, but I get a compiler error, can you explain how to get the results into an array?


Top
 Profile  
 
 Post subject: Re: C++ Library conflict
PostPosted: Wed Sep 29, 2010 4:18 pm 
Offline
Site Admin

Joined: Fri May 07, 2010 7:06 am
Posts: 878
There is no easy way to do such conversion (alglib::real_1d_array => double[N]).

However, you can use temporary output variables and copy data from ALGLIB array into C array using alglib::vmove() function.

P.S. I plan to implement some kind of automatic conversion between ALGLIB arrays and C arrays, but it will wait at least for the next release.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group