gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 05:26:43 24 4
gpt4 key购买 nike

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

我有这个 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com