Hi wonderful people of Stackoverflow:
I'm using cross compilers for my go project which has used rocksdb, an embedded key-value storage written in c++. I execute
CGO_LDFLAGS="-static -L/opt/homebrew/Cellar/rocksdb@7.7.3/7.7.3/lib -L/opt/homebrew/Cellar/zstd/1.5.5/lib -L/opt/homebrew/Cellar/lz4/1.9.4/lib -L/opt/homebrew/Cellar/snappy/1.1.10/lib -L/opt/homebrew/Cellar/zlib/1.2.13/lib" CGO_CFLAGS="-I/opt/homebrew/cellar/rocksdb@7.7.3/7.7.3/include" CGO_ENABLED=1 GOOS=linux GOARCH=amd64 CC=x86_64-unknown-linux-gnu-gcc CXX=x86_64-unknown-linux-gnu-g++ go build -o yeeeeeeeeet
and the result is as follows:
...
/opt/homebrew/Cellar/x86_64-unknown-linux-gnu/11.2.0_1/toolchain/bin/../lib/gcc/x86_64-unknown-linux-gnu/11.2.0/../../../../x86_64-unknown-linux-gnu/bin/ld.bfd: /var/folders/85/7xzvr1n56wnbx8tj6h38drq80000gn/T/go-link-2911826502/000054.o: in function `gorocksdb_compactionfilter_create':
grocksdb.c:(.text+0xbe): undefined reference to `rocksdb_compactionfilter_create'
/opt/homebrew/Cellar/x86_64-unknown-linux-gnu/11.2.0_1/toolchain/bin/../lib/gcc/x86_64-unknown-linux-gnu/11.2.0/../../../../x86_64-unknown-linux-gnu/bin/ld.bfd: /var/folders/85/7xzvr1n56wnbx8tj6h38drq80000gn/T/go-link-2911826502/000054.o: in function `gorocksdb_mergeoperator_create':
grocksdb.c:(.text+0x104): undefined reference to `rocksdb_mergeoperator_create'
/opt/homebrew/Cellar/x86_64-unknown-linux-gnu/11.2.0_1/toolchain/bin/../lib/gcc/x86_64-unknown-linux-gnu/11.2.0/../../../../x86_64-unknown-linux-gnu/bin/ld.bfd: /var/folders/85/7xzvr1n56wnbx8tj6h38drq80000gn/T/go-link-2911826502/000054.o: in function `gorocksdb_slicetransform_create':
grocksdb.c:(.text+0x16d): undefined reference to `rocksdb_slicetransform_create'
collect2: error: ld returned 1 exit status
When I'm not building for the Linux environment and straight on using the default cgo compiler, non of these error messages would have happened. I think the error messages mean that the cross-compiler can't find any of the header files of rocksdb, and there's a high probability that the CGO_CFLAGS environment variable has not been correctly passed on to the c and c++ cross-compiler during build.
I'm humbly asking for any kind of assistance or hints that can potentially help me get this over with. Any assistance is utmostly appreciated.
I wish more people with cgo
cross-compiling experience, especially the good folks who have used https://github.com/FiloSottile/homebrew-musl-cross or https://github.com/messense/homebrew-macos-cross-toolchains can come forward.