error C2491: 不允許 dllimport 函數 的定義


轉載:https://blog.csdn.net/gaofeidongdong/article/details/7781345

在工程屬性中 預編譯宏中加上 DLL_EXPORT
為了減少使用dll時候的設置或者代碼編寫,把dll.h修改一下:
#ifndef DLL_EXPORT
#define DECLDIR __declspec(dllimport)
#else
#define DECLDIR __declspec(dllexport)
#endif
dll實現代碼:
#include "stdafx.h"
#include <iostream>
#define DLL_EXPORT //先定義宏
#include "dll.h"//這個頭文件必須在#define DLL_EXPORT后面
extern "C"{
DECLDIR int Add( int a, int b )
{
return( a + b );
}
DECLDIR void Function( void )
{
std::cout << "DLL Called!" << std::endl;
}
}
這樣編譯后,使用dll的工程中就不需要定義和dll相關的宏了
————————————————
版權聲明:本文為CSDN博主「fisher」的原創文章,遵循CC 4.0 BY-SA版權協議,轉載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/gaofeidongdong/article/details/7781345


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM