【问题标题】:Using c DLL into c++ project在 c++ 项目中使用 c DLL
【发布时间】:2017-03-18 10:38:50
【问题描述】:

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

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

所以我将项目创建为 Empty 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 修饰符。

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


【解决方案1】:

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

您可以参考之前的答案了解如何检测您的代码:Exporting functions from a DLL with dllexport

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-22
    • 1970-01-01
    • 2019-10-07
    • 2012-02-04
    • 1970-01-01
    相关资源
    最近更新 更多