Giter Club home page Giter Club logo

Comments (12)

kjellski avatar kjellski commented on August 19, 2024 1

I've got a similar problem trying to build this on windows failed with go get, for both versions:

import "gopkg.in/libgit2/git2go.v22"

import "github.com/libgit2/git2go"

I'm always having the problem that gcc is told to look at the wrong directory:

# gopkg.in/libgit2/git2go.v22
gcc: error: Files: No such file or directory
gcc: error: (x86)/libgit2/include: No such file or directory

#github.com/libgit2/git2go
gcc: error: Files: No such file or directory
gcc: error: (x86)/libgit2/include: No such file or directory

Has anyone an idea on how to circumvent this? I'm completely new to go, any help would be greatly appreciated.

from git2go.

carlosmn avatar carlosmn commented on August 19, 2024

That looks like what happens when you don't use 'make install' to install the package. None of this should have anything to do with Windows, especially if you're building on MinGW which takes away the Windows system.

from git2go.

carlosmn avatar carlosmn commented on August 19, 2024

If you did install via 'make install', then it looks like whatever compiler you're using does not accept the flags we pass in order to combine the static archive with libgit2 in it and script/with-static.sh would have to be modifed to detect the compiler and figure out how to pass data to it.

from git2go.

vadimi avatar vadimi commented on August 19, 2024

I tried to do it through make install as well. It works only when add -lws2_32 to CGO_LDFLAGS in script/with-static.sh and add -G"MinGW Makefiles" option to cmake in build-libgit2-static.sh (otherwise it uses Visual Studio). It installs successfully, but I get different errors while compiling target app:

github.com/libgit2/git2go(.text): strdup: not defined
github.com/libgit2/git2go(.text): strdup: not defined
github.com/libgit2/git2go(.text): strdup: not defined
github.com/libgit2/git2go(.text): close: not defined
github.com/libgit2/git2go(.text): close: not defined
github.com/libgit2/git2go(.text): close: not defined
github.com/libgit2/git2go(.text): strdup: not defined
github.com/libgit2/git2go(.text): strdup: not defined

from git2go.

clns avatar clns commented on August 19, 2024

UPDATE 2

If specifying -lws2_32 to CGO_LDFLAGS as @vadimi said, the errors below disappear, instead these errors pop up:

...
C:/Users/Calin/go/src/github.com/libgit2/git2go/vendor/libgit2/build/libgit2.a(winhttp.c.obj):winhttp.c:(.text+0x212a): undefined reference to `WinHttpQueryOption'
C:/Users/Calin/go/src/github.com/libgit2/git2go/vendor/libgit2/build/libgit2.a(winhttp.c.obj):winhttp.c:(.text+0x217f): undefined reference to `__imp_CertFreeCertificateContext'
C:/Users/Calin/go/src/github.com/libgit2/git2go/vendor/libgit2/build/libgit2.a(winhttp.c.obj):winhttp.c:(.text+0x21fd): undefined reference to `WinHttpSetOption'
C:/Users/Calin/go/src/github.com/libgit2/git2go/vendor/libgit2/build/libgit2.a(winhttp.c.obj):winhttp.c:(.text+0x222f): undefined reference to `WinHttpSendRequest'
collect2.exe: error: ld returned 1 exit status

UPDATE 1

The compiled library git.lib was for x86, even though I was using an x64 cross compile command prompt. I managed to create an x64 version by specifying the generator to the cmake command, as -G"Visual Studio 12 Win64".

After more research I think I should use -G"MinGW Makefiles", which results in the following errors when running ./script/with-static.sh go install:

C:/Users/Calin/go/src/github.com/libgit2/git2go/vendor/libgit2/build/libgit2.a(index.c.obj):index.c:(.text+0xd04): undefined reference to `__imp_ntohl'
C:/Users/Calin/go/src/github.com/libgit2/git2go/vendor/libgit2/build/libgit2.a(index.c.obj):index.c:(.text+0xec1): undefined reference to `__imp_ntohs'
...
C:/Users/Calin/go/src/github.com/libgit2/git2go/vendor/libgit2/build/libgit2.a(winhttp.c.obj):winhttp.c:(.text+0x19f4): undefined reference to `__imp_CertFreeCertificateContext'
...
C:/Users/Calin/go/src/github.com/libgit2/git2go/vendor/libgit2/build/libgit2.a(socket_stream.c.obj):socket_stream.c:(.text+0x44): undefined reference to `__imp_closesocket'
C:/Users/Calin/go/src/github.com/libgit2/git2go/vendor/libgit2/build/libgit2.a(socket_stream.c.obj):socket_stream.c:(.text+0x4f): undefined reference to `__imp_WSACleanup'
...
C:/Users/Calin/go/src/github.com/libgit2/git2go/vendor/libgit2/build/libgit2.a(socket_stream.c.obj):socket_stream.c:(.text+0x3a6): undefined reference to `__imp_WSAGetLastError'
collect2.exe: error: ld returned 1 exit status

ORIGINAL MESSAGE

Is anyone able to make this work on Windows?

I managed to compile libgit2, have it installed at C:\libgit2 (to avoid spaces in the path, like the error @kjellski mentioned), set the PKG_CONFIG_PATH to C:\libgit2\lib\pkgconfig, but when I run go install it says ld.exe skipping incompatible git2.lib, like below:

$ go install
# github.com/libgit2/git2go
C:/mingw-w64/x86_64-5.1.0-win32-seh-rt_v4-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mi
ngw32/bin/ld.exe: skipping incompatible .\vendor\libgit2\build\Debug/git2.lib when searching for -lgit2
C:/mingw-w64/x86_64-5.1.0-win32-seh-rt_v4-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mi
ngw32/bin/ld.exe: skipping incompatible .\vendor\libgit2\build\Debug/git2.lib when searching for -lgit2
C:/mingw-w64/x86_64-5.1.0-win32-seh-rt_v4-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mi
ngw32/bin/ld.exe: skipping incompatible .\vendor\libgit2\build\Debug\git2.lib when searching for -lgit2
C:/mingw-w64/x86_64-5.1.0-win32-seh-rt_v4-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mi
ngw32/bin/ld.exe: cannot find -lgit2
collect2.exe: error: ld returned 1 exit status

I'm using:

The complete list of commands is:

go get -d github.com/libgit2/git2go
cd $GOPATH/src/github.com/libgit2/git2go
git checkout next
git submodule update --init # get libgit2
cd vendor/libgit2

mkdir build
cd build
cmake -DTHREADSAFE=ON -DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX=C:/libgit2 ..
cmake --build . --target install

cd ..\..\..
$env:PKG_CONFIG_PATH="C:\libgit2\lib\pkgconfig"
go install
# errors follow ...

I also tried the make install method using MSYS2's MINGW64, that also fails with output such as:

[100%] Linking C static library libgit2.a
mingw32-make.exe[3]: Leaving directory 'C:/Users/Calin/go/src/github.com/libgit2/git2go/vendor/libgit2/build'
[100%] Built target git2
mingw32-make.exe[2]: Leaving directory 'C:/Users/Calin/go/src/github.com/libgit2/git2go/vendor/libgit2/build'
mingw32-make.exe[1]: Leaving directory 'C:/Users/Calin/go/src/github.com/libgit2/git2go/vendor/libgit2/build'
./script/with-static.sh go install ./...
+ export BUILD=C:/Users/Calin/go/src/github.com/libgit2/git2go/vendor/libgit2/build
+ BUILD=C:/Users/Calin/go/src/github.com/libgit2/git2go/vendor/libgit2/build
+ export PCFILE=C:/Users/Calin/go/src/github.com/libgit2/git2go/vendor/libgit2/build/libgit2.pc
+ PCFILE=C:/Users/Calin/go/src/github.com/libgit2/git2go/vendor/libgit2/build/libgit2.pc
++ pkg-config --static --libs C:/Users/Calin/go/src/github.com/libgit2/git2go/vendor/libgit2/build/libgit2.pc
+ FLAGS='-LC:/Users/Calin/go/src/github.com/libgit2/git2go/vendor/libgit2/install/lib -lgit2 '
+ export 'CGO_LDFLAGS=C:/Users/Calin/go/src/github.com/libgit2/git2go/vendor/libgit2/build/libgit2.a -LC:/Users/Calin/go/src/github.com/libgit2/git2go/vendor/libgit2/build -LC:/Users/Calin/go/src/github.com/libgit2/git2go/vendor/libgit2/install/lib -lgit2  -lws2_32'
+ CGO_LDFLAGS='C:/Users/Calin/go/src/github.com/libgit2/git2go/vendor/libgit2/build/libgit2.a -LC:/Users/Calin/go/src/github.com/libgit2/git2go/vendor/libgit2/build -LC:/Users/Calin/go/src/github.com/libgit2/git2go/vendor/libgit2/install/lib -lgit2  -lws2_32'
+ export CGO_CFLAGS=-IC:/Users/Calin/go/src/github.com/libgit2/git2go/vendor/libgit2/include
+ CGO_CFLAGS=-IC:/Users/Calin/go/src/github.com/libgit2/git2go/vendor/libgit2/include
+ go install ./...
# github.com/libgit2/git2go
C:/Users/Calin/go/src/github.com/libgit2/git2go/vendor/libgit2/build/libgit2.a(winhttp.c.obj): In function `winhttp_stream_close':
C:/Users/Calin/go/src/github.com/libgit2/git2go/vendor/libgit2/src/transports/winhttp.c:261: undefined reference to `WinHttpCloseHandle'
C:/Users/Calin/go/src/github.com/libgit2/git2go/vendor/libgit2/build/libgit2.a(winhttp.c.obj): In function `write_chunk':
C:/Users/Calin/go/src/github.com/libgit2/git2go/vendor/libgit2/src/transports/winhttp.c:498: undefined reference to `WinHttpWriteData'
...
C:/Users/Calin/go/src/github.com/libgit2/git2go/vendor/libgit2/build/libgit2.a(winhttp.c.obj): In function `put_uuid_string':
C:/Users/Calin/go/src/github.com/libgit2/git2go/vendor/libgit2/src/transports/winhttp.c:995: undefined reference to `__imp_UuidCreate'
collect2.exe: error: ld returned 1 exit status
makefile:11: recipe for target 'install' failed
mingw32-make: *** [install] Error 2

from git2go.

vadimi avatar vadimi commented on August 19, 2024

@clns I tried the same things and couldn't get it working. So I ended up compiling libgit2 to a separate dll and used dynamic linking instead of static one. I believe that there are some bugs in cgo (see golang/go#7555) that will be fixed in go 1.5, so I'd suggest to try once again then.

from git2go.

clns avatar clns commented on August 19, 2024

Thanks, I ended up compiling it using -G"MinGW Makefiles" into a .dll and it did install. However using git2go in a program is still not working, it crashes pretty bad 😄

image

It could be that I overlooked something because I tried so many combinations today that I'm overwhelmed right now.

from git2go.

vadimi avatar vadimi commented on August 19, 2024

Try to put libgit2.dll side by side with your executable or somewhere in your %PATH%.

from git2go.

clns avatar clns commented on August 19, 2024

That worked, thanks!!! Should be interesting to see if this can be fixed before Go 1.5. Till' then, I guess this solution would work.

from git2go.

clns avatar clns commented on August 19, 2024

Anyone having any luck compiling git2go as a static library on Windows amd64 with go 1.5? I'm trying the steps from above but with the same results.

$ go install
C:/libgit2/lib/libgit2.a(index.c.obj):index.c:(.text+0xd04): undefined reference to `__imp_ntohl'
C:/libgit2/lib/libgit2.a(index.c.obj):index.c:(.text+0x59ab): undefined reference to `__imp_htonl'
...
C:/libgit2/lib/libgit2.a(winhttp.c.obj):winhttp.c:(.text+0x68): undefined reference to `WinHttpWriteData'
...
C:/libgit2/lib/libgit2.a(indexer.c.obj):indexer.c:(.text+0x853): undefined reference to `__imp_ntohl'
...

I have compiled libgit2 without any errors, at vendor\libgit2\build\libgit2.a.

from git2go.

carlosmn avatar carlosmn commented on August 19, 2024

As far as the WinHTTP errors, adding -lwinhttp -lcrypt32 -lrpcrt4 -lole32 to CGO_LDFLAGS in ./script/with-static.sh should make it work (those don't get written to the .pc file atm as they don't need to get detected).

If it's completely failing to find the libc/crt functions... then I don't know. The Windows system where I have go installed fails to build libgit2 with gcc so I haven't been able to investigate more.

from git2go.

clns avatar clns commented on August 19, 2024

I was able to successfully build on Windows from a MinGW Shell installed using MSYS2. See PR #307

from git2go.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.