Из-за необходимости проекта мы изменили ядро / цепной код / шим из ткани 1.0.0.Древовидная структура 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 ++, есть фрагмент кода:
//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(){
··· //the C++ source code is in /opt/xxxsrc folder,so is interface.hpp file,the libmyxxx.so file is in /usr/lib folder
}
Я использовал makeКоманда docker для создания однорангового образа на основе hyperledger / fabric-baseimage: x86_64-0.3.1 в каталоге Fabric.Этот hyperledger / fabric-baseimage: x86_64-0.3.1 был изменен мной.Я поставил libmyxxx.так что файл в папку / usr / lib этого "baseimage", и поместите код С ++ soure в / opt / xxxsrc, тогда журнал выполнения:
Building build/docker/bin/peer
(the docker command line is:
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
Я уже пытался добавить путь (/ usr/ lib) в файле /etc/ld.so.conf и выполнили команду «ldconfig», а также попытались добавить путь к переменным среды LD_LIBRARY_PATH и LIBRARY_PATH, проблема все еще появляется, поэтому я хотел бы спросить, есть ли какое-либо решение дляпроблема, спасибо