hasindu2008 / f5c

Ultra-fast methylation calling and event alignment tool for nanopore sequencing data (supports CUDA acceleration)
https://hasindu2008.github.io/f5c/docs/overview
MIT License
143 stars 26 forks source link

Compiling on a Macbook Pro M1 fails #109

Closed noncodo closed 2 years ago

noncodo commented 2 years ago

Trying to compile f5c, getting the following error during compilation:

g++ -g -Wall -O2 -std=c++11 build/main.o build/meth_main.o build/f5c.o build/f5cio.o build/events.o build/nanopolish_read_db.o build/index.o build/nanopolish_fast5_io.o build/model.o build/align.o build/meth.o build/hmm.o build/freq.o build/eventalign.o build/freq_merge.o build/profiles.o slow5lib/lib/libslow5.a -L/opt/homebrew/lib/ htslib/libhts.a   -lhdf5 -lz  -lpthread -lz -rdynamic  -o f5c
Undefined symbols for architecture arm64:
  "_sam_hdr_destroy", referenced from:
      free_core(core_t*, opt_t) in f5c.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [f5c] Error 1

I'm compiling on Apple M1 Max silicon, OS Monterey 12.3.1, using these commands:

git clone https://github.com/hasindu2008/f5c/ && cd f5c
./scripts/install-hts.sh
autoreconf --install
 ./configure LDFLAGS=-L/opt/homebrew/lib/ CPPFLAGS=-I/opt/homebrew/include/
make

I also tried with make GCC=/opt/homebrew/bin/gcc-11 CXX=/opt/homebrew/bin/g++-11 which gave the same results

noncodo commented 2 years ago

I tried specifying gnu compilers (gcc-11/g++-11) for hts and f5c compilation, similar end result.

$ gcc --version
Apple clang version 13.1.6 (clang-1316.0.21.2.3)
Target: arm64-apple-darwin21.4.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

$ g++ --version
Apple clang version 13.1.6 (clang-1316.0.21.2.3)
Target: arm64-apple-darwin21.4.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

$ld -v
@(#)PROGRAM:ld  PROJECT:ld64-762
BUILD 12:49:08 Mar 30 2022
configured to support archs: armv6 armv7 armv7s arm64 arm64e arm64_32 i386 x86_64 x86_64h armv6m armv7k armv7m armv7em
LTO support using: LLVM version 13.1.6, (clang-1316.0.21.2.3) (static support for 28, runtime is 28)
TAPI support using: Apple TAPI version 13.1.6 (tapi-1316.0.7.3)

Here are the logs:

install-hts.log configure.log make.log

hasindu2008 commented 2 years ago

Seems to be a bizarre problem. Logs seem fine. Could you tarball the whole f5c directory with the object files (including htslib dir) so that I can check the binaries?

hasindu2008 commented 2 years ago

Could you perhaps try:

export CC=/opt/homebrew/bin/gcc-11 CXX=/opt/homebrew/bin/g++-11 #so that htslib is built with gcc, not clang
./scripts/install-hts.sh
autoreconf --install
 ./configure LDFLAGS=-L/opt/homebrew/lib/ CPPFLAGS=-I/opt/homebrew/include/
make CC=/opt/homebrew/bin/gcc-11 CXX=/opt/homebrew/bin/g++-11 # so that f5c is built with g++, not clang++
hasindu2008 commented 2 years ago

f5c-m1.tar.gz

Could you please try this binary build of f5c for M1?

hasindu2008 commented 2 years ago

Also the slow5tools binaries with zstd for M1 here: slow5tools-m1.tar.gz

noncodo commented 2 years ago

The binary works (hurray!), but using the custom compiler paths doesn't

Here is the entire folder FYI: f5c_M1max_build.tgz

hasindu2008 commented 2 years ago

Could you please provide access to the shared file above?

hasindu2008 commented 2 years ago

Thanks. This is an interesting situation. It looks like that missing symbol _sam_hdr_destroy is coming from a different version of htslib header file, which was possibly installed using homebrew. That symbol is not present in the version of htslib that the ./scripts/install-hts.sh fetches. To check if this is the issue, could you please rebuild f5c with the homebrew installed htslib using method 3 at https://hasindu2008.github.io/f5c/docs/building.

rm -rf f5c
git clone https://github.com/hasindu2008/f5c/ && cd f5c
autoreconf --install
 ./configure LDFLAGS=-L/opt/homebrew/lib/ CPPFLAGS=-I/opt/homebrew/include/   --enable-systemhts
make

No need to use /opt/homebrew/bin/g++-11, you can simply try the fake gcc/g++ on Mac that defaults to clang. If this works, I will reorder the flags in autoconf such that local paths take precedence over /opt/homebrew/include/.

noncodo commented 2 years ago

Beautiful! works like a charm :-) Many thanks