0
私は、Visual Studioを使用していますし、クラスA
でこのように動作しますいくつかのC++のコードに取り組んでいます:のdllexportクラスの静的メソッド
class A
{
public:
//......
static void foo();
};
クラスB
がエクスポートされます:
class __declspec(dllexport) B
{
public:
//...
void bar()
{
A::foo();
}
};
A
とB
がありますAB.dll(およびAB.lib)にコンパイルされます。
class __declspec(dllimport) B
{
public:
//...
void bar()
{
A::foo();
}
};
まず:あなたが言うファイルヘッダときに、私はコードがあったと仮定し
int main()
{
B b;
b.bar();
return 0;
}
When compiling the main program and linking it to AB.lib,
it complains about the A::foo() as unresolved external symbol
(in this case A::foo is a static function).
Do I need to somehow export A::foo() or could it be that
I introduce errors somewhere? Any help is appreciated.
Modified:
1) Sorry for the type, it should be dllexport, not dllimport
2) in my actual project, the implementation is in .cpp files. They are not inline functions.
Thanks.
http://stackoverflow.com/questions/35048940/what-dis-cis-c-class-declaration-meanへの回答が役立つかもしれません。 –
'B :: bar'の実装をソースファイルに置きます。エクスポートしないでください。 'A'が' B'のソースでのみ使用されている場合は、エクスポートする必要はありません。 –
リンカーにB :: bar()を解決する2つの方法を与えます。 .hファイルの定義を使用することも、AB.libの定義を使用することもできます。それは結論です。.objファイルに存在するので、.hファイルのものが常に好きです。今度はA :: foo()を解決する必要があります。フェイル・クジラ、AB.libにはそれがありません。 .hファイルの定義を削除し、コンパイラが使用できないように.cppファイルに移動する必要があります。 –