我已经在Visual Studio中为我的控制台应用程序创建了一个DLL。在我的DLL中,我有一个名为Dialog_MainMenu的类,它有一个*.cpp文件和一个*.h文件。
以下是错误信息:
错误 9 错误 LNK2001:未解析的外部符号“__declspec(dllimport)public:static enum Dialog_MainMenu :: GAME_STATES Dialog_MainMenu :: CurrentGameState”(_imp?CurrentGameState@Dialog_MainMenu@@2W4GAME_STATES@1@A)C:\Users\Kevin\Desktop\c++ projects\development_testing\The Intense Adventure\Dialogs\Dialog_MainMenu.obj Dialogs
我有点不理解这个错误。当我在头文件中添加一个枚举时才会出现这种情况。
头文件:
以下是错误信息:
错误 9 错误 LNK2001:未解析的外部符号“__declspec(dllimport)public:static enum Dialog_MainMenu :: GAME_STATES Dialog_MainMenu :: CurrentGameState”(_imp?CurrentGameState@Dialog_MainMenu@@2W4GAME_STATES@1@A)C:\Users\Kevin\Desktop\c++ projects\development_testing\The Intense Adventure\Dialogs\Dialog_MainMenu.obj Dialogs
我有点不理解这个错误。当我在头文件中添加一个枚举时才会出现这种情况。
头文件:
#ifdef DIALOG_MAINMENU_EXPORTS
#define DIALOG_MAINMENU_API __declspec(dllexport)
#else
#define DIALOG_MAINMENU_API __declspec(dllimport)
#endif
class Dialog_MainMenu {
public:
static DIALOG_MAINMENU_API enum GAME_STATES {
MAINMENU, GAME, OPTIONS, CREDITS, QUIT
};
static DIALOG_MAINMENU_API GAME_STATES CurrentGameState;
DIALOG_MAINMENU_API GAME_STATES GetState();
};
我不确定问题是否在这里,所以我只是添加一下。 cpp文件通常指:
//Get state
Dialog_MainMenu::GAME_STATES Dialog_MainMenu::GetState() {
// Code..
}
//Switching state
Dialog_MainMenu::CurrentGameState = Dialog_MainMenu::GAME_STATES::GAME;
我真的很感激任何帮助或至少一些建议,让我能够更多地了解这个问题。
enum GAME_STATES
中不需要使用static
和DIALOG_MAINMENU_API
。 - greatwolf