0
votes

Updated: main.h

typedef struct
{
    float x;
    float y;
    float z;
}vec3;
const int sizeOfGrid = 20000;
vec3 *grid[sizeOfGrid];//assume initialized

main.cpp

#include "main.h"
extern "C" void cudaTranslate(vec3 *x);
void display()
{
    cudaTranslate(grid);
}

lineCuda.cu

#include <stdio.h>
#include <assert.h>
#include <cuda.h>
#include "main.h"

extern "C" void cudaTranslate(vec3 *x)
{

}

getting:
main.obj : error LNK2005: "struct vec3 * * grid" (?grid@@3PAPAUvec3@@A) already defined in lineCuda.obj
fatal error LNK1169: one or more multiply defined symbols found

2
What did you try, and how did it fail so far? I can't see any obvious problems with your current approach.Lightness Races in Orbit
You should put the struct definition in a header and #include it from both the .cpp and .cu files.Jeremiah Willcock
@Tomalak: I'm not sure the poster realized that they should have the struct definition included in both files; that was what I was pointing out.Jeremiah Willcock
Your declarations of the argument type of cudaTranslate don't match. (One is vec3*, the other is just vec3.)Kristopher Johnson
@Ninja: Try making sizeOfGrid static. I do not remember if int constants are automatically (I think so).Jeremiah Willcock

2 Answers

2
votes

Move grid to main.cpp. Pass it to lineCuda.cu. Problem solved.

Updated: main.h

typedef struct
{
    float x;
    float y;
    float z;
}vec3;
const int sizeOfGrid = 20000;

main.cpp

#include "main.h"
vec3 *grid[sizeOfGrid];//assume initialized
extern "C" void cudaTranslate(vec3 *x);
void display()
{
    cudaTranslate(grid);
}
0
votes

You could make this a lot simpler by removing extern "C" everywhere and just use C++ bindings.

Having said that, you actually have a multiply defined symbol grid because you are including the file main.h in two translation units. Move the line vec3 *grid[sizeOfGrid] to main.cpp.