错误LNK2028:未解析的令牌(0A00000D)" extern" C" void __cdecl

时间:2015-07-30 11:19:06

标签: c++ c visual-studio linker

我在一个解决方案中有两个项目(使用VS 2013)。 第一个项目 - mtriangle 。包含C代码。
第二个项目 - GeoGui 。包含Windows窗体项目(使用C ++)。

我尝试在 GeoGui 中使用 mtriangle 中的功能。

我有以下代码:

项目 mtriangle

triangle.h

#ifdef __cplusplus 
extern "C" {
#endif
    __declspec(dllexport) void trimain(char *, struct triangulateio *, struct triangulateio *, struct triangulateio *);
#ifdef __cplusplus 
}
#endif 
#ifdef __cplusplus 
extern "C" {
#endif
    void trifree(VOID *memptr);
#ifdef __cplusplus 
}
#endif 

triangle.c

void trimain(char *triswitches, struct triangulateio *in, 
struct triangulateio *out, struct triangulateio *vorout)
{
 // Implementation here, will be provided if need 
}

项目 GeoGui

mainForm.h

#pragma once
extern "C" 
{
   #include "triangle.h"
}

... 

private: System::Void dlgFileOpen_FileOk(System::Object^  sender, System::ComponentModel::CancelEventArgs^  e) {


                 struct triangulateio *in;

                 struct triangulateio *out;

                 struct triangulateio *voronoi;


                 trimain("p", in,out,voronoi);
}

当我尝试构建解决方案时,会显示错误消息:

Error   13  error LNK2028: unresolved token (0A00000D) "extern "C" void __cdecl trimain(char *,struct triangulateio *,struct triangulateio *,struct triangulateio *)" (?trimain@@$$J0YAXPADPAUtriangulateio@@11@Z) referenced in function "private: void __clrcall GeoGUI::mainForm::dlgFileOpen_FileOk(class System::Object ^,class System::ComponentModel::CancelEventArgs ^)" (?dlgFileOpen_FileOk@mainForm@GeoGUI@@$$FA$AAMXP$AAVObject@System@@P$AAVCancelEventArgs@ComponentModel@4@@Z)   C:\Users\Administrator\Documents\Visual Studio 2013\Projects\mtriangle\GeoGUI\GeoGUI.obj    GeoGUI

Error   14  error LNK2019: unresolved external symbol "extern "C" void __cdecl trimain(char *,struct triangulateio *,struct triangulateio *,struct triangulateio *)" (?trimain@@$$J0YAXPADPAUtriangulateio@@11@Z) referenced in function "private: void __clrcall GeoGUI::mainForm::dlgFileOpen_FileOk(class System::Object ^,class System::ComponentModel::CancelEventArgs ^)" (?dlgFileOpen_FileOk@mainForm@GeoGUI@@$$FA$AAMXP$AAVObject@System@@P$AAVCancelEventArgs@ComponentModel@4@@Z)    C:\Users\Administrator\Documents\Visual Studio 2013\Projects\mtriangle\GeoGUI\GeoGUI.obj    GeoGUI

请你告诉我 - 我做错了什么?

谢谢!

我读过这篇文章 What is an undefined reference/unresolved external symbol error and how do I fix it?

,尤其是本节: "符号在C程序中定义,并在C ++代码中使用。"

建议执行以下操作:

  

如果整个库包含在头文件中(并编译为   C代码);包含将需要如下;

> extern "C" {
>     #include "cheader.h" }

但正如我在上面的示例中指出的那样,我已经完成了它:

> extern "C" {
>        #include "triangle.h"
>     }

这是一个区别。

0 个答案:

没有答案