这对我来说很奇怪。
inline complex_t complex_add(complex_t a, complex_t b)
{
complex_t r = {a.re + b.re, a.im + b.im};
return r;
}
inline complex_t complex_subtract(complex_t a, complex_t b)
{
complex_t r = {a.re - b.re, a.im - b.im};
return r;
}
inline complex_t complex_multiply(complex_t a, complex_t b)
{
complex_t r = {a.re * b.re - a.im * b.im, a.re * b.im + a.im * b.re};
return r;
}
inline complex_t complex_conjugate(complex_t a)
{
complex_t r = {a.re, -a.im};
return r;
}
inline complex_t complex_divide(complex_t a, complex_t b)
{
float dem = b.im * b.im + b.re * b.re;
complex_t r = complex_multiply(a, complex_conjugate(b));
r.re /= dem;
r.im /= dem;
return r;
}
int divergence(double x, double y, int iters, complex_t* r)
{
const complex_t c = {x, y};
complex_t z = {0, 0};
int i;
for(i = 0; i < iters && complex_mag(z) < 2; i++)
{
z = complex_add(complex_multiply(z, z), c);
}
*r = z;
return i;
}
编译此代码时,我在行z = complex_add(complex_multiply(z, z), c)
...
home/chase/workspace/MandelbrotSet/Debug/../main.c:62: undefined reference to `complex_multiply'
makefile:44: recipe for target 'MandelbrotSet' failed
/home/chase/workspace/MandelbrotSet/Debug/../main.c:62: undefined reference to `complex_add'
collect2: error: ld returned 1 exit status
make: *** [MandelbrotSet] Error 1
然而,当我从复数函数中删除内联时,代码编译得很好。有什么想法吗?如何添加内联使编译器无法找到该函数?