我正在Visual Studio 2019中开发C++Windows窗体应用程序。
我想使用外部库EDFlib的一些函数。EDFlib是一个C/C++的编程库,它只包含两个文件(.C和.h(
这里有一个简单的代码,当我点击按钮时,它会在EDF文件中写入数据:
#include "edflib.h"
// [...]
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e)
{
double buf[200];
for (int i = 0; i < 200; i++)
buf[i] = i;
int hdl;
hdl = edfopen_file_writeonly("test.edf", EDFLIB_FILETYPE_EDFPLUS, 1);
// [...]
edfwrite_physical_samples(hdl, buf);
edfclose_file(hdl);
}
// [...]
我有以下2个错误:
Erreur LNK2028 jeton non résolu (0A000038) "extern "C" int __cdecl edfopen_file_writeonly(char const *,int,int)" (?edfopen_file_writeonly@@$$J0YAHPBDHH@Z) référencé dans la fonction "private: void __clrcall TestEDF::MyForm::button1_Click(class System::Object ^,class System::EventArgs ^)" (?button1_Click@MyForm@TestEDF@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z)
&
Erreur LNK2019 symbole externe non résolu "extern "C" int __cdecl edfopen_file_writeonly(char const *,int,int)" (?edfopen_file_writeonly@@$$J0YAHPBDHH@Z) référencé dans la fonction "private: void __clrcall TestEDF::MyForm::button1_Click(class System::Object ^,class System::EventArgs ^)" (?button1_Click@MyForm@TestEDF@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z)
我试图阅读有关这些错误的文档。但我不是C/C++专家。我不知道该怎么办。我需要一些帮助。
谢谢。
我猜错误状态是您有未解析的符号,这意味着您调用的函数有一个声明(来自#include"edflib.h"(,链接器在构建过程中试图找到该声明,但没有定义。看起来您只是包含了库的头,但您还需要与它链接。我不知道你使用什么IDE,但你应该看看如何在C++中将库链接到你的项目。有很多关于在线创建和链接库的信息可以帮助您解决这个问题。
您应该给予Extern"C";方法并将库添加到其中,检查
https://isocpp.org/wiki/faq/mixing-c-and-cpp
不能在C++中外部添加C库