[C++-11] Compilation errors on examples

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

[C++-11] Compilation errors on examples

Marco Craveiro
Hi QuantLib,

Just for fun I decided to have a go at compiling trunk (r18307) with GCC 4.7 in C++-11 mode. To my surprise it pretty much compiled OK - except for the examples, where I got the error I attach at the end of the email. I must apologise if this has already been discussed in the list but I'm really struggling to search it properly from either SourceForge, Nabble or GMane - consistently get no relevant matches. My questions are:

- has anyone succeeded in compiling QuantLib C++-11 (e.g. there is a patch somewhere for this problem)? I am linear-searching the archives but haven't bumped into anything as of yet.
- I noticed there is a enable-examples flag in configure but this seems to only have an impact distribution-wise; is there way of not compiling the examples (or just the experimental examples even)?

Many thanks for your time.

Marco
-- 
So young, and already so unknown -- Pauli

blog: http://mcraveiro.blogspot.com

Error message:

g++-4.7 -DHAVE_CONFIG_H -I. -I../../ql  -I../.. -I../.. -isystem /usr/local/pfh/include  -isystem /usr/local/pfh/include -std=c++11 -MT CDS.o -MD -MP -MF .deps/CDS.Tpo -c -o CDS.o CDS.cpp
In file included from ../../ql/experimental/math/all.hpp:4:0,
                 from ../../ql/experimental/all.hpp:17,
                 from ../../ql/quantlib.hpp:42,
                 from CDS.cpp:20:
../../ql/experimental/math/autocovariance.hpp: In function ‘std::vector<std::complex<double> > QuantLib::detail::double_ft(ForwardIterator, ForwardIterator)’:
../../ql/experimental/math/autocovariance.hpp:47:78: error: no matching function for call to ‘transform(std::vector<std::complex<double> >::iterator, std::vector<std::complex<double> >::iterator, QuantLib::Array::iterator, <unresolved overloaded function type>)’
../../ql/experimental/math/autocovariance.hpp:47:78: note: candidates are:
In file included from /usr/local/pfh/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/algorithm:63:0,
                 from /usr/local/pfh/include/boost/smart_ptr/shared_ptr.hpp:41,
                 from /usr/local/pfh/include/boost/shared_ptr.hpp:17,
                 from ../../ql/errors.hpp:31,
                 from ../../ql/patterns/observable.hpp:29,
                 from ../../ql/event.hpp:29,
                 from ../../ql/cashflow.hpp:28,
                 from ../../ql/quantlib.hpp:10,
                 from CDS.cpp:20:
/usr/local/pfh/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/stl_algo.h:4897:5: note: template<class _IIter, class _OIter, class _UnaryOperation> _OIter std::transform(_IIter, _IIter, _OIter, _UnaryOperation)
/usr/local/pfh/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/stl_algo.h:4897:5: note:   template argument deduction/substitution failed:
In file included from ../../ql/experimental/math/all.hpp:4:0,
                 from ../../ql/experimental/all.hpp:17,
                 from ../../ql/quantlib.hpp:42,
                 from CDS.cpp:20:
../../ql/experimental/math/autocovariance.hpp:47:78: note:   could not resolve address from overloaded function ‘norm<QuantLib::Real>’



------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: [C++-11] Compilation errors on examples

Klaus Spanderen-2

Hi

 

I think the problem is that a program like

 

#include <complex>

int main() {

std::norm<double>;

}

 

does not compile with g++ version 4.7 if -std=c++11 is enabled. I don't know if this is a g++ bug for c++11 support.

 

We can solve the problem in QL by introducing our own norm function, which refers to the standard implementation like it is done in the attached files. I'm happy to submit these files but I want to get Luigi's feedback first whether he is a better solution for it, because mine is ugly;-)

 

There was another change needed in testsuite/cdo.cpp which I've already submitted to SVN.

 

regards

Klaus

 

 

 

 

 

 

On Wednesday, August 08, 2012 01:33:42 PM Marco Craveiro wrote:

Hi QuantLib,


Just for fun I decided to have a go at compiling trunk (r18307) with GCC 4.7 in C++-11 mode. To my surprise it pretty much compiled OK - except for the examples, where I got the error I attach at the end of the email. I must apologise if this has already been discussed in the list but I'm really struggling to search it properly from either SourceForge, Nabble or GMane - consistently get no relevant matches. My questions are:


- has anyone succeeded in compiling QuantLib C++-11 (e.g. there is a patch somewhere for this problem)? I am linear-searching the archives but haven't bumped into anything as of yet.

- I noticed there is a enable-examples flag in configure but this seems to only have an impact distribution-wise; is there way of not compiling the examples (or just the experimental examples even)?


Many thanks for your time.


Marco
-- 
So young, and already so unknown -- Pauli

blog: http://mcraveiro.blogspot.com


Error message:


g++-4.7 -DHAVE_CONFIG_H -I. -I../../ql  -I../.. -I../.. -isystem /usr/local/pfh/include  -isystem /usr/local/pfh/include -std=c++11 -MT CDS.o -MD -MP -MF .deps/CDS.Tpo -c -o CDS.o CDS.cpp

In file included from ../../ql/experimental/math/all.hpp:4:0,

                 from ../../ql/experimental/all.hpp:17,

                 from ../../ql/quantlib.hpp:42,

                 from CDS.cpp:20:

../../ql/experimental/math/autocovariance.hpp: In function ‘std::vector<std::complex<double> > QuantLib::detail::double_ft(ForwardIterator, ForwardIterator)’:

../../ql/experimental/math/autocovariance.hpp:47:78: error: no matching function for call to ‘transform(std::vector<std::complex<double> >::iterator, std::vector<std::complex<double> >::iterator, QuantLib::Array::iterator, <unresolved overloaded function type>)’

../../ql/experimental/math/autocovariance.hpp:47:78: note: candidates are:

In file included from /usr/local/pfh/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/algorithm:63:0,

                 from /usr/local/pfh/include/boost/smart_ptr/shared_ptr.hpp:41,

                 from /usr/local/pfh/include/boost/shared_ptr.hpp:17,

                 from ../../ql/errors.hpp:31,

                 from ../../ql/patterns/observable.hpp:29,

                 from ../../ql/event.hpp:29,

                 from ../../ql/cashflow.hpp:28,

                 from ../../ql/quantlib.hpp:10,

                 from CDS.cpp:20:

/usr/local/pfh/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/stl_algo.h:4897:5: note: template<class _IIter, class _OIter, class _UnaryOperation> _OIter std::transform(_IIter, _IIter, _OIter, _UnaryOperation)

/usr/local/pfh/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/stl_algo.h:4897:5: note:   template argument deduction/substitution failed:

In file included from ../../ql/experimental/math/all.hpp:4:0,

                 from ../../ql/experimental/all.hpp:17,

                 from ../../ql/quantlib.hpp:42,

                 from CDS.cpp:20:

../../ql/experimental/math/autocovariance.hpp:47:78: note:   could not resolve address from overloaded function ‘norm<QuantLib::Real>’






------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users

fastfouriertransform.cpp (4K) Download Attachment
autocovariance.hpp (7K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [C++-11] Compilation errors on examples

Joao Paulo Magalhaes-2
Hi Klaus,

I think your norm function should receive its parameter x by reference. I.e. in autocovariance.hpp:

        namespace {
            // patch for g++ verion 4.7 with -std=c++11 enabled
            inline Real norm(const std::complex<Real> &x) {
                return std::norm<Real>(x);
            }
        }

instead of:

        namespace {
            // patch for g++ verion 4.7 with -std=c++11 enabled
            inline Real norm(const std::complex<Real> x) {
                return std::norm<Real>(x);
            }
        }

Regards,
João


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: [C++-11] Compilation errors on examples

Marco Craveiro
Hi,

I think your norm function should receive its parameter x by reference

I've applied Klaus' patches with your fix  on top João and managed to get the code to compile across our build farm (FWIW: Linux 32 and 64-bit, OSX 32 and 64-bit and Windows 32-bit, all on GCC 4.7). We can now mess around with C++-11! Thanks a lot for your help. I attach the final patch in case its useful to anyone else.

Cheers

Marco
--
So young, and already so unknown -- Pauli

blog: http://mcraveiro.blogspot.com

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users

apply-klaus-changes.patch (4K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [C++-11] Compilation errors on examples

Luigi Ballabio
Marco,
    I've applied the changes in the attached patch instead (they
bypass the problem, avoid the helper function, and collapse two loops
into one).  May you try that it works?

Thanks,
    Luigi



On Mon, Aug 13, 2012 at 6:56 PM, Marco Craveiro
<[hidden email]> wrote:
> I've applied Klaus' patches with your fix  on top João and managed to get
> the code to compile across our build farm (FWIW: Linux 32 and 64-bit, OSX 32
> and 64-bit and Windows 32-bit, all on GCC 4.7). We can now mess around with
> C++-11! Thanks a lot for your help. I attach the final patch in case its
> useful to anyone else.

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users

fixes-for-gcc-4.7-in-C-11-mode.patch (4K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [C++-11] Compilation errors on examples

Marco Craveiro
Luigi,

thanks, I'll give that a spin in the next couple of days and report feedback.

Cheers,

Marco

On 3 September 2012 14:58, Luigi Ballabio <[hidden email]> wrote:
Marco,
    I've applied the changes in the attached patch instead (they
bypass the problem, avoid the helper function, and collapse two loops
into one).  May you try that it works?

Thanks,
    Luigi



On Mon, Aug 13, 2012 at 6:56 PM, Marco Craveiro
<[hidden email]> wrote:
> I've applied Klaus' patches with your fix  on top João and managed to get
> the code to compile across our build farm (FWIW: Linux 32 and 64-bit, OSX 32
> and 64-bit and Windows 32-bit, all on GCC 4.7). We can now mess around with
> C++-11! Thanks a lot for your help. I attach the final patch in case its
> useful to anyone else.



--
So young, and already so unknown -- Pauli

blog: http://mcraveiro.blogspot.com

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users