gpt4 book ai didi

c++ - 警告 C4190 C-linkage-specified

转载 作者:太空宇宙 更新时间:2023-11-04 02:52:25 24 4
gpt4 key购买 nike

目前我正在使用 C++ 制作一个 dll 函数。之后,我使用 DllImport 将此 dll 导入到我的 C# 项目中。在我的 C++ 项目中,我在第一次构建过程中收到警告 C4190。

Warning C4190: 'abc' has C-linkage specified, but returns UDT'std::basic_string' which is incompatible with C

My current code is as follows:

extern "C"
{
__declspec(dllexport) std::string abc(std::string targetFile)
{
return somestring;
}
}

最佳答案

C++ 部分:您不能在extern “C” 接口(interface)中使用命名空间和C++ 对象。尝试使用更原始的类型,例如intfloat, char 和返回值和参数中的指针(例如char *)。

C#部分:可以查看MSDN Platform Invoke Data Types用于转换。

关于c++ - 警告 C4190 C-linkage-specified,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20798110/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com