使用c DLL导入c++项目

Using c DLL into c++ project

本文关键字:c++ 项目 导入 DLL 使用      更新时间:2023-10-16

所以我有一个问题。我读了很多书,但似乎都不适合我。

我有这个C库,我用file:

做了一个项目
//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,然后我建立了它,它的ok。但是当我做了另一个项目,并引用了这个项目时,我做了

#include "send.h"

这个include正在工作,他看到。h文件,但是当我构建另一个项目时,它说:

Error   C2129   static function 'int Send_Sample(void)' declared but not defined    AzureEventHubClient c:usersv-vlvesidocumentsgithubazureeventhubclibraryazureeventhubclientsource.cpp 9   

有人知道如何解决这个问题吗?

谢谢!

'static'关键字实际上防止从DLL导出函数。您还必须使用dllimportdllexport

您可以参考前面的答案来了解如何检测您的代码:使用dlexport

从DLL导出函数