I have two projects inside one solution (using VS 2013).
First project - mtriangle. Contains C code.
Second project - GeoGui. Contains Windows Forms project (used C++).
I try to use functions from mtriangle in GeoGui.
I have the following code:
Project 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
}
Project 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);
}
When I try to build solution, error message appears:
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
Could you, please, advise - what I do incorrectly?
Thank you!
I read this article What is an undefined reference/unresolved external symbol error and how do I fix it?
and, especially, this section: "Symbols were defined in a C program and used in C++ code."
it recommends do the following:
If an entire library is included in a header file (and was compiled as C code); the include will need to be as follows;
> extern "C" {
> #include "cheader.h" }
But as I pointed above in sample, I've already done it:
> extern "C" {
> #include "triangle.h"
> }
This is a difference.