c++ - 在 C++ 项目中使用 C DLL

标签 c++ c visual-studio dll static-libraries

所以我有一个问题。 我已经阅读了很多东西,但似乎没有什么对我有用。

我有这个 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 中导出。您还必须使用 dllimportdllexport

关于如何检测您的代码,您可以引用之前的回答:Exporting functions from a DLL with dllexport

关于c++ - 在 C++ 项目中使用 C DLL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40425318/

相关文章:

c - 当我们改变指针的内容时指针指向哪里?

c - 强制子部件尊重父部件绘图区域(如圆角)

c++ - 在 gdb 中,在我按下 tab 后,它可以完成我的命令以及局部变量,但是为什么 lldb 不能

C++ 禁用忙碌/等待光标

c++ - 使用 GLUT 绘制圆锥体和圆柱体

c++ - 为什么 C++ 不支持命名参数?

c++ - 使 SDL 调用纯虚成员函数作为事件回调?

c++ - 在Visual Studio 2012中重建时出现奇怪的链接错误

c++ - 在Visual Studio 2017中为Sapera演示编译错误

c++ - 将文件包含到整个项目中