FiloSottile / homebrew-musl-cross

Homebrew Formula for static-friendly musl-based GCC macOS-to-Linux cross-compilers
https://blog.filippo.io/easy-windows-and-linux-cross-compilers-for-macos/
ISC License
547 stars 45 forks source link

[undefined reference] while compiling on Apple Silicon #44

Closed lichadehehehe closed 1 year ago

lichadehehehe commented 1 year ago

Hi @FiloSottile, many thanks for maintaining this repo offering macOS-to-Linux cross-compiling solutions for Go, you just can't imagine how you make my life easier when one of my projects needs to embed Rocksdb, such an awesome key-value storage that I've recently developed a love-hate relationship with.

Utilizing the c and c++ cross compiler, my first try on the go build command is as follows:

CGO_LDFLAGS="-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 -L/opt/homebrew/cellar/musl-cross/0.9.9_1/libexec/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-linux-musl-gcc CXX=x86_64-linux-musl-g++ go build -o yeeeeeeeeet

Ideally, this should work, but my terminal once again yells at me

-link-2821846975/000054.o: in function `gorocksdb_comparator_with_ts_create':
grocksdb.c:(.text+0x88): undefined reference to `rocksdb_comparator_with_ts_create'
/opt/homebrew/Cellar/musl-cross/0.9.9_1/libexec/bin/../lib/gcc/x86_64-linux-musl/9.2.0/../../../../x86_64-linux-musl/bin/ld: /var/folders/85/7xzvr1n56wnbx8tj6h38drq80000gn/T/go-link-2821846975/000054.o: in function `gorocksdb_compactionfilter_create':
grocksdb.c:(.text+0xbe): undefined reference to `rocksdb_compactionfilter_create'
/opt/homebrew/Cellar/musl-cross/0.9.9_1/libexec/bin/../lib/gcc/x86_64-linux-musl/9.2.0/../../../../x86_64-linux-musl/bin/ld: /var/folders/85/7xzvr1n56wnbx8tj6h38drq80000gn/T/go-link-2821846975/000054.o: in function `gorocksdb_mergeoperator_create':
grocksdb.c:(.text+0x104): undefined reference to `rocksdb_mergeoperator_create'
/opt/homebrew/Cellar/musl-cross/0.9.9_1/libexec/bin/../lib/gcc/x86_64-linux-musl/9.2.0/../../../../x86_64-linux-musl/bin/ld: /var/folders/85/7xzvr1n56wnbx8tj6h38drq80000gn/T/go-link-2821846975/000054.o: in function `gorocksdb_slicetransform_create':
grocksdb.c:(.text+0x16d): undefined reference to `rocksdb_slicetransform_create'
collect2: error: ld returned 1 exit status

Being spammed of those countless undefined reference errors, I think there must have been something wrong with my go build configurations, by looking and half-guessing at https://stackoverflow.com/questions/62158905/undefined-references-to-symbols-in-standard-libraries-with-musl-cross-make , I changed my go build command as follows:

CGO_LDFLAGS="-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 -L/opt/homebrew/cellar/musl-cross/0.9.9_1/libexec/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-linux-musl-gcc CXX=x86_64-linux-musl-g++ go build -o yeeeeeeeeet

Yet the same error occurs.

I think there must have been something extremely simple and outright on the surface, right below my nose, that somehow I've just managed to unsee, yet I can't figure out what and how. Partly because my familiarity with C is not competent enough. And that's why I'm now humbly asking for any assistance that can help me get this over with.

lichadehehehe commented 1 year ago

I gave up on this and decided to build stuff on a x86-linux machine