3

I'm new to the go-lang. I want to use go command to build a binary named cryptogen (hyperledger/fabric tool). I download the source code from github and type the following command accroding to readme:

CGO_CFLAGS=" " GOBIN=/hyperledger/src/github.com/hyperledger/fabric/build/bin go install -tags "" -ldflags "-X github.com/hyperledger/fabric/common/tools/cryptogen/metadata.Version=1.0.7" github.com/hyperledger/fabric/common/tools/cryptogen

On my Mac OS (OS version is 10.13, go-lang version is 1.10) I'm getting the following error:

go build github.com/hyperledger/fabric/vendor/github.com/miekg/pkcs11: invalid flag in #cgo LDFLAGS: -I/usr/local/share/libtool

I thought I missing libtool, after installed it, I'm still getting the same error.

What can I do next?

rollstuhlfahrer
  • 3,988
  • 9
  • 25
  • 38
louis
  • 63
  • 1
  • 4

3 Answers3

2

Just as an FYI, PKCS11 is not really required to use cryptogen. You can actually use -tags "nopkcs11"

Gari Singh
  • 11,418
  • 2
  • 18
  • 41
1

This is apparently a recent problem (Github PR) made in Go 1.9.4 and 1.10 to fix a security (associated Go commit)

The fix was made 22 days ago, but the library you are using github.com/hyperledger/fabric uses a vendored version of the pkcs11 library.

Personally I would see if installing github.com/miekg/pkcs11 HEAD, and removing the vendor directory solves the issue. If it works, create an issue for the fabric author to update the vendoered version or remove it altogether. There is a possibility (depending on the age of the vendored version) that there was already a breaking change made.

Read through the initial issue as well. It appears you can use

CGO_LDFLAGS_ALLOW='-Wl,--no-as-needed' go install

as well.

sberry
  • 128,281
  • 18
  • 138
  • 165
  • I remove '/usr/local/share/libtool' from github.com/miekg/pkcs11 HEAD and then build successfully. – louis Mar 05 '18 at 01:47
1

This behavior has been fixed in GO version 1.10 (the release candidates still had this issue). Yesterday, I've got everything compiled after migrating to GO v1.10 (Ubuntu).

See also: https://go-review.googlesource.com/c/go/+/93836/7/src/cmd/go/internal/work/security.go

  • After installing version 1.10, I was then getting the following error: `ltdl.h: No such file or directory compilation terminated.`. To fix this, ran the following command: `sudo apt-get install libtool` – Flea Mar 16 '18 at 14:59