简体   繁体   English

将C代码编译为Visual C ++ dll吗?

[英]Compile C code into Visual C++ dll?

Is it possible to compile C code into a Visual C++ dll? 是否可以将C代码编译为Visual C ++ dll? I'm looking at using some C code with a .Net project and trying to determine whether this is even an option. 我正在研究在.Net项目中使用一些C代码,并试图确定这是否是一个选择。

Thanks, Becky 谢谢,贝基

yes. 是。 If you want to get rid of name mangling use "extern "C" { /*...*/ } construct. 如果要摆脱名称修饰,请使用"extern "C" { /*...*/ }构造。

Also, refer FAQ : How to mix C and C++ 另请参阅常见问题解答: 如何混合使用C和C ++

Given that C++ is largely backward compatible with C, you should be able to recompile the code using the C++ compiler unless the code uses some C99 features. 鉴于C ++在很大程度上与C向后兼容,除非代码使用某些C99功能,否则您应该能够使用C ++编译器重新编译代码。 However, keep in mind that C++/CLI is not standard C++ so there might be additional issues. 但是,请记住,C ++ / CLI不是标准C ++,因此可能存在其他问题。

As aJ said, if you want to avoid the name mangling, you'll have to 'extern C' the symbols. 正如aJ所说的,如果要避免名称混乱,则必须“附加C”符号。

Another way to accomplish this would be to leave the C library as standard native code and write a thin C++/CLI layer for it. 完成此操作的另一种方法是将C库保留为标准本机代码,并为其编写一个瘦C ++ / CLI层。 Then expose the C++/CLI layer to your .NET application. 然后将C ++ / CLI层公开给您的.NET应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM