对C/C ++混合代码使用cli包装器类-未解决的错误 [英] Using cli wrapper class for c/c++ mixed code - unresolved error
问题描述
首先只有c代码,我添加了一个c ++文件和类,并在我的c ++类中使用了该c代码功能.
现在,我正在为我的混合c/c ++代码创建cli包装器类:
我的"c"代码:
头文件:"Code.h"
first there was only c code, i added a c++ file and class and used that c code function within my c++ class.
Now i am creating cli wrapper class for my mixed c/c++ code:
my ''c'' code:
header file : "Code.h"
#pragma once
extern "C"
{
int perfomtask(int argc,char** argv);
class testclass
{
public :
void begintask(int argc, char **argv);
};
}
代码文件"code.c"
code file "code.c"
#include "Code.h"
int perfomtask(int argc, char **argv){...}
我的cplusplus代码文件:
my cplusplus code file:
#include "code.h"
void testclass::begintask(int argc, char **argv)
{
perfomtask(argc,argv);
}
现在,我已经在这个主类中测试了上述方法的工作原理
now i have tested the working of the above with this main class
int main(int argc, char **argv)
{
testclass obj1;
obj1.begintask(argc,argv);
return 0;
}
现在关于我的c/c ++混合代码
现在这是我的cli包装代码
头文件=
now that''s about my c/c++ mixed code
now here''s my cli wrapper code
header file=
using namespace System;
namespace wrapclass
{
public ref class wrapclass
{
public :
wrapclass();
~wrapclass();
void mynativeclass(int argc,char**argv);
int argc;
char** argv;
private:
testclass *ptestclass;
};
}
代码文件=
code file=
wrapclass::wrapclass::wrapclass()
{
ptestclass = new testclass();
}
wrapclass::wrapclass::~wrapclass()
{
delete ptestclass;
}
void wrapclass::wrapclass::mynativeclass(int argc,char** argv)
{
ptestclass->begintask(argc,argv);
}
现在我正在
错误:
错误LNK2028:无法解析的令牌(0A00032E)外部" C"int __cdecl perfomtask(int,char * *)在函数"public:void __thiscall testclass :: begintask(int,char * *)"中引用
now i am getting
error :
error LNK2028: unresolved token (0A00032E) "extern "C" int __cdecl perfomtask(int,char * *)referenced in function "public: void __thiscall testclass::begintask(int,char * *)" could someone help me out on this one any explanation would be appreciated.
推荐答案
检查公共语言运行时的链接器选项中 not 是否设置为pure.
如果将其设置为"/clr:pure ",则链接器将生成没有任何本机可执行代码的MSIL代码. 应该将其设置为"/clr ",以允许混合(本机和托管)程序集.
请参见此处 [此处 [ ^ ].
Check that in the linker option for common language runtime is not set to pure.
If it is set to ''/clr:pure'' the linker will produce MSIL code without any native executable code.
It should be set to ''/clr''to allow for Mixed (Native and Managed) Assemblies.
See here[^] and here[^].
这篇关于对C/C ++混合代码使用cli包装器类-未解决的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!