所以我有一个问题。 我已经阅读了很多东西,但似乎没有什么对我有用。
我有这个 C 库,我用文件制作了项目:
//send.h
#ifndef SEND_H
#define SEND_H
#ifdef __cplusplus
extern "C" {
#endif
static int Send_Sample(void);
#ifdef __cplusplus
}
#endif
#endif /* SEND_H */
我有
//send.c
#include "thatLibrary.h"
static int Send_Sample(void)
{ return 0; }
所以我将项目创建为空 DLL,然后我构建了它,一切正常。 但是当我制作另一个项目并在其中引用这个项目时,我会这样做
#include "send.h"
这个包含正在工作,他看到那个 .h 文件,但是当我构建另一个项目时,它说:
Error C2129 static function 'int Send_Sample(void)' declared but not defined AzureEventHubClient c:\users\v-vlvesi\documents\github\azureeventhubclibrary\azureeventhubclient\source.cpp 9
有谁知道如何解决这个问题?
谢谢!
最佳答案
“static”关键字实际上阻止了函数从 DLL 中导出。您还必须使用 dllimport 和 dllexport。
关于如何检测您的代码,您可以引用之前的回答:Exporting functions from a DLL with dllexport
关于c++ - 在 C++ 项目中使用 C DLL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40425318/