Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29258 Discussions

Calling FORTRAN zcos function from C++

ids-removed295
Beginner
1,091 Views
I am attempting to call the ifort zcos function from a C++ main program. For functions that are in libraries I am able to use the technique...
extern "C" MYFUN()
...
MYFUN()
within my C++ code, where MYFUN is a fortran routine in a FORTRAN library. The zcos function, however, appears to be a "builtin" intrinsics and thus keeps coming up as unresolved with this technique.
Any advice or example, greatly appreciated.
Beau Paisley
0 Kudos
4 Replies
Steven_L_Intel1
Employee
1,091 Views
I don't quite understand what you are doing. Are you writing a Fortran function that calls ZCOS? (CDCOS is the preferred name for this function). It should not matter that it is "builtin". Or are you trying to call the math routine directly from C++? Note that this routine returns a double complex result, and Fortran functions that do this pass a hidden first argument for the result.
0 Kudos
ids-removed295
Beginner
1,091 Views
I am writing a C++ function that call the ZCOS, (or DCOS, same problem).
e.g. from within my C++ function
extern "C" ZCOS(double *);
...
ZCOS(&d);
and then link against libm.lib, but ZCOS comes up as undefined, and I suspect it is because it is not actually in any of the fortran libraries. It's built in.
Beau
0 Kudos
ids-removed295
Beginner
1,091 Views
This all is an artifact of the z_cos, z_sin, etc. functions being removed from the Intel compiler at version 8. If the fortran-based source code is available, or you know of such I can just compile and link in my own.
Beau
0 Kudos
Steven_L_Intel1
Employee
1,091 Views
No, the routines were not removed. The ZCOS intrinsic is still supported. However, the name of the external routine it calls is _ccos. Calling the math library routines directly is not supported, and the names can change without notice.

As I noted, ZCOS is an alternate spelling of CDCOS. You could write your own routine as follows:

complex(8) function zcos (arg)
complex(8), intent(in) :: arg
zcos = cdcos(arg)
return
end

You would have to call this from C++ as:

zcos (&result, &arg);
0 Kudos
Reply