LNK2019:从 CPP 代码调用 C 函数
LNK2019: Calling C function from CPP code
我创建了一个MSVS2015项目(MFC/C++),它与静态 C 库的链接。当我构建项目我收到以下错误:
error LNK2019:
unresolved external symbol "void __cdecl testLinkerError(void)" (?testLinkerError@@YAXXZ) referenced
in function "void __cdecl test1(void)" (?test1@@YAXXZ) [PATH_REMOVED]test.obj [NAME_OF_MFC_PROJECT]
出于调试目的,我创建了 3 个文件:
test.cpp
linkertest.c
linkertest.h
- test.cpp 已添加到 MFC 项目中,如下所示:
#include "linkertest.h" void test1(void) { testLinkerError(); }
- 头文件 linkertest.h 如下所示:
#pragma once #ifdef _cplusplus extern "C" { #endif void testLinkerError(void); #ifdef _cplusplus } #endif
- linkertest.c看起来像这样:
#include "linkertest.h" void testLinkerError(void) { int x = 5; int y = 7; int z = x + y; }
我很确定这是某种名称重整问题,但我不知道如何解决它。两个项目中的调用约定都设置为 __cdecl
基于编译器错误,编译器尝试查找?testLinkerError@@YAXXZ
这是一个C++函数名称。 所以这意味着在您的导入部分(不是您的 DLL 导出)上您没有使用extern "C"
....
还有一件事, 编译C++翻译单元时,名称__cplusplus
(两个下划线)定义为值 201402L。 请检查您的代码 确保定义了_cplusplus
(一个下划线)。
相关文章:
- 如何用参数值调用函数(仅在运行时已知)
- 从python中调用C++函数并获取返回值
- 当使用通配符和null指针调用函数时,对输出的说明
- 从R调用C++函数并对其进行集成时出错
- 使用QTreeView,如何通过调用函数只突出显示特定的行/列
- 如何在qt中从另一个类调用函数
- 在 COUT 语句中使用 COUT 调用函数
- 如何从线程中的不同模块调用函数?
- C++从函数指针数组调用函数
- 当 A 在 for 循环中调用函数 B 时,如何计算函数 A 的空间复杂度?
- 如何在 C/C++ 中从外部库调用函数
- 如何使用运算符在同一行中多次调用函数
- 是否可以创建一个从不同类调用函数的线程?
- 无法为类成员调用函数
- 如何从另一个标头 c++ 调用函数
- C++有什么方法可以在既不调用函数模板也不提供其模板参数的情况下引用函数模板?
- 如何只允许在调用函数 B 后调用函数 A?
- 我可以这样调用函数吗?
- 如何在 c++ 的类中递归调用函数方法?
- 为什么在指向对象的迭代器上调用函数不允许我更改对象本身?