我使用VC ++ 6,我想在我的一个自制函数中使用复杂的幂函数(pow())。 我在头文件(.h)中编写了必要的函数。
这是头文件中的函数:
#include "MrServers/MrVista/Ice/IceIdeaFunctors/DllInterface.h"
// Base class:
#include "MrServers/MrVista/Include/Ice/IceUtils/IceImageReconFunctors.h"
#include "MrServers/MrVista/Include/Ice/IceUtils/IceUtils.h"
#include "MrServers/MrVista/Include/Ice/IceAlgos/IceWrapper.h"
// C++ class:
#include <vector>
#include <iostream>
#include <math.h>
#include <cmath>
#include <numeric>
#include <complex>
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
// #define ACC 40.0 //Make larger to increase accuracy.
// #define BIGNO 1.0e10
// #define BIGNI 1.0e-10
// #define PI 3.14159265
typedef std::vector <float> array_1d;
typedef std::vector <array_1d> array_2d;
typedef std::vector <array_2d> array_3d;
using namespace std;
IceWrapper myice;
...other function...
void Hankel_Transform(IceAs& dstAs, IceAs& srcAs, int M, int N, int nCha, int nPHS, float delta_r, float delta_rho, int r_range)
{
//parameters for Hankel Transform
//M: Number of samples on a spoke
//N: total number of orders
//rho: a 1D vector contains rho values (in source image)
//r: a 1D vector contains r values (for final image)
//r_range: length of vector r
double res = 0.005;
int z_ord = (int) N/2;
float pii = 3.14159265f; // f means float. to avoid error
array_3d bessel_table(N, array_2d(M, array_1d(r_range)));
// load "bessel_table" from PDS// (will be added later)
// load bessel_table
//array_2d bessel_table;
//bessel_table = read_bessel_txt();
// create pointer in order to access srcAs and dstAs
CMPLX *p_srcAs = (CMPLX*) srcAs.calcSplObjStartAddr();
CMPLX *p_dstAs = (CMPLX*) dstAs.calcSplObjStartAddr();
// Hankel Formula //
//int my_ind;
float my_j;
float r;
float rho;
complex<float> temp (0.0 , 0.0);
complex<float> fn_r (0.0 , 0.0);
complex<float> immm(0, 1);
float ipow =0.0f;
//CMPLX *temp;
//CMPLX *fn_r;
for (int phase = 0; phase < nPHS; phase++)
{ for(int ord = -(N/2); ord < (N/2); ord++) //lines
{ for(int nc = 0; nc < nCha; nc++) //channels
{ for(int rr = 0; rr < r_range; rr++) //columns
{
r=(float)(rr+1)*delta_r;
fn_r=complex<float>(0.0 , 0.0);
//fn_r -> re = 0;
//fn_r -> im = 0;
for(int rhoo = 0; rhoo < M; rhoo++)
{
rho = delta_rho/2 + (float)rhoo*delta_rho;
// to avoid redunduncy in calculation of besselj in cha and phase
if ( nc == 0 && phase == 0 )
{
my_j = bessj(ord , (float)(pii*rho*r));
bessel_table[ord+z_ord][rhoo][rr] = my_j;
}
else
{
my_j = bessel_table[ord+z_ord][rhoo][rr];
}
//my_ind = (int)floor((float)(pii*rho*r/res)); // should be "round" :(
//if(my_ind==0){my_ind=1;}
//my_j = bessel_table[ord+z_ord][my_ind-1]; // dar c++ andis ha az 0 shoru mishe!!
// bayad esme jadval "bessel_table" bashad!
temp = complex<float>(rho*my_j*p_srcAs->re , rho*my_j*p_srcAs->im);
fn_r += temp;
p_srcAs++;
}
ipow = (float)ord;
//ICE_OUT(std::pow<complex>(fn_r,2));
fn_r *= std::pow(immm,ipow); //exp(ipow*log(immm));//pow(immm,ipow);
p_dstAs->re = real(fn_r);
p_dstAs->im = imag(fn_r);
p_dstAs++;
if(rr != (r_range-1) )
{
p_srcAs -= M;
}
}
}
}
}
}
不放这一行:fn_r *= std::pow(immm,ipow)
,一切正常,项目正确编译。但是当我尝试放入这一行,或者使用exp()或log()时,函数编译失败并出现此错误:
IcePFTd_HankelFunctor.obj : error LNK2001: unresolved external symbol "struct _STL::complex<float> __cdecl _STL::pow(str
uct _STL::complex<float> const &,float const &)" (?pow@_STL@@YA?AU?$complex@M@1@ABU21@ABM@Z)
/n4/x86/prod/bin/IcePFTd.dll : fatal error LNK1120: 1 unresolved externals
make: *** [\n4\x86\prod/bin/IcePFTd.dll] Error 96
我还尝试使用表达式exp(ipow*log(immm))
而不是幂函数,但它也失败并出现相同的错误。
我尝试在visual studio 2016中的一个简单代码中使用此函数(pow()),它工作正常,可以在标题的第一行考虑#include <complex>
。