lni / dragonboat

A feature complete and high performance multi-group Raft library in Go.
Apache License 2.0
5.05k stars 540 forks source link

compile error #21

Closed hnwyllmm closed 5 years ago

hnwyllmm commented 5 years ago

master分支和release2.0都会报这个错误:

CGO_CFLAGS="-I$RAFT_HOME/include" CGO_LDFLAGS="-L$RAFT_HOME/lib -lrocksdb" go build -v 
github.com/lni/dragonboat/internal/logdb/gorocksdb
# github.com/lni/dragonboat/internal/logdb/gorocksdb
internal/logdb/gorocksdb/optionsnoop.go:5:13: undefined: Options
internal/logdb/gorocksdb/optionsnoop.go:8:13: undefined: Options
internal/logdb/gorocksdb/optionsnoop.go:11:13: undefined: Options
internal/logdb/gorocksdb/optionsnoop.go:14:13: undefined: ReadOptions
internal/logdb/gorocksdb/optionsnoop.go:17:13: undefined: CompactionOptions
echo $CGO_CFLAGS
-I/data02/wangyl11/raft/include
echo $CGO_LDFLAGS
-L/data02/wangyl11/raft/lib -lrocksdb

rocksdb version 5.18 gcc 5.2.0 go 1.10(source compiled)

hnwyllmm commented 5 years ago

more information use -x build option:

[wangyl11@host-10-19-18-65 dragonboat]$ CGO_CFLAGS="-I$RAFT_HOME/include" CGO_LDFLAGS="-L$RAFT_HOME/lib -lrocksdb" go build -v -x 
WORK=/tmp/go-build671097247
github.com/lni/dragonboat/internal/logdb/gorocksdb
mkdir -p $WORK/b128/
cat >$WORK/b128/importcfg << 'EOF' # internal
# import config
packagefile bytes=/data02/wangyl11/raft/project/go/pkg/linux_amd64/bytes.a
packagefile errors=/data02/wangyl11/raft/project/go/pkg/linux_amd64/errors.a
packagefile fmt=/data02/wangyl11/raft/project/go/pkg/linux_amd64/fmt.a
packagefile io=/data02/wangyl11/raft/project/go/pkg/linux_amd64/io.a
packagefile reflect=/data02/wangyl11/raft/project/go/pkg/linux_amd64/reflect.a
EOF
cd /data02/wangyl11/raft/project/gopath/src/github.com/lni/dragonboat/internal/logdb/gorocksdb
/data02/wangyl11/raft/project/go/pkg/tool/linux_amd64/compile -o $WORK/b128/_pkg_.a -trimpath $WORK/b128 -p github.com/lni/dragonboat/internal/logdb/gorocksdb -complete -buildid EzM3JjSTC2GwhCDCGdyc/EzM3JjSTC2GwhCDCGdyc -D "" -importcfg $WORK/b128/importcfg -pack -c=4 ./doc.go ./options_compression.go ./optionsnoop.go
# github.com/lni/dragonboat/internal/logdb/gorocksdb
internal/logdb/gorocksdb/optionsnoop.go:5:13: undefined: Options
internal/logdb/gorocksdb/optionsnoop.go:8:13: undefined: Options
internal/logdb/gorocksdb/optionsnoop.go:11:13: undefined: Options
internal/logdb/gorocksdb/optionsnoop.go:14:13: undefined: ReadOptions
internal/logdb/gorocksdb/optionsnoop.go:17:13: undefined: CompactionOptions

gorocksdb has been installed

lni commented 5 years ago

I couldn't reproduce your problem. Could you please provide the full go build -v -x output?

On my system using Go 1.10, gcc 5.5 and rocksdb 5.17.2, I can see the following in my output -

github.com/lni/dragonboat/internal/logdb/gorocksdb
mkdir -p $WORK/b123/
cd /home/lni/golang_ws/src/github.com/lni/dragonboat/internal/logdb/gorocksdb
CGO_LDFLAGS='"-L/home/lni/golang_ws/src/github.com/lni/dragonboat/build/lib" "-lrocksdb" "-lrocksdb" "-lstdc++" "-lm"' /usr/local/go/pkg/tool/linux_amd64/cgo -objdir $WORK/b123/ -importpath github.com/lni/dragonboat/internal/logdb/gorocksdb -- -I $WORK/b123/ -I//home/lni/golang_ws/src/github.com/lni/dragonboat/build/include ./backup.go ./cache.go ./cf_handle.go ./checkpoint.go ./compaction_filter.go ./comparator.go ./db.go ./dynflag.go ./env.go ./filter_policy.go ./iterator.go ./merge_operator.go ./options.go ./options_block_based_table.go ./options_compaction.go ./options_env.go ./options_flush.go ./options_ingest.go ./options_read.go ./options_transaction.go ./options_transactiondb.go ./options_write.go ./ratelimiter.go ./slice.go ./slice_transform.go ./snapshot.go ./sst_file_writer.go ./transaction.go ./transactiondb.go ./util.go ./write_batch.go

then

gcc -I /home/lni/golang_ws/src/github.com/lni/dragonboat/internal/logdb/gorocksdb -fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=$WORK/b123=/tmp/go-build -gno-record-gcc-switches -I ./ -I//home/lni/golang_ws/src/github.com/lni/dragonboat/build/include -o ./_x001.o -c _cgo_export.c
gcc -I /home/lni/golang_ws/src/github.com/lni/dragonboat/internal/logdb/gorocksdb -fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=$WORK/b123=/tmp/go-build -gno-record-gcc-switches -I ./ -I//home/lni/golang_ws/src/github.com/lni/dragonboat/build/include -o ./_x002.o -c backup.cgo2.c
gcc -I /home/lni/golang_ws/src/github.com/lni/dragonboat/internal/logdb/gorocksdb -fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=$WORK/b123=/tmp/go-build -gno-record-gcc-switches -I ./ -I//home/lni/golang_ws/src/github.com/lni/dragonboat/build/include -o ./_x003.o -c cache.cgo2.c
gcc -I /home/lni/golang_ws/src/github.com/lni/dragonboat/internal/logdb/gorocksdb -fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=$WORK/b123=/tmp/go-build -gno-record-gcc-switches -I ./ -I//home/lni/golang_ws/src/github.com/lni/dragonboat/build/include -o ./_x004.o -c cf_handle.cgo2.c
gcc -I /home/lni/golang_ws/src/github.com/lni/dragonboat/internal/logdb/gorocksdb -fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=$WORK/b123=/tmp/go-build -gno-record-gcc-switches -I ./ -I//home/lni/golang_ws/src/github.com/lni/dragonboat/build/include -o ./_x005.o -c checkpoint.cgo2.c
gcc -I /home/lni/golang_ws/src/github.com/lni/dragonboat/internal/logdb/gorocksdb -fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=$WORK/b123=/tmp/go-build -gno-record-gcc-switches -I ./ -I//home/lni/golang_ws/src/github.com/lni/dragonboat/build/include -o ./_x006.o -c compaction_filter.cgo2.c
gcc -I /home/lni/golang_ws/src/github.com/lni/dragonboat/internal/logdb/gorocksdb -fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=$WORK/b123=/tmp/go-build -gno-record-gcc-switches -I ./ -I//home/lni/golang_ws/src/github.com/lni/dragonboat/build/include -o ./_x007.o -c comparator.cgo2.c
gcc -I /home/lni/golang_ws/src/github.com/lni/dragonboat/internal/logdb/gorocksdb -fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=$WORK/b123=/tmp/go-build -gno-record-gcc-switches -I ./ -I//home/lni/golang_ws/src/github.com/lni/dragonboat/build/include -o ./_x008.o -c db.cgo2.c
gcc -I /home/lni/golang_ws/src/github.com/lni/dragonboat/internal/logdb/gorocksdb -fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=$WORK/b123=/tmp/go-build -gno-record-gcc-switches -I ./ -I//home/lni/golang_ws/src/github.com/lni/dragonboat/build/include -o ./_x009.o -c dynflag.cgo2.c
gcc -I /home/lni/golang_ws/src/github.com/lni/dragonboat/internal/logdb/gorocksdb -fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=$WORK/b123=/tmp/go-build -gno-record-gcc-switches -I ./ -I//home/lni/golang_ws/src/github.com/lni/dragonboat/build/include -o ./_x010.o -c env.cgo2.c
gcc -I /home/lni/golang_ws/src/github.com/lni/dragonboat/internal/logdb/gorocksdb -fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=$WORK/b123=/tmp/go-build -gno-record-gcc-switches -I ./ -I//home/lni/golang_ws/src/github.com/lni/dragonboat/build/include -o ./_x011.o -c filter_policy.cgo2.c
gcc -I /home/lni/golang_ws/src/github.com/lni/dragonboat/internal/logdb/gorocksdb -fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=$WORK/b123=/tmp/go-build -gno-record-gcc-switches -I ./ -I//home/lni/golang_ws/src/github.com/lni/dragonboat/build/include -o ./_x012.o -c iterator.cgo2.c
gcc -I /home/lni/golang_ws/src/github.com/lni/dragonboat/internal/logdb/gorocksdb -fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=$WORK/b123=/tmp/go-build -gno-record-gcc-switches -I ./ -I//home/lni/golang_ws/src/github.com/lni/dragonboat/build/include -o ./_x013.o -c merge_operator.cgo2.c
gcc -I /home/lni/golang_ws/src/github.com/lni/dragonboat/internal/logdb/gorocksdb -fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=$WORK/b123=/tmp/go-build -gno-record-gcc-switches -I ./ -I//home/lni/golang_ws/src/github.com/lni/dragonboat/build/include -o ./_x014.o -c options.cgo2.c
gcc -I /home/lni/golang_ws/src/github.com/lni/dragonboat/internal/logdb/gorocksdb -fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=$WORK/b123=/tmp/go-build -gno-record-gcc-switches -I ./ -I//home/lni/golang_ws/src/github.com/lni/dragonboat/build/include -o ./_x015.o -c options_block_based_table.cgo2.c
cd /home/lni/golang_ws/src/github.com/lni/dragonboat/internal/cpp
g++ -I . -fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=$WORK/b113=/tmp/go-build -gno-record-gcc-switches -I $WORK/b113/ -g -O2 -std=c++11 -O3 -I/home/lni/golang_ws/src/github.com/lni/dragonboat/binding/include -o $WORK/b113/_x005.o -c statemachine.cpp
cd $WORK/b123
gcc -I /home/lni/golang_ws/src/github.com/lni/dragonboat/internal/logdb/gorocksdb -fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=$WORK/b123=/tmp/go-build -gno-record-gcc-switches -I ./ -I//home/lni/golang_ws/src/github.com/lni/dragonboat/build/include -o ./_x016.o -c options_compaction.cgo2.c

followed by

/usr/local/go/pkg/tool/linux_amd64/compile -o $WORK/b123/_pkg_.a -trimpath $WORK/b123 -p github.com/lni/dragonboat/internal/logdb/gorocksdb -buildid Lz0ZqR6ARmLXj5-XSMSP/Lz0ZqR6ARmLXj5-XSMSP -goversion go1.10.7 -D "" -importcfg $WORK/b123/importcfg -pack -c=4 ./doc.go ./options_compression.go ./optionsnoop.go $WORK/b123/_cgo_gotypes.go $WORK/b123/backup.cgo1.go $WORK/b123/cache.cgo1.go $WORK/b123/cf_handle.cgo1.go $WORK/b123/checkpoint.cgo1.go $WORK/b123/compaction_filter.cgo1.go $WORK/b123/comparator.cgo1.go $WORK/b123/db.cgo1.go $WORK/b123/dynflag.cgo1.go $WORK/b123/env.cgo1.go $WORK/b123/filter_policy.cgo1.go $WORK/b123/iterator.cgo1.go $WORK/b123/merge_operator.cgo1.go $WORK/b123/options.cgo1.go $WORK/b123/options_block_based_table.cgo1.go $WORK/b123/options_compaction.cgo1.go $WORK/b123/options_env.cgo1.go $WORK/b123/options_flush.cgo1.go $WORK/b123/options_ingest.cgo1.go $WORK/b123/options_read.cgo1.go $WORK/b123/options_transaction.cgo1.go $WORK/b123/options_transactiondb.cgo1.go $WORK/b123/options_write.cgo1.go $WORK/b123/ratelimiter.cgo1.go $WORK/b123/slice.cgo1.go $WORK/b123/slice_transform.cgo1.go $WORK/b123/snapshot.cgo1.go $WORK/b123/sst_file_writer.cgo1.go $WORK/b123/transaction.cgo1.go $WORK/b123/transactiondb.cgo1.go $WORK/b123/util.cgo1.go $WORK/b123/write_batch.cgo1.go $WORK/b123/_cgo_import.go
lni commented 5 years ago

please post your go env output.

when you build your go tools from source, any change to the code? maybe try to build using the official binary.

hnwyllmm commented 5 years ago

Thanks for your help. I have forgot this:

CGO_ENABLED=1
lni commented 5 years ago

Cool, happy to see the problem is now resolved.

Could you please also help me to understand why CGO_ENABLE was initially switched off on your system, is there any concern to have it enabled? I am wondering this as I want to better understand users' concerns on using cgo. Many thanks!

hnwyllmm commented 5 years ago

Cool, happy to see the problem is now resolved.

Could you please also help me to understand why CGO_ENABLE was initially switched off on your system, is there any concern to have it enabled? I am wondering this as I want to better understand users' concerns on using cgo. Many thanks!

I am a newer of golang(from yestoday) and I do not know why golong set CGO_ENABLED to 0. Whatever, you can write "CGO_ENABLED=1" in the document. Note that the variable is CGO_ENABLED but not CGO_ENABLE.

lni commented 5 years ago

Thanks for the info @hnwyllmm