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

cgo:cc1.exe: sorry, unimplemented: 64-bit mode not compiled in,第1张

cgo:cc1.exe: sorry, unimplemented: 64-bit mode not compiled in
1.背景

在安装github.com/mattn/go-sqlite3时,执行命令:

go get -v -x github.com/mattn/go-sqlite3

输出如下:

$ go get -v -x github.com/mattn/go-sqlite3
# get https://goproxy.io/github.com/@v/list
# get https://goproxy.io/github.com/mattn/go-sqlite3/@v/list
# get https://goproxy.io/github.com/mattn/@v/list
# get https://goproxy.io/github.com/mattn/go-sqlite3/@v/list: 200 OK (0.235s)
# get https://goproxy.io/github.com/@v/list: 404 Not Found (0.236s)
# get https://goproxy.io/github.com/mattn/@v/list: 404 Not Found (0.236s)
go: downloading github.com/mattn/go-sqlite3 v1.14.7
# get https://goproxy.io/github.com/mattn/go-sqlite3/@v/v1.14.7.zip
# get https://goproxy.io/github.com/mattn/go-sqlite3/@v/v1.14.7.zip: 200 OK (0.093s)
WORK=C:\Users\EB\AppData\Local\Temp\go-build1410891463
github.com/mattn/go-sqlite3
mkdir -p $WORK\b001\
cd C:\Users\EB\Desktop\gopath\pkg\mod\github.com\mattn\[email protected]
TERM='dumb' CGO_LDFLAGS='"-g" "-O2" "-lmingwex" "-lmingw32"' "C:\Program Files\Go\pkg\tool\windows_amd64\cgo.exe" -objdir
"$WORK\\b001\\" -importpath github.com/mattn/go-sqlite3 -- -I "$WORK\\b001\\" -g -O2 -std=gnu99 -DSQLITE_ENABLE_RTREE -DSQLITE_T
HREADSAFE=1 -DHAVE_USLEEP=1 -DSQLITE_ENABLE_FTS3 -DSQLITE_ENABLE_FTS3_PARENTHESIS -DSQLITE_TRACE_SIZE_LIMIT=15 -DSQLITE_OMIT_DEP
RECATED -DSQLITE_DEFAULT_WAL_SYNCHRONOUS=1 -DSQLITE_ENABLE_UPDATE_DELETE_LIMIT -Wno-deprecated-declarations "-IC:\Users\EB\De
sktop\gopath\pkg\mod\github.com\mattn\[email protected]" -fno-stack-check -fno-stack-protector -mno-stack-arg-probe "C:\
Users\EB\Desktop\gopath\pkg\mod\github.com\mattn\[email protected]\backup.go" "C:\Users\EB\Desktop\gopath\pkg\mo
d\github.com\mattn\[email protected]\callback.go" "C:\Users\EB\Desktop\gopath\pkg\mod\github.com\mattn\go-sqlite3@
v1.14.7\error.go" "C:\Users\EB\Desktop\gopath\pkg\mod\github.com\mattn\[email protected]\sqlite3.go" "C:\Users\EB\
\Desktop\gopath\pkg\mod\github.com\mattn\[email protected]\sqlite3_context.go" "C:\Users\EB\Desktop\gopath\pkg\mod
\github.com\mattn\[email protected]\sqlite3_load_extension.go" "C:\Users\EB\Desktop\gopath\pkg\mod\github.com\mattn
\[email protected]\sqlite3_opt_userauth_omit.go" "C:\Users\EB\Desktop\gopath\pkg\mod\github.com\mattn\go-sqlite3@v1.
14.7\sqlite3_type.go" "C:\Users\EB\Desktop\gopath\pkg\mod\github.com\mattn\[email protected]\sqlite3_usleep_windows.
go" "C:\Users\EB\Desktop\gopath\pkg\mod\github.com\mattn\[email protected]\sqlite3_windows.go"
# github.com/mattn/go-sqlite3
cc1.exe: sorry, unimplemented: 64-bit mode not compiled in

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


2.环境

gcc、g++相关:

EB@DESKTOP-K45IA6V MINGW64 ~/Desktop/test1280
$ gcc --version
gcc.exe (MinGW.org GCC-6.3.0-1) 6.3.0
Copyright (C) 2016 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.

EB@DESKTOP-K45IA6V MINGW64 ~/Desktop/test1280
$ g++ --version
g++.exe (MinGW.org GCC-6.3.0-1) 6.3.0
Copyright (C) 2016 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.

EB@DESKTOP-K45IA6V MINGW64 ~/Desktop/test1280
$ gcc -v
Using built-in specs.
COLLECT_GCC=D:\app\MinGW\bin\gcc.exe
COLLECT_LTO_WRAPPER=d:/app/mingw/bin/../libexec/gcc/mingw32/6.3.0/lto-wrapper.exe
Target: mingw32
Configured with: ../src/gcc-6.3.0/configure --build=x86_64-pc-linux-gnu --host=mingw32 --target=mingw32 --with-gmp=/mingw --with
-mpfr --with-mpc=/mingw --with-isl=/mingw --prefix=/mingw --disable-win32-registry --with-arch=i586 --with-tune=generic --enable
-languages=c,c++,objc,obj-c++,fortran,ada --with-pkgversion='MinGW.org GCC-6.3.0-1' --enable-static --enable-shared --enable-thr
eads --with-dwarf2 --disable-sjlj-exceptions --enable-version-specific-runtime-libs --with-libiconv-prefix=/mingw --with-libintl
-prefix=/mingw --enable-libstdcxx-debug --enable-libgomp --disable-libvtv --enable-nls
Thread model: win32
gcc version 6.3.0 (MinGW.org GCC-6.3.0-1)

EB@DESKTOP-K45IA6V MINGW64 ~/Desktop/test1280
$ g++ -v
Using built-in specs.
COLLECT_GCC=D:\app\MinGW\bin\g++.exe
COLLECT_LTO_WRAPPER=d:/app/mingw/bin/../libexec/gcc/mingw32/6.3.0/lto-wrapper.exe
Target: mingw32
Configured with: ../src/gcc-6.3.0/configure --build=x86_64-pc-linux-gnu --host=mingw32 --with-gmp=/mingw --with-mpfr=/mingw --wi
th-mpc=/mingw --with-isl=/mingw --prefix=/mingw --disable-win32-registry --target=mingw32 --with-arch=i586 --enable-languages=c,
c++,objc,obj-c++,fortran,ada --with-pkgversion='MinGW.org GCC-6.3.0-1' --enable-static --enable-shared --enable-threads --with-d
warf2 --disable-sjlj-exceptions --enable-version-specific-runtime-libs --with-libiconv-prefix=/mingw --with-libintl-prefix=/ming
w --enable-libstdcxx-debug --with-tune=generic --enable-libgomp --disable-libvtv --enable-nls
Thread model: win32
gcc version 6.3.0 (MinGW.org GCC-6.3.0-1)

注意:

此处gcc、g++的Target均为:mingw32。

这代表此处的gcc、g++可执行文件都是32bit,因为基于MinGW编译的程序都是32bit的。

Although programs produced under MinGW are 32-bit executables, they can be used both in 32 and 64-bit versions of Windows.
https://en.wikipedia.org/wiki/MinGW

Go相关:

EB@DESKTOP-K45IA6V MINGW64 ~/Desktop/test1280
$ go env
set GO111MODULE=on
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\EB\AppData\Local\go-build
set GOENV=C:\Users\EB\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\EB\Desktop\gopath\pkg\mod
set GONOPROXY=<gitlab,马赛克>
set GONOSUMDB=<gitlab,马赛克>
set GOOS=windows
set GOPATH=C:\Users\EB\Desktop\gopath;D:\workspace\gopath
set GOPRIVATE=<gitlab,马赛克>
set GOPROXY=https://goproxy.io
set GOROOT=C:\Program Files\Go
set GOSUMDB=off
set GOTMPDIR=
set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.16.4
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=C:\Users\EB\Desktop\test1280\go.mod
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\EB\AppData\Local\Temp\go-build2764431276=/tmp/go-bu
ild -gno-record-gcc-switches

3.解决 3.1.安装mingw-w64

下载mingw-w64,安装64bit的gcc、g++(工具集)。

https://sourceforge.net/projects/mingw-w64/files/mingw-w64/mingw-w64-release/

可选安装方式:

3.1.1.使用Online Installer安装:

此种安装方式最常见,通常下一步即可。


如果通过Online Installer安装仍有问题,请确认:
When running mingw-64-install.exe, you have to choose the x86_64 architecture on the settings screen. With this architecture, 64-bit is also the default target.
参考:
https://stackoverflow.com/questions/38589886/sorry-unimplemented-64-bit-mode-not-compiled-in

3.1.2.使用源码安装:

这种安装方式是通过源码编译生成mingw-w64,我没有尝试过。

3.1.3.使用可执行文件包安装:

这种安装方式,是在特定平台,预编译源码生成二进制文件,已经包含可执行文件。

下载链接:

https://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Personal%20Builds/mingw-builds/8.1.0/threads-posix/seh/x86_64-8.1.0-release-posix-seh-rt_v6-rev0.7z

我们选择第三种,直接下载已经预编译好的安装包,进行安装mingw-w64。

下载文件成功后,得到文件:x86_64-8.1.0-release-posix-seh-rt_v6-rev0.7z。

将其解压缩到:D:\app\mingw64。

3.1.4.查看

查看已安装的可执行文件:

EB@DESKTOP-K45IA6V MINGW64 /d/app/mingw64/bin
$ ll c++.exe cpp.exe g++.exe gcc.exe gdb.exe ld.exe nm.exe objdump.exe
-rwxr-xr-x 1 EB 197609 1958400 May 12  2018 c++.exe*
-rwxr-xr-x 1 EB 197609 1956352 May 12  2018 cpp.exe*
-rwxr-xr-x 1 EB 197609 1958400 May 12  2018 g++.exe*
-rwxr-xr-x 1 EB 197609 1955328 May 12  2018 gcc.exe*
-rwxr-xr-x 1 EB 197609   59605 May 12  2018 gdb.exe*
-rwxr-xr-x 1 EB 197609 1489408 May 12  2018 ld.exe*
-rwxr-xr-x 1 EB 197609 1067008 May 12  2018 nm.exe*
-rwxr-xr-x 1 EB 197609 2285056 May 12  2018 objdump.exe*

3.2.修改环境变量

修改环境变量PATH,新增D:\app\mingw64\bin搜索路径并提升至最高优先级。

查看:

在PATH中的多个目录中找到gcc、g++,但是D:\app\mingw64\bin\gcc.exe(64bit)优先级最高。

Microsoft Windows [版本 10.0.17763.107]
(c) 2018 Microsoft Corporation。保留所有权利。

C:\Users\EB>where gcc
D:\app\mingw64\bin\gcc.exe
D:\app\MinGW\bin\gcc.exe

版本:

C:\Users\EB>gcc --version
gcc (x86_64-posix-seh-rev0, Built by MinGW-W64 project) 8.1.0
Copyright (C) 2018 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.


C:\Users\EB>g++ --version
g++ (x86_64-posix-seh-rev0, Built by MinGW-W64 project) 8.1.0
Copyright (C) 2018 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.


C:\Users\EB>gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=D:/app/mingw64/bin/../libexec/gcc/x86_64-w64-mingw32/8.1.0/lto-wrapper.exe
Target: x86_64-w64-mingw32
Configured with: ../../../src/gcc-8.1.0/configure --host=x86_64-w64-mingw32 --build=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --prefix=/mingw64 --with-sysroot=/c/mingw810/x86_64-810-posix-seh-rt_v6-rev0/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 --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/mingw810/prerequisites/x86_64-w64-mingw32-static --with-mpfr=/c/mingw810/prerequisites/x86_64-w64-mingw32-static --with-mpc=/c/mingw810/prerequisites/x86_64-w64-mingw32-static --with-isl=/c/mingw810/prerequisites/x86_64-w64-mingw32-static --with-pkgversion='x86_64-posix-seh-rev0, Built by MinGW-W64 project' --with-bugurl=https://sourceforge.net/projects/mingw-w64 CFLAGS='-O2 -pipe -fno-ident -I/c/mingw810/x86_64-810-posix-seh-rt_v6-rev0/mingw64/opt/include -I/c/mingw810/prerequisites/x86_64-zlib-static/include -I/c/mingw810/prerequisites/x86_64-w64-mingw32-static/include' CXXFLAGS='-O2 -pipe -fno-ident -I/c/mingw810/x86_64-810-posix-seh-rt_v6-rev0/mingw64/opt/include -I/c/mingw810/prerequisites/x86_64-zlib-static/include -I/c/mingw810/prerequisites/x86_64-w64-mingw32-static/include' CPPFLAGS=' -I/c/mingw810/x86_64-810-posix-seh-rt_v6-rev0/mingw64/opt/include -I/c/mingw810/prerequisites/x86_64-zlib-static/include -I/c/mingw810/prerequisites/x86_64-w64-mingw32-static/include' LDFLAGS='-pipe -fno-ident -L/c/mingw810/x86_64-810-posix-seh-rt_v6-rev0/mingw64/opt/lib -L/c/mingw810/prerequisites/x86_64-zlib-static/lib -L/c/mingw810/prerequisites/x86_64-w64-mingw32-static/lib '
Thread model: posix
gcc version 8.1.0 (x86_64-posix-seh-rev0, Built by MinGW-W64 project)

C:\Users\EB>g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=D:/app/mingw64/bin/../libexec/gcc/x86_64-w64-mingw32/8.1.0/lto-wrapper.exe
Target: x86_64-w64-mingw32
Configured with: ../../../src/gcc-8.1.0/configure --host=x86_64-w64-mingw32 --build=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --prefix=/mingw64 --with-sysroot=/c/mingw810/x86_64-810-posix-seh-rt_v6-rev0/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 --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/mingw810/prerequisites/x86_64-w64-mingw32-static --with-mpfr=/c/mingw810/prerequisites/x86_64-w64-mingw32-static --with-mpc=/c/mingw810/prerequisites/x86_64-w64-mingw32-static --with-isl=/c/mingw810/prerequisites/x86_64-w64-mingw32-static --with-pkgversion='x86_64-posix-seh-rev0, Built by MinGW-W64 project' --with-bugurl=https://sourceforge.net/projects/mingw-w64 CFLAGS='-O2 -pipe -fno-ident -I/c/mingw810/x86_64-810-posix-seh-rt_v6-rev0/mingw64/opt/include -I/c/mingw810/prerequisites/x86_64-zlib-static/include -I/c/mingw810/prerequisites/x86_64-w64-mingw32-static/include' CXXFLAGS='-O2 -pipe -fno-ident -I/c/mingw810/x86_64-810-posix-seh-rt_v6-rev0/mingw64/opt/include -I/c/mingw810/prerequisites/x86_64-zlib-static/include -I/c/mingw810/prerequisites/x86_64-w64-mingw32-static/include' CPPFLAGS=' -I/c/mingw810/x86_64-810-posix-seh-rt_v6-rev0/mingw64/opt/include -I/c/mingw810/prerequisites/x86_64-zlib-static/include -I/c/mingw810/prerequisites/x86_64-w64-mingw32-static/include' LDFLAGS='-pipe -fno-ident -L/c/mingw810/x86_64-810-posix-seh-rt_v6-rev0/mingw64/opt/lib -L/c/mingw810/prerequisites/x86_64-zlib-static/lib -L/c/mingw810/prerequisites/x86_64-w64-mingw32-static/lib '
Thread model: posix
gcc version 8.1.0 (x86_64-posix-seh-rev0, Built by MinGW-W64 project)

非全路径默认执行gcc、g++,按搜索优先级,执行的是D:\app\mingw64\bin\中的可执行文件:

Target均变成了x86_64-w64-mingw32(x86_64,即64bit)。

3.3.关闭终端重试

如果是在终端,如bash、sh、cmd.exe中,则关闭终端,重试。

如果是在idea-GoLand中打开终端,重启idea-GoLand,打开终端,重试。

执行成功:


思考:

重启终端、重启idea-GoLand,本质都是重启进程。

修改了环境变量,只是改了一个文件,只有重新fork进程时,环境变量才可以更新生效。

类似Unix中的.profile/.bash_profile。


4.原因

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

4.1.分析

1.gcc、g++工具有被安装,否则将会报错找不到cc1.exe命令;
2.gcc、g++工具是32bit的,而使用的Go是64bit的;

4.2.原因

不能用64bit的Go调用32bit的cc1.exe:

You use 64-bit Go, so you have to install 64-bit (mingw-w64) for cgo.

https://stackoverflow.com/questions/39615419/go-get-error-cc1-exe-sorry-unimplemented-64-bit-mode-not-compiled-in

我的gcc、g++工具都是基于MinGW安装,其为32bit的,而我的go是64bit的。

PS:

基于MinGW生成的可执行程序都是32bit的。

一般情况下,32bit可执行文件是可以在32bit或64bit的 *** 作系统中执行。

4.3.解决方法

安装64bit的gcc、g++工具。例如,可以通过MinGW-w64安装。

MinGW-w64:MinGW-w64 - for 32 and 64 bit Windows

The mingw-w64 project is a complete runtime environment for gcc to support binaries native to Windows 64-bit and 32-bit operating systems.

https://sourceforge.net/projects/mingw-w64/

MinGW-w64是类似MinGW的工具集,区别:

32bit64bit
MinGW支持
MinGW-w64支持支持

更多参考:
https://github.com/FrankHB/pl-docs/blob/master/zh-CN/mingw-vs-mingw-v64.md
https://blog.csdn.net/lqz790192593/article/details/102857719


5.参考

1.https://stackoverflow.com/questions/39863157/cgo-sorry-unimplemented-64-bit-mode-not-compiled-in
2.https://www.cnblogs.com/ghj1976/p/3540257.html
3.https://blog.csdn.net/test1280/article/details/118106818

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/994319.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-21
下一篇 2022-05-21

发表评论

登录后才能评论

评论列表(0条)

保存