c++ - 使用导出的 C++ 函数

标签 c++ import include export

<分区>

我已经用谷歌搜索好几天了,但我似乎无法解决这个问题。

我有一个标题,它将一些函数导出到一个库中。该文件称为 test_extern.h,函数如下所示:

__declspec(dllexport) int aFunction(int a, int b);

我还有另外两个文件,一个 .h 和 .cpp,它们在导出文件的帮助下计算一些东西。我已经精简了版本以显示我想要做什么。

A.h文件:

// Include CBaseDILI_J1939 header file.
class A : public CBaseDILI_J1939
{
public:
  int bFunction(int a, int b);
}

A.cpp文件:

#include "test_extern.h"
#include "A.h"

int A::bFunction(int a, int b) {
  return aFunction(a, b);  // REturn the value of the exported function!
}

现在当我运行它时,我得到“错误 LNK2019:未解析的外部符号 _imp_aFunction”。

我已经阅读并阅读了所有关于导出 dll 的内容,有没有人知道我可能做错了什么?

最佳答案

您必须在调用模块中将 dll 函数声明为 dllspec(dllimport)。

关于c++ - 使用导出的 C++ 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18106104/

相关文章:

C++ 不能在 cout 中使用 vector 和字符串文字

c++ - 我的以下断言是否正确?

ios - 在 iOS 中创建一个导出的方法库类

import - 在RDBMS中没有主键的Sqoop导入

Java 导入语句语法

javascript - 如何在从另一个脚本文件加载 JS 时执行成功回调

c++ - 包含 vector 时 Visual Studio 崩溃

c++ - 如何在 Windows 中将共享库 *dll 与 CMake 链接

c++ - 返回 std::array 未知大小

PHP 导入带有 utf-8 重音符号的 CSV