静态成员变量导出

时间:2013-04-29 13:32:48

标签: c++ visual-studio-2012 mfc

静态错误:

   in test1.dll:
    xxx.h
    class AFX_EXT_CLASS CTest1
    {
        static int num;
    }

    xxx.cpp
    int CTest1::num = 0;

    in a cpp of test2.dll: test2 is dependent test1.dll
    ...
    int i = CTest1::num;
    ...

    in a cpp of App: App is dependent test1.dll & test2.dll
    ...
    int i = CTest1::num;
    ...

在test2.dll中,静态上的“未解析的外部符号”:CTest1 :: num。 但在App中,没问题。

BTW:如果我使用CTest1的其他功能,没问题。

非常感谢,帮助我。

1 个答案:

答案 0 :(得分:0)

编译器正在剥离符号。您可以尝试__declspecimport。您还可以尝试extern变量并在另一个项目中创建人工参考。

相关问题