Works with 64-bit Windows (without pkg-config) but doesn't work with 32-bit Windows. #27

Closed
stever opened this Issue Nov 2, 2012 · 84 comments

Projects

None yet

4 participants

@stever
stever commented Nov 2, 2012

Hello. I've been having trouble with getting this to work on Windows using 32-bit and then found that it works on 64-bit Windows even without pkg-config (which incidentally I had got installed though I'm not sure that could help after all). Having learned more about the current head revision I understand that it works without pkg-config on Windows however I could not get it to work with 32-bit Windows and I get a stream of error messages like "__divdi3: not defined". My understanding of C and cgo is patchy and I'm not sure what this means. I couldn't see why it should be different on 32-bit Windows but perhaps some other compiler option is required.

I resolved my problems by discarding pkg-config and the static compilation on Windows and use the DLL instead, which is what other platforms are using anyway. So instead of the #cgo pkg-config line I'm using "#cgo LDFLAGS: -lsqlite3" having the environment set up with the include files on the path for gcc (LIBRARY_PATH and C_INCLUDE_PATH). The little work with cgo that I've done so far this works best with the smallest of changes to the source-code across platforms.

I've never used pkg-config before and while I had no trouble with it on other platforms on Windows it was a struggle getting an environment set up. Wouldn't this be better without pkg-config?

In any case the current head revision doesn't appear to work for 32-bit Windows and the static compilation as an exception for Windows seems unnecessarily complicated. Maybe you can get it to work but I wonder if this is the wrong direction to go.

Contributor

Check here: https://groups.google.com/forum/?fromgroups=#!topic/golang-nuts/VNP6Mwz_B6o

I fixed __divdi3: not defined errors with adding -lgcc_s to LDFLAGS in C:\Go\src\pkg\github.com\mattn\go-sqlite3\sqlite3_windows.go file:

package sqlite

/*
#cgo CFLAGS: -I. -fno-stack-check -fno-stack-protector -mno-stack-arg-probe
#cgo LDFLAGS: -lmingwex -lmingw32  -lgcc_s
*/
import "C"

and then go install in that folder.

Best regards

Owner
mattn commented Nov 29, 2012

Hmm, libgcc_s.a is provided for mingw64. it don't exists in my mingw/lib directory.

stever commented Nov 29, 2012

I can confirm that works for me on a 32-bit and 64-bit Windows now.

I have libgcc_s.a in "C:\MinGW\lib64" (mingw64) on the 64-bit system. On the 32-bit system I have "C:\MinGW\lib\gcc\mingw32\4.6.2\libgcc_s.a" in case that helps at all.

Thanks & Regards

Owner
mattn commented Nov 29, 2012

Oh, ok, I'll check it soon.

Owner
mattn commented Nov 29, 2012

Hmm, if linking libgcc_s.a on mingw32 32bit, example/main crash.

Owner
mattn commented Nov 29, 2012

@stever If change as following, can it succeeded to build?

#cgo windows/386 CFLAGS: -I. -fno-stack-check -fno-stack-protector -mno-stack-arg-probe
#cgo windows/386 LDFLAGS: -lmingwex -lmingw32
#cgo windows/amd64 CFLAGS: -I. -fno-stack-check -fno-stack-protector -mno-stack-arg-probe
#cgo windows/amd64 LDFLAGS: -lmingwex -lmingw32  -lgcc_s
stever commented Nov 29, 2012

Build succeeded but then when I run the example it fails with similar error messages, on win32.

I think I need the -lgcc_s flag on win32 and not win64.

The example/main didn't crash for me when I ran it with this on either architecture. I made sure sqlite3.dll and include files were not on the path either in case that was having an effect. I have a fairly clean setup so far as I know and the suggestion from matrixik works for me.

Owner
mattn commented Nov 29, 2012

I'm checking this issue on windows 32bit and It don't require libgcc_s.a for building.

stever commented Nov 29, 2012

Sure, seem to need to link to it on win32 though. I didn't need to link to it with win64.

Owner
mattn commented Nov 29, 2012

Hmm, inversed result?

stever commented Nov 29, 2012

I don't know why linking libgcc_s.a on win32 crashes for you. Maybe we have different mingw32 versions? I've used a fairly recent mingw-get-inst installer.

Owner
mattn commented Nov 29, 2012

What version of go?

stever commented Nov 29, 2012

1.0.3

Owner
mattn commented Nov 29, 2012

Me too...

Owner
mattn commented Nov 29, 2012

Ah, but I'm using hg tip.

srinathh commented Dec 5, 2012

Hi, just forked go-sqlite3 & added the following flags in sqlite3.go & was able to subsequently do a simple "go get" to install the package. Example compiles perfectly on win32 with standard MinGW. Had the same issues & soln. building Russ Cox's sqlite3 bindings... libgcc_s.a contains the "__divdi3" which gets rid of not found etc errors. Removing the stack protection gets rid of "__chkstk_ms" not found errors which i simply wasn't able to figure out (this is supposed to be defined in the standard libgcc.a which is included by default by MinGW but somehow wasn't getting linked)

#cgo LDFLAGS: -lgcc_s
#cgo CFLAGS: -fno-stack-check -fno-stack-protector -mno-stack-arg-probe

Owner
mattn commented Dec 6, 2012

That flags is already put in sqlite3_windows.go

srinathh commented Dec 6, 2012

hmmmm..... a simple "go get" was throwing a whole bunch of starting with __divdi3 type of errors on compiling the test program before i made this change. Wonder why.... maybe because of -lgcc_s?

Contributor
matrixik commented Dec 6, 2012

@mattn no it's not, you didn't push it to github

Owner
mattn commented Dec 7, 2012

@matrixik ? I didn't change anything. What you want?

Owner
mattn commented Dec 7, 2012

@srinathdevelopment

maybe because of -lgcc_s?

I guess it so.

Contributor
matrixik commented Dec 7, 2012

You didn't add -lgcc_s to sqlite3_windows.go
https://github.com/mattn/go-sqlite3/blob/master/sqlite3_windows.go
that's why @srinathdevelopment still see errors with go get (and I too)

Owner
mattn commented Dec 7, 2012

@matrixik see above. if add -lgcc_s on win32, it occur crashed.

stever commented Dec 7, 2012

@mattn That's true for you, but is it true for others? Not true for me. It's only required in my win32 build but doesn't hurt to have it for both that and 64-bit windows too.

Owner
mattn commented Dec 7, 2012

@stever if it occur on your environment just only, I'll change to

#cgo windows/386 CFLAGS: -I. -fno-stack-check -fno-stack-protector -mno-stack-arg-probe
#cgo windows/386 LDFLAGS: -lmingwex -lmingw32
#cgo windows/amd64 CFLAGS: -I. -fno-stack-check -fno-stack-protector -mno-stack-arg-probe
#cgo windows/amd64 LDFLAGS: -lmingwex -lmingw32  -lgcc_s

Is this ok?

stever commented Dec 7, 2012

@mattn Really is it needed in 64-bit windows at all? Weird that I have the complete opposite. I'll just fork it to work around the issue I have, but I'm not assuming right now I'm the only person that does. I've tested this on a bunch of computers with consistent results.

Owner
mattn commented Dec 7, 2012

@stever Where did you get sqlite3.dll or header files ?

stever commented Dec 7, 2012

@mattn I've tested with an without my own sqlite3.dll and header files. I made a fork before just to remove the static include for windows here as a special case. However, on windows I still like this so right now I'm not using anything outside of your repository plus the '-lgcc_s' fix mentioned above.

Owner
mattn commented Dec 7, 2012

I'm confusing...

stever commented Dec 7, 2012

Maybe I've confused you... I didn't/don't fully understand the problem but the suggested fix '-lgcc_s' worked for me and that's all I needed. It's neat to be able to include SQLite statically on windows so I prefer this than the DLL option that I had mentioned as my initial workaround. It would be ideal if the '-lgcc_s' fix work for you and everyone else.

It would be useful if other people will confirm there experience with this on 32-bit windows.

Owner
mattn commented Dec 7, 2012

Is there anyone who occur this issue without stever?

Contributor
matrixik commented Dec 7, 2012

Yes, me.

Owner
mattn commented Dec 7, 2012

@stever @matrixik What OS do you use to build/run ? I'm building this on WindowsXP 32bit.

stever commented Dec 7, 2012

@mattn I'm mostly using 32-bit Windows 7 and 64-bit Windows 8.

srinathh commented Dec 7, 2012

in case this helps... i built using -lgcc_s on Win7 32 bit, MinGW & Go
latest versions as of last weekend
On Dec 7, 2012 6:42 PM, "mattn" notifications@github.com wrote:

@stever https://github.com/stever @matrixikhttps://github.com/matrixikWhat OS do you use to build/run ? I'm building this on WindowsXP.


Reply to this email directly or view it on GitHubhttps://github.com/mattn/go-sqlite3/issues/27#issuecomment-11129535.

Owner
mattn commented Dec 7, 2012

Are there someone using Windows XP 32bit ? hmmmmmm

Contributor
matrixik commented Dec 7, 2012

Windows 7 x32

Owner
mattn commented Dec 10, 2012

@stever what are you saying does not work on win32, crash? broken results?

stever commented Dec 10, 2012

@mattn Exactly as in the comment from @matrixik above - #27 (comment)

Owner
mattn commented Dec 10, 2012

@stever How about to add -lgcc instead of -lgcc_s ? I got succeeded to build and run example/main. If you don't get fail, I'll update.

stever commented Dec 10, 2012

@mattn I tried and sadly that's the same as before.

Owner
mattn commented Dec 10, 2012

@stever once more, please try to add -static-libgcc.

stever commented Dec 10, 2012

@mattn Same result.

Owner
mattn commented Dec 10, 2012

Hmm, It read some documentation, but it seems that libgcc_s.a is not provided for 32 bit OSs.

stever commented Dec 10, 2012

I'm using MinGW (mingw.org) on 32-bit Windows and MinGW-w64 (mingw-w64.sourceforge.net) on 64-bit Windows.

Maybe that's why -lgcc_s isn't required to run your example/main.go on 64-bit Windows.

Do you use the same?

I've got Windows XP here - not tried it yet, but I could try and replicate your problem here if that helps.

Owner
mattn commented Dec 10, 2012

@stever

Please try to get whether divdi3 is contained in libgcc.a ?

C:\MinGW\lib\gcc\mingw32\4.7.2>nm -o libgcc.a | grep divdi3
libgcc.a:_divdi3.o:00000000 b .bss
libgcc.a:_divdi3.o:00000000 d .data
libgcc.a:_divdi3.o:00000000 r .eh_frame
libgcc.a:_divdi3.o:00000000 t .text
libgcc.a:_divdi3.o:00000000 T ___divdi3
libgcc.a:_udivdi3.o:00000000 b .bss
libgcc.a:_udivdi3.o:00000000 d .data
libgcc.a:_udivdi3.o:00000000 r .eh_frame
libgcc.a:_udivdi3.o:00000000 t .text
libgcc.a:_udivdi3.o:00000000 T ___udivdi3
libgcc.a:bid64_div.o:         U ___udivdi3
libgcc.a:bid128_div.o:         U ___udivdi3

divdi3 is contained on my environment.

libgcc.a:_divdi3.o:00000000 T ___divdi3

Or, libgcc_s.a contains it ?

Owner
mattn commented Dec 10, 2012

It seems that divdi3 is exported as shared function in libgcc_s.a

C:\MinGW\lib\gcc\mingw32\4.7.2>nm -o libgcc_s.a | grep divdi3
libgcc_s.a:d000118.o:00000000 T ___udivdi3
libgcc_s.a:d000118.o:00000000 I __imp____udivdi3
libgcc_s.a:d000040.o:00000000 T ___divdi3
libgcc_s.a:d000040.o:00000000 I __imp____divdi3
Owner
mattn commented Dec 10, 2012

So, I can't understand why you can't build with libgcc.a.

stever commented Dec 10, 2012

I get that line also:

libgcc.a:_divdi3.o:00000000 T ___divdi3

However the path I have is C:\MinGW\lib\gcc\mingw32\4.6.2

the error comes because for some reason in 32 bit MinGW, these functions
are defined in libgcc_s.a rather libgcc.a... so these errors come. As i
said, this error is not unique to this library's config, happens if you try
to build sqlite3 with other go libraries as well
On Dec 10, 2012 4:46 PM, "Steven Robertson" notifications@github.com
wrote:

I get that line also:

libgcc.a:_divdi3.o:00000000 T ___divdi3

However the path I have is C:\MinGW\lib\gcc\mingw32\4.6.2


Reply to this email directly or view it on GitHubhttps://github.com/mattn/go-sqlite3/issues/27#issuecomment-11189377.

Owner
mattn commented Dec 10, 2012

However the path I have is C:\MinGW\lib\gcc\mingw32\4.6.2

Thank your do it.

It seems that libgcc.a is linked on my environment. Is it linked on your environment?

go build -x 2>&1 | tee log
WORK=C:\DOCUME~1\MATTN\LOCALS~1\Temp\go-build560761051
mkdir -p $WORK\github.com\mattn\go-sqlite3\_obj\
cd c:\temp\github\go-mattn\src\github.com\mattn\go-sqlite3
c:\go\pkg\tool\windows_386\cgo.exe -objdir $WORK\github.com\mattn\go-sqlite3\_obj\ -- -I. -fno-stack-check -fno-stack-protector -mno-stack-arg-probe -I $WORK\github.com\mattn\go-sqlite3\_obj\ sqlite3.go sqlite3_windows.go
c:\go\pkg\tool\windows_386\8c.exe -FVw -I $WORK\github.com\mattn\go-sqlite3\_obj\ -I c:\go\pkg\windows_386 -o $WORK\github.com\mattn\go-sqlite3\_obj\_cgo_defun.8 -DGOOS_windows -DGOARCH_386 $WORK\github.com\mattn\go-sqlite3\_obj\_cgo_defun.c
gcc -I . -g -O2 -m32 -mthreads -print-libgcc-file-name
gcc -I . -g -O2 -m32 -mthreads -I. -fno-stack-check -fno-stack-protector -mno-stack-arg-probe -I $WORK\github.com\mattn\go-sqlite3\_obj\ -o $WORK\github.com\mattn\go-sqlite3\_obj\_cgo_main.o -c $WORK\github.com\mattn\go-sqlite3\_obj\_cgo_main.c
gcc -I . -g -O2 -m32 -mthreads -I. -fno-stack-check -fno-stack-protector -mno-stack-arg-probe -I $WORK\github.com\mattn\go-sqlite3\_obj\ -o $WORK\github.com\mattn\go-sqlite3\_obj\_cgo_export.o -c $WORK\github.com\mattn\go-sqlite3\_obj\_cgo_export.c
gcc -I . -g -O2 -m32 -mthreads -I. -fno-stack-check -fno-stack-protector -mno-stack-arg-probe -I $WORK\github.com\mattn\go-sqlite3\_obj\ -o $WORK\github.com\mattn\go-sqlite3\_obj\sqlite3.cgo2.o -c $WORK\github.com\mattn\go-sqlite3\_obj\sqlite3.cgo2.c
gcc -I . -g -O2 -m32 -mthreads -I. -fno-stack-check -fno-stack-protector -mno-stack-arg-probe -I $WORK\github.com\mattn\go-sqlite3\_obj\ -o $WORK\github.com\mattn\go-sqlite3\_obj\sqlite3_windows.cgo2.o -c $WORK\github.com\mattn\go-sqlite3\_obj\sqlite3_windows.cgo2.c
gcc -I . -g -O2 -m32 -mthreads -I. -fno-stack-check -fno-stack-protector -mno-stack-arg-probe -I $WORK\github.com\mattn\go-sqlite3\_obj\ -o $WORK\github.com\mattn\go-sqlite3\_obj\sqlite3_windows.o -c .\sqlite3_windows.c
gcc -I . -g -O2 -m32 -mthreads -o $WORK\github.com\mattn\go-sqlite3\_obj\_cgo_.o $WORK\github.com\mattn\go-sqlite3\_obj\_cgo_main.o $WORK\github.com\mattn\go-sqlite3\_obj\_cgo_export.o $WORK\github.com\mattn\go-sqlite3\_obj\sqlite3.cgo2.o $WORK\github.com\mattn\go-sqlite3\_obj\sqlite3_windows.cgo2.o $WORK\github.com\mattn\go-sqlite3\_obj\sqlite3_windows.o -lmingwex -lmingw32
c:\go\pkg\tool\windows_386\cgo.exe -objdir $WORK\github.com\mattn\go-sqlite3\_obj\ -dynimport $WORK\github.com\mattn\go-sqlite3\_obj\_cgo_.o -dynout $WORK\github.com\mattn\go-sqlite3\_obj\_cgo_import.c
c:\go\pkg\tool\windows_386\8c.exe -FVw -I $WORK\github.com\mattn\go-sqlite3\_obj\ -I c:\go\pkg\windows_386 -o $WORK\github.com\mattn\go-sqlite3\_obj\_cgo_import.8 -DGOOS_windows -DGOARCH_386 $WORK\github.com\mattn\go-sqlite3\_obj\_cgo_import.c
gcc -I . -g -O2 -m32 -mthreads -o $WORK\github.com\mattn\go-sqlite3\_obj\_all.o $WORK\github.com\mattn\go-sqlite3\_obj\_cgo_export.o $WORK\github.com\mattn\go-sqlite3\_obj\sqlite3.cgo2.o $WORK\github.com\mattn\go-sqlite3\_obj\sqlite3_windows.cgo2.o $WORK\github.com\mattn\go-sqlite3\_obj\sqlite3_windows.o -Wl,-r -nostdlib -lmingwex -lmingw32 c:/mingw/bin/../lib/gcc/mingw32/4.7.2/libgcc.a
c:\go\pkg\tool\windows_386\8g.exe -o $WORK\github.com\mattn\go-sqlite3\_obj\_go_.8 -p github.com/mattn/go-sqlite3 -D _/c_/temp/github/go-mattn/src/github.com/mattn/go-sqlite3 -I $WORK $WORK\github.com\mattn\go-sqlite3\_obj\_cgo_gotypes.go $WORK\github.com\mattn\go-sqlite3\_obj\sqlite3.cgo1.go $WORK\github.com\mattn\go-sqlite3\_obj\sqlite3_windows.cgo1.go
c:\go\pkg\tool\windows_386\pack.exe grcP $WORK $WORK\github.com\mattn\go-sqlite3.a $WORK\github.com\mattn\go-sqlite3\_obj\_go_.8 $WORK\github.com\mattn\go-sqlite3\_obj\_cgo_import.8 $WORK\github.com\mattn\go-sqlite3\_obj\_cgo_defun.8 $WORK\github.com\mattn\go-sqlite3\_obj\_all.o

Owner
mattn commented Dec 10, 2012

On my environment, libgcc.a is linked correctly.

-lmingw32 c:/mingw/bin/../lib/gcc/mingw32/4.7.2/libgcc.a

stever commented Dec 10, 2012

@mattn I haven't spent much time with MinGW to follow these steps constructively. Assuming you are right and the MinGW environment I have is not linking libgcc properly, how do I go about getting the environment you've got running?

Owner
mattn commented Dec 10, 2012

I haven't spent much time with MinGW to follow these steps constructively. Assuming you are right and the MinGW environment I have is not linking libgcc properly, how do I go about getting the environment you've got running?

I'm getting latest compiler with mingw-get.
But, I hope go-sqlite3 works on your environment which don't need any change...

stever commented Dec 10, 2012

I've installed MinGW using minw-get. Now have the same path for the libs C:\MinGW\lib\gcc\mingw32\4.7.2 but the result is the same as before. I still have to use -lgcc_s in sqlite3_windows.go.

Owner
mattn commented Dec 10, 2012

Could you please get the result of go build -x ?

My result in in above: #27 (comment)

stever commented Dec 10, 2012
C:\Users\Steve\Documents\Go\src\github.com\mattn\go-sqlite3>go build -x
WORK=C:\Users\Steve\AppData\Local\Temp\go-build367808483
mkdir -p $WORK\github.com\mattn\go-sqlite3\_obj\
cd C:\Users\Steve\Documents\Go\src\github.com\mattn\go-sqlite3
C:\Go\pkg\tool\windows_386\cgo.exe -objdir $WORK\github.com\mattn\go-sqlite3\_ob
j\ -- -I. -fno-stack-check -fno-stack-protector -mno-stack-arg-probe -I $WORK\gi
thub.com\mattn\go-sqlite3\_obj\ sqlite3.go sqlite3_windows.go
C:\Go\pkg\tool\windows_386\8c.exe -FVw -I $WORK\github.com\mattn\go-sqlite3\_obj
\ -I C:\Go\pkg\windows_386 -o $WORK\github.com\mattn\go-sqlite3\_obj\_cgo_defun.
8 -DGOOS_windows -DGOARCH_386 $WORK\github.com\mattn\go-sqlite3\_obj\_cgo_defun.
c
gcc -I . -g -O2 -m32 -mthreads -I. -fno-stack-check -fno-stack-protector -mno-st
ack-arg-probe -I $WORK\github.com\mattn\go-sqlite3\_obj\ -o $WORK\github.com\mat
tn\go-sqlite3\_obj\_cgo_main.o -c $WORK\github.com\mattn\go-sqlite3\_obj\_cgo_ma
in.c
gcc -I . -g -O2 -m32 -mthreads -I. -fno-stack-check -fno-stack-protector -mno-st
ack-arg-probe -I $WORK\github.com\mattn\go-sqlite3\_obj\ -o $WORK\github.com\mat
tn\go-sqlite3\_obj\_cgo_export.o -c $WORK\github.com\mattn\go-sqlite3\_obj\_cgo_
export.c
gcc -I . -g -O2 -m32 -mthreads -I. -fno-stack-check -fno-stack-protector -mno-st
ack-arg-probe -I $WORK\github.com\mattn\go-sqlite3\_obj\ -o $WORK\github.com\mat
tn\go-sqlite3\_obj\sqlite3.cgo2.o -c $WORK\github.com\mattn\go-sqlite3\_obj\sqli
te3.cgo2.c
gcc -I . -g -O2 -m32 -mthreads -I. -fno-stack-check -fno-stack-protector -mno-st
ack-arg-probe -I $WORK\github.com\mattn\go-sqlite3\_obj\ -o $WORK\github.com\mat
tn\go-sqlite3\_obj\sqlite3_windows.cgo2.o -c $WORK\github.com\mattn\go-sqlite3\_
obj\sqlite3_windows.cgo2.c
gcc -I . -g -O2 -m32 -mthreads -I. -fno-stack-check -fno-stack-protector -mno-st
ack-arg-probe -I $WORK\github.com\mattn\go-sqlite3\_obj\ -o $WORK\github.com\mat
tn\go-sqlite3\_obj\sqlite3_windows.o -c .\sqlite3_windows.c
gcc -I . -g -O2 -m32 -mthreads -o $WORK\github.com\mattn\go-sqlite3\_obj\_cgo_.o
 $WORK\github.com\mattn\go-sqlite3\_obj\_cgo_main.o $WORK\github.com\mattn\go-sq
lite3\_obj\_cgo_export.o $WORK\github.com\mattn\go-sqlite3\_obj\sqlite3.cgo2.o $
WORK\github.com\mattn\go-sqlite3\_obj\sqlite3_windows.cgo2.o $WORK\github.com\ma
ttn\go-sqlite3\_obj\sqlite3_windows.o -lmingwex -lmingw32 -lgcc_s
C:\Go\pkg\tool\windows_386\cgo.exe -objdir $WORK\github.com\mattn\go-sqlite3\_ob
j\ -dynimport $WORK\github.com\mattn\go-sqlite3\_obj\_cgo_.o -dynout $WORK\githu
b.com\mattn\go-sqlite3\_obj\_cgo_import.c
C:\Go\pkg\tool\windows_386\8c.exe -FVw -I $WORK\github.com\mattn\go-sqlite3\_obj
\ -I C:\Go\pkg\windows_386 -o $WORK\github.com\mattn\go-sqlite3\_obj\_cgo_import
.8 -DGOOS_windows -DGOARCH_386 $WORK\github.com\mattn\go-sqlite3\_obj\_cgo_impor
t.c
C:\Go\pkg\tool\windows_386\8g.exe -o $WORK\github.com\mattn\go-sqlite3\_obj\_go_
.8 -p github.com/mattn/go-sqlite3 -D _/C_/Users/Steve/Documents/Go/src/github.co
m/mattn/go-sqlite3 -I $WORK $WORK\github.com\mattn\go-sqlite3\_obj\_cgo_gotypes.
go $WORK\github.com\mattn\go-sqlite3\_obj\sqlite3.cgo1.go $WORK\github.com\mattn
\go-sqlite3\_obj\sqlite3_windows.cgo1.go
C:\Go\pkg\tool\windows_386\pack.exe grcP $WORK $WORK\github.com\mattn\go-sqlite3
.a $WORK\github.com\mattn\go-sqlite3\_obj\_go_.8 $WORK\github.com\mattn\go-sqlit
e3\_obj\_cgo_import.8 $WORK\github.com\mattn\go-sqlite3\_obj\_cgo_defun.8 $WORK\
github.com\mattn\go-sqlite3\_obj\_cgo_export.o $WORK\github.com\mattn\go-sqlite3
\_obj\sqlite3.cgo2.o $WORK\github.com\mattn\go-sqlite3\_obj\sqlite3_windows.cgo2
.o $WORK\github.com\mattn\go-sqlite3\_obj\sqlite3_windows.o

C:\Users\Steve\Documents\Go\src\github.com\mattn\go-sqlite3>    
Owner
mattn commented Dec 10, 2012

@stever Ah, sorry, please remove -lgcc_s before build.

stever commented Dec 10, 2012
C:\Users\Steve\Documents\Go\src\github.com\mattn\go-sqlite3>go build -x
WORK=C:\Users\Steve\AppData\Local\Temp\go-build030297219
mkdir -p $WORK\github.com\mattn\go-sqlite3\_obj\
cd C:\Users\Steve\Documents\Go\src\github.com\mattn\go-sqlite3
C:\Go\pkg\tool\windows_386\cgo.exe -objdir $WORK\github.com\mattn\go-sqlite3\_ob
j\ -- -I. -fno-stack-check -fno-stack-protector -mno-stack-arg-probe -I $WORK\gi
thub.com\mattn\go-sqlite3\_obj\ sqlite3.go sqlite3_windows.go
C:\Go\pkg\tool\windows_386\8c.exe -FVw -I $WORK\github.com\mattn\go-sqlite3\_obj
\ -I C:\Go\pkg\windows_386 -o $WORK\github.com\mattn\go-sqlite3\_obj\_cgo_defun.
8 -DGOOS_windows -DGOARCH_386 $WORK\github.com\mattn\go-sqlite3\_obj\_cgo_defun.
c
gcc -I . -g -O2 -m32 -mthreads -I. -fno-stack-check -fno-stack-protector -mno-st
ack-arg-probe -I $WORK\github.com\mattn\go-sqlite3\_obj\ -o $WORK\github.com\mat
tn\go-sqlite3\_obj\_cgo_main.o -c $WORK\github.com\mattn\go-sqlite3\_obj\_cgo_ma
in.c
gcc -I . -g -O2 -m32 -mthreads -I. -fno-stack-check -fno-stack-protector -mno-st
ack-arg-probe -I $WORK\github.com\mattn\go-sqlite3\_obj\ -o $WORK\github.com\mat
tn\go-sqlite3\_obj\_cgo_export.o -c $WORK\github.com\mattn\go-sqlite3\_obj\_cgo_
export.c
gcc -I . -g -O2 -m32 -mthreads -I. -fno-stack-check -fno-stack-protector -mno-st
ack-arg-probe -I $WORK\github.com\mattn\go-sqlite3\_obj\ -o $WORK\github.com\mat
tn\go-sqlite3\_obj\sqlite3.cgo2.o -c $WORK\github.com\mattn\go-sqlite3\_obj\sqli
te3.cgo2.c
gcc -I . -g -O2 -m32 -mthreads -I. -fno-stack-check -fno-stack-protector -mno-st
ack-arg-probe -I $WORK\github.com\mattn\go-sqlite3\_obj\ -o $WORK\github.com\mat
tn\go-sqlite3\_obj\sqlite3_windows.cgo2.o -c $WORK\github.com\mattn\go-sqlite3\_
obj\sqlite3_windows.cgo2.c
gcc -I . -g -O2 -m32 -mthreads -I. -fno-stack-check -fno-stack-protector -mno-st
ack-arg-probe -I $WORK\github.com\mattn\go-sqlite3\_obj\ -o $WORK\github.com\mat
tn\go-sqlite3\_obj\sqlite3_windows.o -c .\sqlite3_windows.c
gcc -I . -g -O2 -m32 -mthreads -o $WORK\github.com\mattn\go-sqlite3\_obj\_cgo_.o
 $WORK\github.com\mattn\go-sqlite3\_obj\_cgo_main.o $WORK\github.com\mattn\go-sq
lite3\_obj\_cgo_export.o $WORK\github.com\mattn\go-sqlite3\_obj\sqlite3.cgo2.o $
WORK\github.com\mattn\go-sqlite3\_obj\sqlite3_windows.cgo2.o $WORK\github.com\ma
ttn\go-sqlite3\_obj\sqlite3_windows.o -lmingwex -lmingw32 -lgcc_s
C:\Go\pkg\tool\windows_386\cgo.exe -objdir $WORK\github.com\mattn\go-sqlite3\_ob
j\ -dynimport $WORK\github.com\mattn\go-sqlite3\_obj\_cgo_.o -dynout $WORK\githu
b.com\mattn\go-sqlite3\_obj\_cgo_import.c
C:\Go\pkg\tool\windows_386\8c.exe -FVw -I $WORK\github.com\mattn\go-sqlite3\_obj
\ -I C:\Go\pkg\windows_386 -o $WORK\github.com\mattn\go-sqlite3\_obj\_cgo_import
.8 -DGOOS_windows -DGOARCH_386 $WORK\github.com\mattn\go-sqlite3\_obj\_cgo_impor
t.c
C:\Go\pkg\tool\windows_386\8g.exe -o $WORK\github.com\mattn\go-sqlite3\_obj\_go_
.8 -p github.com/mattn/go-sqlite3 -D _/C_/Users/Steve/Documents/Go/src/github.co
m/mattn/go-sqlite3 -I $WORK $WORK\github.com\mattn\go-sqlite3\_obj\_cgo_gotypes.
go $WORK\github.com\mattn\go-sqlite3\_obj\sqlite3.cgo1.go $WORK\github.com\mattn
\go-sqlite3\_obj\sqlite3_windows.cgo1.go
C:\Go\pkg\tool\windows_386\pack.exe grcP $WORK $WORK\github.com\mattn\go-sqlite3
.a $WORK\github.com\mattn\go-sqlite3\_obj\_go_.8 $WORK\github.com\mattn\go-sqlit
e3\_obj\_cgo_import.8 $WORK\github.com\mattn\go-sqlite3\_obj\_cgo_defun.8 $WORK\
github.com\mattn\go-sqlite3\_obj\_cgo_export.o $WORK\github.com\mattn\go-sqlite3
\_obj\sqlite3.cgo2.o $WORK\github.com\mattn\go-sqlite3\_obj\sqlite3_windows.cgo2
.o $WORK\github.com\mattn\go-sqlite3\_obj\sqlite3_windows.o

C:\Users\Steve\Documents\Go\src\github.com\mattn\go-sqlite3>    
Owner
mattn commented Dec 10, 2012

It seems not removed -lgcc_s.

stever commented Dec 10, 2012

I thought I had done, but you're right. Trying again...

C:\Users\Steve\Documents\Go\src\github.com\mattn\go-sqlite3>go build -x
WORK=C:\Users\Steve\AppData\Local\Temp\go-build397327063
mkdir -p $WORK\github.com\mattn\go-sqlite3\_obj\
cd C:\Users\Steve\Documents\Go\src\github.com\mattn\go-sqlite3
C:\Go\pkg\tool\windows_386\cgo.exe -objdir $WORK\github.com\mattn\go-sqlite3\_ob
j\ -- -I. -fno-stack-check -fno-stack-protector -mno-stack-arg-probe -I $WORK\gi
thub.com\mattn\go-sqlite3\_obj\ sqlite3.go sqlite3_windows.go
C:\Go\pkg\tool\windows_386\8c.exe -FVw -I $WORK\github.com\mattn\go-sqlite3\_obj
\ -I C:\Go\pkg\windows_386 -o $WORK\github.com\mattn\go-sqlite3\_obj\_cgo_defun.
8 -DGOOS_windows -DGOARCH_386 $WORK\github.com\mattn\go-sqlite3\_obj\_cgo_defun.
c
gcc -I . -g -O2 -m32 -mthreads -I. -fno-stack-check -fno-stack-protector -mno-st
ack-arg-probe -I $WORK\github.com\mattn\go-sqlite3\_obj\ -o $WORK\github.com\mat
tn\go-sqlite3\_obj\_cgo_main.o -c $WORK\github.com\mattn\go-sqlite3\_obj\_cgo_ma
in.c
gcc -I . -g -O2 -m32 -mthreads -I. -fno-stack-check -fno-stack-protector -mno-st
ack-arg-probe -I $WORK\github.com\mattn\go-sqlite3\_obj\ -o $WORK\github.com\mat
tn\go-sqlite3\_obj\_cgo_export.o -c $WORK\github.com\mattn\go-sqlite3\_obj\_cgo_
export.c
gcc -I . -g -O2 -m32 -mthreads -I. -fno-stack-check -fno-stack-protector -mno-st
ack-arg-probe -I $WORK\github.com\mattn\go-sqlite3\_obj\ -o $WORK\github.com\mat
tn\go-sqlite3\_obj\sqlite3.cgo2.o -c $WORK\github.com\mattn\go-sqlite3\_obj\sqli
te3.cgo2.c
gcc -I . -g -O2 -m32 -mthreads -I. -fno-stack-check -fno-stack-protector -mno-st
ack-arg-probe -I $WORK\github.com\mattn\go-sqlite3\_obj\ -o $WORK\github.com\mat
tn\go-sqlite3\_obj\sqlite3_windows.cgo2.o -c $WORK\github.com\mattn\go-sqlite3\_
obj\sqlite3_windows.cgo2.c
gcc -I . -g -O2 -m32 -mthreads -I. -fno-stack-check -fno-stack-protector -mno-st
ack-arg-probe -I $WORK\github.com\mattn\go-sqlite3\_obj\ -o $WORK\github.com\mat
tn\go-sqlite3\_obj\sqlite3_windows.o -c .\sqlite3_windows.c
gcc -I . -g -O2 -m32 -mthreads -o $WORK\github.com\mattn\go-sqlite3\_obj\_cgo_.o
 $WORK\github.com\mattn\go-sqlite3\_obj\_cgo_main.o $WORK\github.com\mattn\go-sq
lite3\_obj\_cgo_export.o $WORK\github.com\mattn\go-sqlite3\_obj\sqlite3.cgo2.o $
WORK\github.com\mattn\go-sqlite3\_obj\sqlite3_windows.cgo2.o $WORK\github.com\ma
ttn\go-sqlite3\_obj\sqlite3_windows.o -lmingwex -lmingw32
C:\Go\pkg\tool\windows_386\cgo.exe -objdir $WORK\github.com\mattn\go-sqlite3\_ob
j\ -dynimport $WORK\github.com\mattn\go-sqlite3\_obj\_cgo_.o -dynout $WORK\githu
b.com\mattn\go-sqlite3\_obj\_cgo_import.c
C:\Go\pkg\tool\windows_386\8c.exe -FVw -I $WORK\github.com\mattn\go-sqlite3\_obj
\ -I C:\Go\pkg\windows_386 -o $WORK\github.com\mattn\go-sqlite3\_obj\_cgo_import
.8 -DGOOS_windows -DGOARCH_386 $WORK\github.com\mattn\go-sqlite3\_obj\_cgo_impor
t.c
C:\Go\pkg\tool\windows_386\8g.exe -o $WORK\github.com\mattn\go-sqlite3\_obj\_go_
.8 -p github.com/mattn/go-sqlite3 -D _/C_/Users/Steve/Documents/Go/src/github.co
m/mattn/go-sqlite3 -I $WORK $WORK\github.com\mattn\go-sqlite3\_obj\_cgo_gotypes.
go $WORK\github.com\mattn\go-sqlite3\_obj\sqlite3.cgo1.go $WORK\github.com\mattn
\go-sqlite3\_obj\sqlite3_windows.cgo1.go
C:\Go\pkg\tool\windows_386\pack.exe grcP $WORK $WORK\github.com\mattn\go-sqlite3
.a $WORK\github.com\mattn\go-sqlite3\_obj\_go_.8 $WORK\github.com\mattn\go-sqlit
e3\_obj\_cgo_import.8 $WORK\github.com\mattn\go-sqlite3\_obj\_cgo_defun.8 $WORK\
github.com\mattn\go-sqlite3\_obj\_cgo_export.o $WORK\github.com\mattn\go-sqlite3
\_obj\sqlite3.cgo2.o $WORK\github.com\mattn\go-sqlite3\_obj\sqlite3_windows.cgo2
.o $WORK\github.com\mattn\go-sqlite3\_obj\sqlite3_windows.o

C:\Users\Steve\Documents\Go\src\github.com\mattn\go-sqlite3>    
Owner
mattn commented Dec 10, 2012

ok, -lgcc_s is removed, and it seems that you don't get fail to build. :)

Owner
mattn commented Dec 10, 2012

When the build error happen? building example/main.go ? If it so, please show me the result of go build -x main.go.

stever commented Dec 10, 2012

No build error. Just errors when running. Here's the output:

C:\Users\Steve\Documents\Go\src\github.com\mattn\go-sqlite3\example>go run main.go
# command-line-arguments
C:\Users\Steve\AppData\Local\Temp\go-build545176583/github.com/mattn/go-sqlite3.a(sqlite3_windows.)(.text): __moddi3: not defined
C:\Users\Steve\AppData\Local\Temp\go-build545176583/github.com/mattn/go-sqlite3.a(sqlite3_windows.)(.text): __divdi3: not defined
C:\Users\Steve\AppData\Local\Temp\go-build545176583/github.com/mattn/go-sqlite3.a(sqlite3_windows.)(.text): __moddi3: not defined
C:\Users\Steve\AppData\Local\Temp\go-build545176583/github.com/mattn/go-sqlite3.a(sqlite3_windows.)(.text): __divdi3: not defined
C:\Users\Steve\AppData\Local\Temp\go-build545176583/github.com/mattn/go-sqlite3.a(sqlite3_windows.)(.text): __divdi3: not defined
C:\Users\Steve\AppData\Local\Temp\go-build545176583/github.com/mattn/go-sqlite3.a(sqlite3_windows.)(.text): __divdi3: not defined
C:\Users\Steve\AppData\Local\Temp\go-build545176583/github.com/mattn/go-sqlite3.a(sqlite3_windows.)(.text): __divdi3: not defined
C:\Users\Steve\AppData\Local\Temp\go-build545176583/github.com/mattn/go-sqlite3.a(sqlite3_windows.)(.text): __moddi3: not defined
C:\Users\Steve\AppData\Local\Temp\go-build545176583/github.com/mattn/go-sqlite3.a(sqlite3_windows.)(.text): __divdi3: not defined
C:\Users\Steve\AppData\Local\Temp\go-build545176583/github.com/mattn/go-sqlite3.a(sqlite3_windows.)(.text): __moddi3: not defined
C:\Users\Steve\AppData\Local\Temp\go-build545176583/github.com/mattn/go-sqlite3.a(sqlite3_windows.)(.text): __moddi3: not defined
C:\Users\Steve\AppData\Local\Temp\go-build545176583/github.com/mattn/go-sqlite3.a(sqlite3_windows.)(.text): __divdi3: not defined
C:\Users\Steve\AppData\Local\Temp\go-build545176583/github.com/mattn/go-sqlite3.a(sqlite3_windows.)(.text): __divdi3: not defined
C:\Users\Steve\AppData\Local\Temp\go-build545176583/github.com/mattn/go-sqlite3.a(sqlite3_windows.)(.text): __divdi3: not defined
C:\Users\Steve\AppData\Local\Temp\go-build545176583/github.com/mattn/go-sqlite3.a(sqlite3_windows.)(.text): __divdi3: not defined
C:\Users\Steve\AppData\Local\Temp\go-build545176583/github.com/mattn/go-sqlite3.a(sqlite3_windows.)(.text): __moddi3: not defined
C:\Users\Steve\AppData\Local\Temp\go-build545176583/github.com/mattn/go-sqlite3.a(sqlite3_windows.)(.text): __moddi3: not defined
C:\Users\Steve\AppData\Local\Temp\go-build545176583/github.com/mattn/go-sqlite3.a(sqlite3_windows.)(.text): __umoddi3: not defined
C:\Users\Steve\AppData\Local\Temp\go-build545176583/github.com/mattn/go-sqlite3.a(sqlite3_windows.)(.text): __udivdi3: not defined
C:\Users\Steve\AppData\Local\Temp\go-build545176583/github.com/mattn/go-sqlite3.a(sqlite3_windows.)(.text): __umoddi3: not defined
C:\Users\Steve\AppData\Local\Temp\go-build545176583/github.com/mattn/go-sqlite3.a(sqlite3_windows.)(.text): __udivdi3: not defined
too many errors

C:\Users\Steve\Documents\Go\src\github.com\mattn\go-sqlite3\example>    
Owner
mattn commented Dec 10, 2012

If use #cgo LDFLAGS: -lgcc -lgcc_s -lmingwex, it can work ?

stever commented Dec 10, 2012

Actually no - same errors. Still, if I use #cgo LDFLAGS: -lmingwex -lmingw32 -lgcc_s it does. Seems interesting.

Owner
mattn commented Dec 10, 2012

<g> OMG

stever commented Dec 10, 2012

Also built with #cgo LDFLAGS: -lmingwex -lmingw32 -lgcc -lgcc_s and the example doesn't work. It does work if I remove -lgcc to have #cgo LDFLAGS: -lmingwex -lmingw32 -lgcc_s

I'm using the command go install though and I'm not sure if that hides build errors. There was no ouput.

Owner
mattn commented Dec 10, 2012

Hmm, maybe I must write __divdi3 on my code.

stever commented Dec 10, 2012

The example even works for me if all I use is #cgo LDFLAGS: -lgcc_s

stever commented Dec 10, 2012

I'm not so interested in having sqlite3 statically compiled over having it has a DLL dependency. Initially I made a fork and included the following info to help build 32-bit and 64-bit sqlite3.dll on Windows. Perhaps it is useful.

Download the SQLite amalgamation source
and compile using MinGW.

64-bit:

gcc -shared -DWIN64 -DNDEBUG -D_WINDOWS -D_USRDLL -DNO_TCL -D_CRT_SECURE_NO_DEPRECATE -DTHREADSAFE=1 -DTEMP_STORE=1 -DSQLITE_MAX_EXPR_DEPTH=0 -m64 -I. shell.c sqlite3.c -o sqlite3.dll -Wl,--out-implib,sqlite3.a

32-bit:

gcc -shared -DWIN32 -D_WINDOWS -D_USRDLL -DNO_TCL -D_CRT_SECURE_NO_DEPRECATE -DTHREADSAFE=1 -DTEMP_STORE=1 -DSQLITE_MAX_EXPR_DEPTH=0 -m32 -I. shell.c sqlite3.c -o sqlite3.dll -Wl,--out-implib,sqlite3.a
  • Copy sqlite3.dll to a location included in LIBRARY_PATH.
  • Copy sqlite3.h and sqlite3ext.h to a location included in C_INCLUDE_PATH.

See Compiling SQLite for Windows (64-bit)

stever commented Dec 10, 2012

I had struggled without the above info to make 32-bit and 64-bit versions of the sqlite3.dll which I required.

Owner
mattn commented Dec 10, 2012

Probably, whether compiler use divdi3 or not, is related on CPU. On my
environment, the optimization is disabled maybe. And probably your is
enabled. i.e. divdi3 is not linked from libgcc.a on my environment,
And libgcc_s.a is linked not properly(compiler isn't expected).

On 12/10/12, Steven Robertson notifications@github.com wrote:

I had struggled without the above info to make 32-bit and 64-bit versions of
the sqlite3.dll which I required.


Reply to this email directly or view it on GitHub:
#27 (comment)

  • Yasuhiro Matsumoto
stever commented Dec 10, 2012

I've only tested using Windows in VMware for 32-bit, though hosted on systems with both 64-bit Intel and AMD CPU.

Owner
mattn commented Dec 10, 2012

I'll try to build without optimization of CPU arch in next time.

On 12/11/12, Steven Robertson notifications@github.com wrote:

I've only tested using Windows in VMware for 32-bit, though hosted on
systems with both 64-bit Intel and AMD CPU.


Reply to this email directly or view it on GitHub:
#27 (comment)

  • Yasuhiro Matsumoto
stever commented Dec 14, 2012

Ah, a resolved issue in Go. I'm not keen to compile Go on Windows, though maybe it's easy... I'll give it a go.

stever commented Dec 14, 2012

Actually, building tip from source is no problem. Just need Mercurial installed... and it works!

No need for the -lgcc_s flag at all with Go source tip revision, on either 32-bit Windows or 64-bit Windows.

Thanks for the resolution.

Contributor

Trying install Go from source, fails on compilation time and even that it look like Go working I couldn't go get some packages (but go get github.com/gorilla/mux worked o_O ):

d:\Dropbox\_Politechnika>go get code.google.com/p/go.crypto/scrypt
package code.google.com/p/go.crypto/scrypt: Get https://code.google.com/p/go/source/checkout?repo=crypto: dial tcp 173.194.65.138:443: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.

d:\Dropbox\_Politechnika>go get thegoods.biz/httpbuf
package thegoods.biz/httpbuf: unrecognized import path "thegoods.biz/httpbuf"

Move back to Windows installer and go get working again

But when I have Go installed from source go-sqlite3 worked OK without -lgcc_s flag.

I would leave that issue open until Go stable release will fix it (next year?).

Best regards

Owner
mattn commented Feb 13, 2013

Did you make sure this issue on hg tip?

Contributor

Working without problems on tip.

Best regards,
Dobrosław Żybort

Owner
mattn commented Feb 13, 2013

@matrixik thank you! is this closable?

Contributor

Yes.
But maybe you can add some info to readme that there can be problems with Go 1.0 on Windows with link to this issue (or specific post showing how to fix it).

Best regards,
Dobrosław Żybort

@mattn mattn added a commit that referenced this issue Feb 13, 2013
@mattn Updated doc. Added link to #27 #39 716b2f5
Owner
mattn commented Feb 13, 2013

Thank you all.

@mattn mattn closed this Feb 13, 2013
@mattn mattn added a commit that referenced this issue Dec 15, 2016
@mattn fix #27 77eae5a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment