Cgo:抱歉,未实现:64 位模式未编译

Cgo: sorry, unimplemented: 64-bit mode not compiled in

我目前正在尝试向我的 Go 项目添加一些 C 代码。没什么好看的

/*
#include <stdio.h>
void test() {
    printf("hooola")
}
*/

import (
    "C"
)

func MessageBox() {
    C.test()
}

但是这会 return

cc1.exe: sorry, unimplemented: 64-bit mode not compiled in

我检查了我的 g++gcc 编译器,一切似乎都很好,g++ -v returns this

C:\Users\ragga>g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=C:/Program\ Files/mingw-w64/x86_64-6.2.0-posix-seh-rt_v5-rev1/mingw64/bin/../libexec/gcc/x86_64-w64-mingw32/6.2.0/lto-wrapper.exe
Target: x86_64-w64-mingw32
Configured with: ../../../src/gcc-6.2.0/configure --host=x86_64-w64-mingw32 --build=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --prefix=/mingw64 --with-sysroot=/c/mingw620/x86_64-620-posix-seh-rt_v5-rev1/mingw64 --enable-shared --enable-static --disable-multilib --enable-languages=c,c++,fortran,lto --enable-libstdcxx-time=yes --enable-threads=posix --enable-libgomp --enable-libatomic --enable-lto --enable-graphite --enable-checking=release --enable-fully-dynamic-string --enable-version-specific-runtime-libs --enable-libstdcxx-filesystem-ts=yes --disable-isl-version-check --disable-libstdcxx-pch --disable-libstdcxx-debug --enable-bootstrap --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --with-gnu-as --with-gnu-ld --with-arch=nocona --with-tune=core2 --with-libiconv --with-system-zlib --with-gmp=/c/mingw620/prerequisites/x86_64-w64-mingw32-static --with-mpfr=/c/mingw620/prerequisites/x86_64-w64-mingw32-static --with-mpc=/c/mingw620/prerequisites/x86_64-w64-mingw32-static --with-isl=/c/mingw620/prerequisites/x86_64-w64-mingw32-static --with-pkgversion='x86_64-posix-seh-rev1, Built by MinGW-W64 project' --with-bugurl=http://sourceforge.net/projects/mingw-w64 CFLAGS='-O2 -pipe -I/c/mingw620/x86_64-620-posix-seh-rt_v5-rev1/mingw64/opt/include -I/c/mingw620/prerequisites/x86_64-zlib-static/include -I/c/mingw620/prerequisites/x86_64-w64-mingw32-static/include' CXXFLAGS='-O2 -pipe -I/c/mingw620/x86_64-620-posix-seh-rt_v5-rev1/mingw64/opt/include -I/c/mingw620/prerequisites/x86_64-zlib-static/include -I/c/mingw620/prerequisites/x86_64-w64-mingw32-static/include' CPPFLAGS= LDFLAGS='-pipe -L/c/mingw620/x86_64-620-posix-seh-rt_v5-rev1/mingw64/opt/lib -L/c/mingw620/prerequisites/x86_64-zlib-static/lib -L/c/mingw620/prerequisites/x86_64-w64-mingw32-static/lib '
Thread model: posix
gcc version 6.2.0 (x86_64-posix-seh-rev1, Built by MinGW-W64 project)

虽然gcc --versionreturn是这个

g:\Workspace\Go\src\github.com\raggaer\snak>gcc --version
gcc (GCC) 4.8.1
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

两者都是使用 mingw64bits 安装的,所以我不确定我的问题出在哪里?

  1. 简答:
    我尝试了很多版本,64 位 Windows OS 中 32 位和 64 位 go build 的唯一工作版本是 tdm64-gcc-5.1.0-2.exe (see the tdm-gcc page).
    您可以将它安装到 C:\TDM-GCC-64\ 并将 C:\TDM-GCC-64\bin 添加到您的 PATH(在顶部 = 或左侧)。

  1. 你可以试试MinGW-w64 - for 32 and 64-bit Windows 或者 x64-4.8.1-release-posix-seh-rev5.
    此版本仅适用于 64 位构建(不适用于 64 位 OS 上的 32 位目标)。

  1. 对于 Windows OS 运行 您的命令提示符:cmd(Linux 中的终端)然后 运行此命令(Linux 中的whereis gcc):

    where gcc
    

    那么如果有多个gcc路径,那么你可以编辑这些路径的顺序,把你需要的放在最前面,或者把其他的都去掉。


  1. 见:
    • Differences between Mingw-w64 and TDM-GCC for a simple GDI project
    • What is the difference between Orwell's MinGW and TDM Dev-C++ versions?

希望对您有所帮助。

对我有用的是安装 64 位版本的 mingw,将其添加到 PATH,然后从 PATH 中删除所有其他 mingw,然后非常重要的是重新启动计算机,您必须重新启动计算机。

很好的答案,但让我感到困惑的是 MinGW-w64 安装程序默认选择架构 i686 而不是 x

此问题来自编译器:gcc 和 g++ 旧版本(6.2.x)。使用来自 here 的 MinGW 安装程序更新你的 gcc 和 g++(确保你正在下载 32 位的 mingw-w32,64 位的 mingw-w64)重新启动你的电脑并检查你的版本是否为 11.^。这对我有用。

正在下载最新的 <a href="https://jmeubank.github.io/tdm-gcc/articles/2021-05/10.3.0-release" rel="nofollow noreferrer">TDM-GCC-64</a> 发布对我有用!确保将 C:\TDM-GCC-64\bin 添加到 PATH 环境变量。