我在Visual Studio 2013上創建DLL時出現問題。此代碼可用於Code :: Blocks。錯誤是definition of dllimport function not allowed" on line void DLL_EXPORT prim(map<string, vector<int>> nodes, map<pair<string, string>, pair<int, string>> edges)
。如何解決它?錯誤C2491:不允許使用dllimport函數的定義
main.h:
#ifndef __MAIN_H__
#define __MAIN_H__
#include <windows.h>
#include <iostream>
#include <vector>
#include <map>
using namespace std;
#ifdef BUILD_DLL
#define DLL_EXPORT __declspec(dllexport)
#else
#define DLL_EXPORT __declspec(dllimport)
#endif
#ifdef __cplusplus
extern "C"
{
#endif
void DLL_EXPORT prim(map<string,vector<int>> nodes, map<pair<string,string>,pair<int,string>> edges);
#ifdef __cplusplus
}
#endif
#endif // __MAIN_H__
第二個文件:
main.cpp:
#include "main.h"
//some other includes
// a sample exported function
extern "C"
{
void DLL_EXPORT prim(map<string, vector<int>> nodes, map<pair<string, string>, pair<int, string>> edges)
{
//some code
}
}
我試圖修復它,但我沒有更多的想法。當我將第二個文件中的prim函數從定義更改爲聲明時,dll編譯時沒有錯誤,但沒有代碼負責執行算法。
感謝您的回覆。
編輯:
我添加臨時的#define BUILD_DLL到main.h後來在CMake和我的作品。感謝您的回覆。