0

I work with VC++6 and I want to use complex power function (pow()) in one of my self-made function. I wrote my necessary functions in a header file (.h).

Here is my function in the header file:

    #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;
                    }
                }
            }   
        }
    }

}

Without putting this line: fn_r *= std::pow(immm,ipow) , everything works fine and the project correctly compiles. But when i try to put this line, or using exp() or log() function compiling fails with this errors:

    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

I also tried to use the expression exp(ipow*log(immm)) instead of power function, but it also fails with the same error. I tried to use this function (pow()) in a simple code in visual studio 2016,it works fine and it's just okay to consider #include <complex> in the first lines of the header.

Do you have any idea? Any help will be appreciated.

  • Function *definition* in a header file? Can certainly be done, but requires some precautions. Have you considered perhaps wrapping said function in an anonymous namespace to keep the many definitions apart? Also, any special reason not to *declare* the function in the header as `extern` and *define* it in some `.cpp` (`.cxx`, `.C` ...) file? – 0xC0000022L Apr 17 '18 at 07:17
  • Visual Studio 6 and its C++ compiler is ***old***, really *ancient*. And not fully standard compliant (it came out in 1998, the same year C++ was first standardized). Don't expect anything in the `std` namespace to work as expected (or at all). – Some programmer dude Apr 17 '18 at 07:17
  • 1
    *VC++6* remind me is that from Jurassic or Cretaceous? – n. m. could be an AI Apr 17 '18 at 08:14
  • yeah it is very old! but for some reason i have to work with it :( – fatemeh.rastegar Apr 18 '18 at 08:17

0 Answers0