我在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和我的作品。感谢您的回复。