I have the following code structure composed of one .cpp, one .cu and one .hxx
UTILITIES.hxx
#ifndef UTILITIES_HXX
#define UTILITIES_HXX
namespace B{
extern int doors;
}
FILE2.cu
#include "utilities.hxx"
namespace A {
int foo (){
switch(B::doors){
//do something
}
}
}
FILE3.cxx
#include "utilities.hxx"
namespace B{
int doors=-1;
class Vehicle{
public:
void operation() {
doors++;
A::foo();
doors++;
A::foo();
}
}
}
I am declaring the doors variable as extern in the header and I am defining it in the .cxx file. So after that, the second .cpp should be able to use it. However I am getting the following error when linking:
/usr/bin/ld: ../src/libapp.a(FILE2.cu.o): in function A::foo(void)': /MYPATH/FILE2.cu:19: undefined reference to
B::doors'
What am I doing wrong? Actually the foo function in the FILE2.cu is a normal C++ function, no CUDA involved at all.