I have a problem with make a dll on Visual Studio 2013. This code works on Code::Blocks. The error was 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)
. How to fix it?
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__
And the second file:
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
}
}
I tried to fix it, but I have no more idea. When I changed the prim function in second file from definition to the declaration, the dll was compile without errors, but without the code responsible for the implementation of the algorithm.
Thanks for all replies.
Edit:
I add temporary #define BUILD_DLL to main.h and later in Cmake and I works. Thanks for replies.