我已经做了一切,根据MSDN文档,但我的功能仍然没有导出。LINK1 LINK2 LINK3
下面是我所拥有的(从DLL导入的2个项目、dll和App ),如下所示(简写):
DLL函数.h
#prgma once
#ifdef COMPILE_DLL
#define EXPORT __declspec(dllexport)
#else
#define EXPORT __declspec(dllimport)
#endif // COMPILE_DLL
namespace wsl
{
EXPORT bool PointInTriangle(int x1, int y1, int x2, int y2, int x3, int y3, int x, int y);
}DLL functions.cpp
#include "functions.h"
namespace wsl
{
bool PointInTriangle(int x1, int y1, int x2, int y2, int x3, int y3, int x, int y)
{
// implementation...
return true;
}
}DLL dllmain.cpp
#include <Windows.h>
BOOL APIENTRY DllMain(
[[maybe_unused]] HMODULE hModule,
DWORD ul_reason_for_call,
[[maybe_unused]] LPVOID lpReserved)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}注意:项目中还有其他几个头文件和cpp文件,它们都正在编译,但没有导出函数。
应用程序main.cpp
#include "functions.h"
int main()
{
wsl::PointInTriangle(0, 0, 20, 0, 10, 30, 10, 15);
return 0;
}程序输出:
2>main.obj : error LNK2019:未解析的外部符号"__declspec(dllimport) bool __cdecl wsl::PointInCircleSector(int,float,float)“(__imp_?PointInCircleSector@wsl@@YA_NHHHMM@Z) --在函数main 2>main.obj : error LNK2019:未解析的外部符号"__declspec(dllimport) bool __cdecl wsl::PointIn三角( int,int)中引用的(__imp_?PointInTriangle@wsl@@YA_NHHHHHHHH@Z)函数main 2>main.obj : error LNK2019:未决外部符号"__declspec(dllimport) bool __cdecl wsl::PointInEllipse(int,int)“(__imp_?PointInEllipse@wsl@@YA_NHHHHHH@Z)在函数main 2>main.obj : error LNK2019:未解析外部符号"__declspec(dllimport) bool __cdecl wsl::PointIn圆环( int,int)”中引用。(__imp_?PointInCircle@wsl@@YA_NHHHHH@Z)“( 2>main.obj )函数中引用的:错误LNK2019:未解析的外部符号"__declspec(dllimport) bool __cdecl wsl::PointInRect角度( int,int,在函数main 2>C:\Users\User\source\repos\WindowsSuperLibrary\x64\Debug DLL\MathSample.exe中引用的int)“(__imp_?PointInRectangle@wsl@@YA_NHHHHHH@Z):致命错误LNK1120: 5未解决的外部环境2>Done构建项目"MathSample.vcxproj”--失败。
你能解释一下这里有什么问题吗?
我已经对dll运行了dumpbin /EXPORTS,并且可以确认没有导出任何函数。
COMPILE_DLL宏当然是在dll项目中定义的。
我确实在我的项目中包括了导入库。
名称空间名称在头文件和cpp文件中都是相同的。
发布于 2019-09-22 12:36:46
为了实际导出DLL源文件中声明的函数,必须执行以下两项操作之一:
或者(1)将__declspec(dllexport)属性添加到定义的源中的函数中(而不仅仅是在标头中)。
或者(2)将函数添加到模块定义文件(.def)中的.def列表中。
可用的文档(特别是旧文档)倾向于假设使用.def文件EXPORTS方法,并且可能会产生很大的误导性。
https://stackoverflow.com/questions/58049045
复制相似问题