Dec 8, 2012

openSUSE Forums: Linking quadmath with C++

openSUSE Forums
openSUSE Forums
Linking quadmath with C++
Dec 8th 2012, 19:32

I have an example code:
Code:

#include <quadmath.h>
int main()
{
    __float128 foo=123;
    cosq(foo);
    return 0;
}

I tried to compile it with the following commands:

Code:

g++ f128.cpp -lquadmath
g++ f128.cpp /usr/lib64/gcc/x86_64-suse-linux/4.6/libquadmath.a
g++ f128.cpp /usr/lib64/gcc/x86_64-suse-linux/4.6/libquadmath.a /usr/lib64/libquadmath.so.0
g++ f128.cpp /usr/lib64/gcc/x86_64-suse-linux/4.6/libquadmath.a /usr/lib64/libquadmath.so.0 /usr/lib64/gcc/x86_64-suse-linux/4.6/libquadmath.a

All these commands produce one and the same error:
Code:

f128.cpp:(.text+0x1b): undefined reference to `cosq(__float128)'
I also tried to declare cosq as follows, without inluding quadmath.h. Declarations of such style are used in C++ interface to fortran subroutines in other programs, and they work well.

Code:

extern "C" __float128 cosq_(__float128 *op);
extern "C" __float128 cosq_(__float128 op);
extern "C" __float128 cosq(__float128 *op);
...and so on...

Result was the same.
Then I tried to use cosq in Fortran:
Code:

PROGRAM test
          REAL*16 foo
          REAL*16 res
          foo=1;
          res=cos(foo)
        PRINT *,res
END

This program compiles and executes well (prints the answer with lots of digits), so cosq works in it. This program was compiled with no options: gfortran f128.f90.

I tried OpenSUSE 12.1 with gcc 4.6.2 and OpenSUSE 12.2 with gcc 4.7.1. *.h, *.a and *.so files mentioned are provided by gcc46-fortran and libquadmath46 packages.
All needed include files and libraries exist, linker doesn't print any nonexistance errors.

What is the proper way to use cosq and other quadmath functions in C++?
I wouldn't like to write Fortran wrappers for them.

You are receiving this email because you subscribed to this feed at blogtrottr.com.

If you no longer wish to receive these emails, you can unsubscribe from this feed, or manage all your subscriptions

No comments: