ubuntu golang使用sqlite

本文介绍了在Ubuntu环境下,如何使用Golang进行SQLite数据库操作,并详细阐述了交叉编译到Windows平台的过程,包括遇到的问题及解决方法,如安装依赖库、设置环境变量等。

使用方式:

http://studygolang.com/articles/5456

https://siongui.github.io/2016/01/09/go-sqlite-example-basic-usage/

交叉编译

$ CC=i686-w64-mingw32-gcc-win32 GOOS=windows GOARCH=386 CGO_ENABLED=1 \
go build -o go-one-password-ui go-one-password-ui.go

github.com/mattn/go-gtk/pango

/usr/bin/i686-w64-mingw32-ld: cannot find -lpango-1.0
/usr/bin/i686-w64-mingw32-ld: cannot find -lgobject-2.0
/usr/bin/i686-w64-mingw32-ld: cannot find -lglib-2.0
collect2: error: ld returned 1 exit status

github.com/mattn/go-gtk/glib

/usr/bin/i686-w64-mingw32-ld: cannot find -lgobject-2.0
/usr/bin/i686-w64-mingw32-ld: cannot find -lglib-2.0
collect2: error: ld returned 1 exit status

I also needed to make sure I had several different gcc packages installed on my Ubuntu machine to support this process. I installed them with:

sudoaptgetinstallgccmultilib sudo apt-get install gcc-mingw-w64

The trickiest part though was building the various bits. I used make.bash. Perhaps there is a way to do this with all.bash. But I wasn’t sure what that actually did and whether it would pick up the particular environment variables I wanted to specify. So I ran make.bash multiple times. I start by building the Windows stuff (I’ll explain why in a sec):

cdsrc GOOS=windows GOARCH=386 CGO_ENABLED=1 CXX_FOR_TARGET=i686-w64-mingw32-g++ CC_FOR_TARGET=i686-w64-mingw32-gcc ./make.bash

This enabled CGO and specifies special C and C++ compilers to use in order to build the native exes. This is for the win32 platform. Then, I run the command again for win64 but add the –no-clean option:

$ GOOS=windows GOARCH=amd64 CGO_ENABLED=1 CXX_FOR_TARGET=x86_64-w64-mingw32-g++ CC_FOR_TARGET=x86_64-w64-mingw32-gcc ./make.bash –no-clean

Finally, I do a build for native Linux (again with –no-clean)

$ GOOS=linux GOARCH=amd64 CGO_ENABLED=1 CXX_FOR_TARGET=g++ CC_FOR_TARGET=gcc ./make.bash –no-clean

Now you might wonder why I built them in this order. I played around with this quite a bit actually. The issue is that these builds are somehow “stateful”. The last build seems to set some defaults somewhere or something. You’d think that it would be sufficient to just specify GOOS and GOARCH whenever you ran the go tool, but it isn’t. If I build Linux first and Windows last, the Linux version wouldn’t work (because the last build was Windows and that messed up Linux). And yes, building Linux last messes up the Windows builds. BUT, that can be overcome by setting some environment variables.

The way I dealt with this was to create some special scripts:

$ echo ‘export GOOS=windows; export GOARCH=386; export CGO_ENABLED=1; export CXX=i686-w64-mingw32-g++; export CC=i686-w64-mingw32-gcc’ > go-win32

$ echo ‘export GOOS=windows; export GOARCH=amd64; export CGO_ENABLED=1; export CXX=x86_64-w64-mingw32-g++; export CC=x86_64-w64-mingw32-gcc’ > go-win64

Notice the fact that I explicitly set the values of CXX and CC. What I normally do is just source these, i.e., (NOTE THE ‘.’)

$ . go-win32

This sets the environment variables needed to perform a win32 build. After that, I can just use the go tool as usual, e.g.

数据库创建

在SQLite中,自增字段需要使用关键字INTEGER PRIMARY KEY。
http://www.cnblogs.com/russellluo/p/3186786.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值