Hello,
Iam trying to compile a example from “CUDA by Example”.
include “common/book.h”
include “common/cpu_bitmap.h”
define DIM 1000
struct cuComplex
{
float r;
float i;
cuComplex(float a, float b) : r(a) , i(b) {}
__device__ float magnitude2 (void)
{
return r*r+i*i;
}
__device__ cuComplex operator*(const cuComplex &a)
{
return cuComplex(r*a.r - i*a.i , i*a.r + r*a.i);
}
__device__ cuComplex operator+(const cuComplex &a)
{
return cuComplex(r+a.r, i+a.i);
}
};
device int julia( int x, int y)
{
const float scale = 1.5;
float jx = scale* (float)(DIM/2-x)/(DIM/2);
float jy = scale* (float)(DIM/2-y)/(DIM/2);
cuComplex c(-0.8, 0.156);
cuComplex a(jx,jy);
for(int i=0; i < 200; i++)
{
a = a*a + c;
if(a.magnitude2() > 1000)
return 0;
}
return 1;
}
global void kernel( unsigned char *ptr)
{
int x = blockIdx.x;
int y = blockIdx.y;
int offset = x+y * gridDim.x;
int juliaValue = julia(x,y);
ptr[offset*4+0] = 255 * juliaValue;
ptr[offset*4+1] = 0;
ptr[offset*4+2] = 0;
ptr[offset*4+3] = 255;
}
int main ()
{
CPUBitmap bitmap (DIM, DIM);
unsigned char *dev_bitmap;
HANDLE_ERROR( cudaMalloc( (void**) &dev_bitmap, bitmap.image_size() ) );
dim3 grid(DIM,DIM);
kernel<<<grid,1>>>( dev_bitmap );
HANDLE_ERROR( cudaMemcpy (bitmap.get_ptr(), dev_bitmap, bitmap.image_size(), cudaMemcpyDeviceToHost ) );
bitmap.display_and_exit();
cudaFree (dev_bitmap);
}
Iam trying to compile it via:
nvcc -o julia_set julia_set.cu
Then i resolved that error:
julia_set.cu
tmpxft_000009b0_00000000-3_julia_set.cudafe1.gpu
tmpxft_000009b0_00000000-8_julia_set.cudafe2.gpu
julia_set.cu
tmpxft_000009b0_00000000-3_julia_set.cudafe1.cpp
tmpxft_000009b0_00000000-14_julia_set.ii
tmpxft_000009b0_00000000-15_julia_set.obj : error LNK2019: unresolved external s
ymbol ___glutInitWithExit@12 referenced in function _glutInit_ATEXIT_HACK@8
tmpxft_000009b0_00000000-15_julia_set.obj : error LNK2019: unresolved external s
ymbol ___glutCreateWindowWithExit@8 referenced in function _glutCreateWindow_ATE
XIT_HACK@4
julia_set.exe : fatal error LNK1120: 2 unresolved externals
I allready installed glut. How can i fix that problem?
You’re missing some library file. Are there any library files that come with the book? Or maybe you need to ensure that the glut library in your system is linked.
I didn’t find any libary with the book. How i can link that glut stuff?
One way is to look in the directories (bin, lib) and copypaste both the glut32.dll , glut32.lib into the chapter04 directory. This inelegant method works - I know!
Perhaps someone can tell me the proper way of doing this