hyperledger-fabric1.0.0版本make docker时报错
因为项目需要,我们改了fabric1.0.0的core/chaincode/shim的代码,对应shim的树形结构如下:
shim
├── chaincode.go
├── handler.go
├── inprocstream.go
├── interfaces.go
├── java
│ └── ···
├── mockstub.go
├── mockstub_test.go
├── response.go
├── myxxxutil.go
├── shim_test.go
└── myxxx.go
其中有一些功能需要cgo,然后这部分代码使用c++实现,对应的代码片段如下:
//这个文件对应的目录是/hyperledger/fabric/core/chaincode/shim/myxxx.go
package shim
/*
#cgo CFLAGS: -I/opt/xxxsrc
#cgo LDFLAGS: -L/usr/lib -lmyxxx
#include "interface.hpp"
#include <stdlib.h>
*/
import "C"
func SomeFucn() {
···
//其中/opt/xxxsrc里面是c++源代码,interface.hpp也在该目录下,/usr/lib下存放对应的libmyxxx.so文件
}
接着,我在fabric目录下使用make docker命令制作基于hyperledger/fabric-baseimage:x86_64-0.3.1的peer镜像,这个hyperledger/fabric-baseimage:x86_64-0.3.1已经被我修改过,我把libmyxxx.so文件放入了该镜像的/usr/lib目录下,也把xxxsrc放在了该镜像的/opt/xxxsrc目录下,然后对应执行日志如下
Building build/docker/bin/peer
(对应执行的docker命令为:
docker run -i --rm --user=0 -v /home/my/gopath/src/github.com/hyperledger/fabric:/opt/gopath/src/github.com/hyperledger/fabric -w /opt/gopath/src/github.com/hyperledger/fabric -v /home/my/gopath/src/github.com/hyperledger/fabric/build/docker/bin:/opt/gopath/bin -v /home/my/gopath/src/github.com/hyperledger/fabric/build/docker/peer/pkg:/opt/gopath/pkg hyperledger/fabric-baseimage:x86_64-0.3.1
go install -ldflags "-X github.com/hyperledger/fabric/common/metadata.Version=1.0.0 -X github.com/hyperledger/fabric/common/metadata.BaseVersion=0.3.1 -X github.com/hyperledger/fabric/common/metadata.BaseDockerLabel=org.hyperledger.fabric -X github.com/hyperledger/fabric/common/metadata.DockerNamespace=hyperledger -X github.com/hyperledger/fabric/common/metadata.BaseDockerNamespace=hyperledger -linkmode external -extldflags -static -lpthread" github.com/hyperledger/fabric/peer
)
github.com/hyperledger/fabric/core/chaincode/shim
mkdir -p $WORK/github.com/hyperledger/fabric/core/chaincode/shim/_obj/
cd /opt/gopath/src/github.com/hyperledger/fabric/core/chaincode/shim
CGO_LDFLAGS="-g" "-O2" "-L/usr/lib" "-lmyxxx" "-L/usr/lib" "-lmyxxx" /opt/go/pkg/tool/linux_amd64/cgo -objdir $WORK/github.com/hyperledger/fabric/core/chaincode/shim/_obj/ -importpath github.com/hyperledger/fabric/core/chaincode/shim -- -I $WORK/github.com/hyperledger/fabric/core/chaincode/shim/_obj/ -I/opt/xxxsrc -I/opt/xxxsrc myxxxutil.go myxxx.go
cd /opt/gopath/src/github.com/hyperledger/fabric/core/chaincode/shim
gcc -I . -fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=$WORK=/tmp/go-build -gno-record-gcc-switches -I $WORK/github.com/hyperledger/fabric/core/chaincode/shim/_obj/ -g -O2 -I/opt/xxxsrc -I/opt/xxxsrc -o $WORK/github.com/hyperledger/fabric/core/chaincode/shim/_obj/_cgo_main.o -c $WORK/github.com/hyperledger/fabric/core/chaincode/shim/_obj/_cgo_main.c
cd /opt/gopath/src/github.com/hyperledger/fabric/core/chaincode/shim
gcc -I . -fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=$WORK=/tmp/go-build -gno-record-gcc-switches -I $WORK/github.com/hyperledger/fabric/core/chaincode/shim/_obj/ -g -O2 -I/opt/xxxsrc -I/opt/xxxsrc -o $WORK/github.com/hyperledger/fabric/core/chaincode/shim/_obj/_cgo_export.o -c $WORK/github.com/hyperledger/fabric/core/chaincode/shim/_obj/_cgo_export.c
gcc -I . -fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=$WORK=/tmp/go-build -gno-record-gcc-switches -I $WORK/github.com/hyperledger/fabric/core/chaincode/shim/_obj/ -g -O2 -I/opt/xxxsrc -I/opt/xxxsrc -o $WORK/github.com/hyperledger/fabric/core/chaincode/shim/_obj/myxxxutil.cgo2.o -c $WORK/github.com/hyperledger/fabric/core/chaincode/shim/_obj/myxxxutil.cgo2.c
gcc -I . -fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=$WORK=/tmp/go-build -gno-record-gcc-switches -I $WORK/github.com/hyperledger/fabric/core/chaincode/shim/_obj/ -g -O2 -I/opt/xxxsrc -I/opt/xxxsrc -o $WORK/github.com/hyperledger/fabric/core/chaincode/shim/_obj/xxx.cgo2.o -c $WORK/github.com/hyperledger/fabric/core/chaincode/shim/_obj/xxx.cgo2.c
cd /opt/gopath/src/github.com/hyperledger/fabric/core/chaincode/shim
gcc -I . -fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=$WORK=/tmp/go-build -gno-record-gcc-switches -o $WORK/github.com/hyperledger/fabric/core/chaincode/shim/_obj/_cgo_.o $WORK/github.com/hyperledger/fabric/core/chaincode/shim/_obj/_cgo_main.o $WORK/github.com/hyperledger/fabric/core/chaincode/shim/_obj/_cgo_export.o $WORK/github.com/hyperledger/fabric/core/chaincode/shim/_obj/myxxxutil.cgo2.o $WORK/github.com/hyperledger/fabric/core/chaincode/shim/_obj/myxxx.cgo2.o -g -O2 -L/usr/lib -lmyxxx -L/usr/lib -lmyxxx
cd /opt/gopath/src/github.com/hyperledger/fabric/core/chaincode/shim
/opt/go/pkg/tool/linux_amd64/cgo -objdir $WORK/github.com/hyperledger/fabric/core/chaincode/shim/_obj/ -dynpackage shim -dynimport $WORK/github.com/hyperledger/fabric/core/chaincode/shim/_obj/_cgo_.o -dynout $WORK/github.com/hyperledger/fabric/core/chaincode/shim/_obj/_cgo_import.go
gcc -I . -fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=$WORK=/tmp/go-build -gno-record-gcc-switches -o $WORK/github.com/hyperledger/fabric/core/chaincode/shim/_obj/_all.o $WORK/github.com/hyperledger/fabric/core/chaincode/shim/_obj/_cgo_export.o $WORK/github.com/hyperledger/fabric/core/chaincode/shim/_obj/myxxxutil.cgo2.o $WORK/github.com/hyperledger/fabric/core/chaincode/shim/_obj/myxxx.cgo2.o -g -O2 -L/usr/lib -L/usr/lib -Wl,-r -nostdlib -no-pie -Wl,--build-id=none
/opt/go/pkg/tool/linux_amd64/compile -o $WORK/github.com/hyperledger/fabric/core/chaincode/shim.a -trimpath $WORK -p github.com/hyperledger/fabric/core/chaincode/shim -buildid 2ee9889b3f3fdd6fc02e5029d94e8c287f977ccb -importmap github.com/golang/protobuf/proto=github.com/hyperledger/fabric/vendor/github.com/golang/protobuf/proto -importmap github.com/golang/protobuf/ptypes/timestamp=github.com/hyperledger/fabric/vendor/github.com/golang/protobuf/ptypes/timestamp -importmap github.com/looplab/fsm=github.com/hyperledger/fabric/vendor/github.com/looplab/fsm -importmap github.com/op/go-logging=github.com/hyperledger/fabric/vendor/github.com/op/go-logging -importmap github.com/spf13/viper=github.com/hyperledger/fabric/vendor/github.com/spf13/viper -importmap golang.org/x/net/context=github.com/hyperledger/fabric/vendor/golang.org/x/net/context -importmap google.golang.org/grpc=github.com/hyperledger/fabric/vendor/google.golang.org/grpc -D _/opt/gopath/src/github.com/hyperledger/fabric/core/chaincode/shim -I $WORK -I /opt/gopath/pkg/linux_amd64 -pack ./chaincode.go ./fileIO.go ./handler.go ./inprocstream.go ./interfaces.go ./mockstub.go ./response.go $WORK/github.com/hyperledger/fabric/core/chaincode/shim/_obj/_cgo_gotypes.go $WORK/github.com/hyperledger/fabric/core/chaincode/shim/_obj/myxxxutil.cgo1.go $WORK/github.com/hyperledger/fabric/core/chaincode/shim/_obj/myxxx.cgo1.go $WORK/github.com/hyperledger/fabric/core/chaincode/shim/_obj/_cgo_import.go
cd /opt/gopath/src/github.com/hyperledger/fabric/core/chaincode/shim
pack r $WORK/github.com/hyperledger/fabric/core/chaincode/shim.a $WORK/github.com/hyperledger/fabric/core/chaincode/shim/_obj/_all.o # internal
cp $WORK/github.com/hyperledger/fabric/core/chaincode/shim.a /opt/gopath/pkg/linux_amd64/github.com/hyperledger/fabric/core/chaincode/shim.a
/opt/go/pkg/tool/linux_amd64/link -o $WORK/github.com/hyperledger/fabric/peer/_obj/exe/a.out -L $WORK -L /opt/gopath/pkg/linux_amd64 -extld=gcc -buildmode=exe -buildid=c7ee3188106eddcbae7255ad032536402bc38b29 -X github.com/hyperledger/fabric/common/metadata.Version=1.0.0 -X github.com/hyperledger/fabric/common/metadata.BaseVersion=0.3.1 -X github.com/hyperledger/fabric/common/metadata.BaseDockerLabel=org.hyperledger.fabric -X github.com/hyperledger/fabric/common/metadata.DockerNamespace=hyperledger -X github.com/hyperledger/fabric/common/metadata.BaseDockerNamespace=hyperledger -linkmode external -extldflags "-static -lpthread" $WORK/github.com/hyperledger/fabric/peer.a
# github.com/hyperledger/fabric/peer
/opt/go/pkg/tool/linux_amd64/link: running gcc failed: exit status 1
/usr/bin/ld: cannot find -lmyxxx
/usr/bin/ld: cannot find -lmyxxx
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libltdl.a(dlopen.o): In function `vm_open':
(.text+0x5e): warning: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/tmp/go-link-940349017/000001.o: In function `_cgo_7a2d42f1a351_C2func_getaddrinfo':
/tmp/workdir/go/src/net/cgo_unix.go:66: warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
collect2: error: ld returned 1 exit status
Makefile:197: recipe for target 'build/docker/bin/peer' failed
make: *** [build/docker/bin/peer] Error 2
我已经尝试过加入路径在/etc/ld.so.conf文件里,并且执行了ldconfig,也尝试过增加路径到环境变量LD_LIBRARY_PATH和LIBRARY_PATH中,问题依然重现,所以想请问各路大神有没有什么解决方法,在此谢谢了
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论