0

nvccを使用して次の問題が発生しました。別のコンパイルを使用して(最終的にcmake__device__ __constant__ (extern) type1<type2> var[length]で実行しました)、配列の宣言で問題が発生しました。

これが私のヘッダーです:

#include <type.h>
#include <type2.h>

#ifndef GUARD_H_
#define GUARD_H_

namespace NameSpace1{
  namespace NameSpace2{

    namespace Constants{
      __device__ __constant__ extern Type1<Type2> array[10];
      __device__ Type1<Type2> accessConstantX(size_t index);
    }
  }
}
#endif

そして彼女の私の.cuファイル:

#include <header.h>
#include <assert.h>

namespace NameSpace1{
  namespace NameSpace2{

    namespace Constants{
      __device__ Type1<Type2> accessConstantX(size_t index){
    assert(index <= 9);
    return array[index];
      }
    }
  }
}

中間の個別のコンパイル手順で次のエラーが発生します。

nvlink error   : Undefined reference to '_ZN12NameSpace115NameSpace29Constants17arrayE'

これは、.cuファイルへのアクセスが原因です。提案をありがとう。

4

1 に答える 1

1

この投稿を読んで、自分の間違いが何であるかを知りました。ヘッダー ファイルでグローバル変数を正しく宣言する方法を理解していないことがわかりました。私の問題はnvccとは何の関係もありませんでした。答えを探す方向に私を指摘してくれた@talonmiesに感謝します。

ここに私の問題の解決策があります:

これが私のヘッダーです:

#include <type.h>
#include <type2.h>

#ifndef GUARD_H_
#define GUARD_H_

namespace NameSpace1{
  namespace NameSpace2{

    namespace Constants{
      extern __device__ __constant__ extern Type1<Type2> array[10];
      __device__ Type1<Type2> accessConstantX(size_t index);
    }
  }
}
#endif

そして彼女の私の.cuファイル:

#include <header.h>
#include <assert.h>

namespace NameSpace1{
  namespace NameSpace2{

    namespace Constants{
      __device__ __constant__ Type1<Type2> array[10];
      __device__ Type1<Type2> accessConstantX(size_t index){
        assert(index <= 9);
        return array[index];
      }
    }
  }
}
于 2013-02-03T15:19:30.213 に答える