iis服务器助手广告广告
返回顶部
首页 > 资讯 > 后端开发 > GO >Cgo 生成的源无法在 MVC 上编译
  • 603
分享到

Cgo 生成的源无法在 MVC 上编译

2024-04-05 00:04:33 603人浏览 八月长安
摘要

来到编程网的大家,相信都是编程学习爱好者,希望在这里学习golang相关编程知识。下面本篇文章就来带大家聊聊《CGo 生成的源无法在 mvc 上编译》,介绍一下,希望对大家的知识积累有所帮助,助力实

来到编程网的大家,相信都是编程学习爱好者,希望在这里学习golang相关编程知识。下面本篇文章就来带大家聊聊《CGo 生成的源无法在 mvc 上编译》,介绍一下,希望对大家的知识积累有所帮助,助力实战开发

问题内容

我有一个用 cgo 制作的共享库,它在 linuxAndroid 上链接得很好。但是,当使用 microsoft visual studio 2017 在 windows 10 上进行编译时,我收到以下错误:

microsoft (r) program maintenance utility version 14.16.27024.1
copyright (c) microsoft corporation.  all rights reserved.

        cl -c -nologo -zc:wchar_t -fs -zc:rvaluecast -zc:inline -zc:strictstrings -zc:throwingnew -zc:referencebinding -zc:__cplusplus -o2 -md -w3 -w34100 -w34189 -w44996 -w44456 -w44457 -w44458 -wd4577 -wd4467 -ehsc -dunicode -d_unicode -dwin32 -d_enable_extended_aligned_storage -dwin64 -dQt_deprecated_warnings -dqt_no_debug -dqt_quickcontrols2_lib -dqt_quick_lib -dqt_gui_lib -dqt_qml_lib -dqt_network_lib -dqt_core_lib -dndebug -i. -irelease -i..\..\qt\5.12.0\msvc2017_64\include -i..\..\qt\5.12.0\msvc2017_64\include\qtquickcontrols2 -i..\..\qt\5.12.0\msvc2017_64\include\qtquick -i..\..\qt\5.12.0\msvc2017_64\include\qtgui -i..\..\qt\5.12.0\msvc2017_64\include\qtangle -i..\..\qt\5.12.0\msvc2017_64\include\qtqml -i..\..\qt\5.12.0\msvc2017_64\include\qtnetwork -i..\..\qt\5.12.0\msvc2017_64\include\qtcore -irelease -i\include -i..\..\qt\5.12.0\msvc2017_64\mkspecs\win32-msvc -forelease\ @c:\users\nick\appdata\local\temp\nm2b40.tmp
connekt.cpp
c2.cpp
cgo-GCc-export-header-prolog(15): error c4430: missing type specifier - int assumed. note: c++ does not support default-int
cgo-gcc-export-header-prolog(15): error c2146: syntax error: missing ';' before identifier 'gouintptr'
cgo-gcc-export-header-prolog(18): error c2146: syntax error: missing ';' before identifier 'gocomplex64'
cgo-gcc-export-header-prolog(18): error c4430: missing type specifier - int assumed. note: c++ does not support default-int
cgo-gcc-export-header-prolog(19): error c2371: '_complex': redefinition; different basic types
cgo-gcc-export-header-prolog(18): note: see declaration of '_complex'
cgo-gcc-export-header-prolog(19): error c2146: syntax error: missing ';' before identifier 'gocomplex128'
cgo-gcc-export-header-prolog(19): error c4430: missing type specifier - int assumed. note: c++ does not support default-int
generating code...
nmake : fatal error u1077: '"c:\program files (x86)\microsoft visual studio\2017\commUnity\vc\tools\msvc\14.16.27023\bin\hostx86\x64\cl.exe"' : return code '0x2'
stop.
nmake : fatal error u1077: '"c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\bin\hostx86\x86\nmake.exe"' : return code '0x2'
stop.

库的头文件(.h)由cgo生成,它包含以下几行:

typedef signed char goint8;
typedef unsigned char gouint8;
typedef short goint16;
typedef unsigned short gouint16;
typedef int goint32;
typedef unsigned int gouint32;
typedef long long goint64;
typedef unsigned long long gouint64;
typedef goint64 goint;
typedef gouint64 gouint;
//typedef __size_type__ gouintptr;
typedef size_t gouintptr;
typedef float gofloat32;
typedef double gofloat64;
typedef float _complex gocomplex64;
typedef double _complex gocomplex128;

例如,这一行报告了一个错误:

typedef float _complex gocomplex64;

但是 float _complex 是一个已经定义的类型,为什么不能将其别名为 gocomplex64

为了修复 gouintptr,我注释了 size_type 行并将其替换为 size_t,但它也无法编译:

//typedef __SIZE_TYPE__ GoUintptr;
typedef size_t GoUintptr;

这里可以做什么来修复这些编译错误?也许有一些标志可以让 visual c++ 不那么严格? (因为在其他平台上我没有任何问题)


解决方案


有同样的问题 - 我最终注释掉了 _complex 类型 (gocomplex..) 以及 __size_type__ (gouintptr) - 这样,.h 就可以编译

typedef signed char goint8;
typedef unsigned char gouint8;
typedef short goint16;
typedef unsigned short gouint16;
typedef int goint32;
typedef unsigned int gouint32;
typedef long long goint64;
typedef unsigned long long gouint64;
typedef goint64 goint;
typedef gouint64 gouint;
//typedef __size_type__ gouintptr;
typedef float gofloat32;
typedef double gofloat64;
//typedef float _complex gocomplex64;
//typedef double _complex gocomplex128;

但是,我仍然没有使用 cl 链接它:

> cl /ehsc /i ..\libbleveindextest main.cpp ..\libbleveindextest\libbleveindextest.a
microsoft (r) C/C++ optimizing compiler version 19.16.27024.1 for x64
copyright (c) microsoft corporation.  all rights reserved.

cl : command line warning d9024 : unrecognized source file type '..\libbleveindextest\libbleveindextest.a', object file assumed
main.cpp
microsoft (r) incremental linker version 14.16.27024.1
copyright (c) microsoft corporation.  all rights reserved.

/out:main.exe
main.obj
..\libbleveindextest\libbleveindextest.a
libbleveindextest.a(go.o) : warning lnk4078: multiple '.text' sections found with different attributes (60600060)
libbleveindextest.a(000005.o) : warning lnk4217: locally defined symbol _errno imported in function x_cgo_sys_thread_create
libbleveindextest.a(000007.o) : warning lnk4049: locally defined symbol _errno imported
libbleveindextest.a(000005.o) : error lnk2019: unresolved external symbol __imp___iob_func referenced in function _cgo_preinit_init
libbleveindextest.a(000006.o) : error lnk2001: unresolved external symbol __imp___iob_func
libbleveindextest.a(000007.o) : error lnk2001: unresolved external symbol __imp___iob_func
libbleveindextest.a(000005.o) : error lnk2019: unresolved external symbol __imp__beginthread referenced in function x_cgo_sys_thread_create
libbleveindextest.a(000007.o) : error lnk2001: unresolved external symbol __imp__beginthread
main.exe : fatal error lnk1120: 2 unresolved externals

__imp__iob...我可以通过添加来修复:

extern "C" { FILE __iob_func[3] = { *stdin,*stdout,*stderr }; }

到主 c 源代码。 但是,我无法修复“__imp__beginthread”。

以上就是本文的全部内容了,是否有顺利帮助你解决问题?若是能给你带来学习上的帮助,请大家多多支持编程网!更多关于Golang的相关知识,也可关注编程网公众号。

您可能感兴趣的文档:

--结束END--

本文标题: Cgo 生成的源无法在 MVC 上编译

本文链接: https://www.lsjlt.com/news/596402.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作