c++ - 在 C++ 中使用 C 函数 使用 extern "C"
问题描述
我正在尝试使用 extern "C" 在 Cpp 代码中访问我的两个 C 函数。我使用它如下:
#include <stdio.h>
#include <stdlib.h>
#include <cstdio>
extern "C"
{
#include "pltfrm.h"
#include "xil_printf.h"
}
int main()
{
init_platform();
print("Hello World\n\r");
print("Successfully ran Hello World application");
cleanup_platform();
return 0;
}
函数"init_platform"
和"cleanup_platform"
在内部声明"pltfrm.h"
我在两个函数上都收到“未定义的引用”错误。我做错了什么?iam 使用 c++ 空项目模板的 eclipse 构建项目选项进行编译。
解决方案
该消息来自链接步骤,当编译所有源文件并且链接器尝试将所有函数连接到函数调用时。
您可能需要链接到某个库或将源文件(对于您添加的 c 头文件)添加到您的项目中。
推荐阅读
- c# - 如何在不指定完整命名空间的情况下使用 OData(7.4) .Net Core 过滤枚举列表?
- python - 如何将索引值列表替换为现有的 x 值?
- c# - 令牌必须过期时如何对场景进行单元测试?
- typescript - 打字稿中的强类型方法装饰
- vba - 使用硒从 VBA 中的 Css 元素中获取价值
- objective-c - Mac Catalyst 中的鼠标滚动
- discord - discord.js 在 oauth2 之后获取用户的所有行会
- java - 如何将 Spring Boot 安全 API 连接到 Android 应用程序
- python - 具有月份频率的熊猫日期范围
- javascript - Heroku 服务器上的 CORS 策略问题