odelaneau / shapeit4

Segmented HAPlotype Estimation and Imputation Tool
MIT License
89 stars 17 forks source link

Compiling with shared libraries #7

Closed pcarbo closed 3 years ago

pcarbo commented 4 years ago

This isn't really an issue---just an FYI in case it's useful. I wasn't able to compile SHAPEIT 4.1 on our system (Centos 7) using the static htslib, but it worked with the dynamic libraries. Perhaps others will find this information useful. Below is the exact Makefile used. Feel free to incorporate this information into your installation instructions.

CXX=g++ -std=c++11

HTSLIB_ROOT=/project2/jnovembre/software/htslib-1.9
HTSLIB_INC=$(HTSLIB_ROOT/include/htslib
HTSLIB_LIB=-L$(HTSLIB_ROOT)/lib -lhts

BOOST_INC=$(BOOST_ROOT)/include
BOOST_LIB_IO=-L$(BOOST_ROOT)/lib -lboost_iostreams
BOOST_LIB_PO=-L$(BOOST_ROOT)/lib -lboost_program_options

CXXFLAG=-O3 -march=native
LDFLAG=-O3

DYN_LIBS=-lz -lbz2 -lm -lpthread -llzma

BFILE=bin/shapeit4
HFILE=$(shell find src -name *.h)
CFILE=$(shell find src -name *.cpp)
OFILE=$(shell for file in `find src -name *.cpp`; do echo obj/$$(basename $$file .cpp).o; done)
VPATH=$(shell for file in `find src -name *.cpp`; do echo $$(dirname $$file); done)

all: $(BFILE)

$(BFILE): $(OFILE)
        $(CXX) $(LDFLAG) $^ $(HTSLIB_LIB) $(BOOST_LIB_IO) $(BOOST_LIB_PO) -o $@ $(DYN_LIBS)

obj/%.o: %.cpp $(HFILE)
        $(CXX) $(CXXFLAG) -c $< -o $@ -Isrc -I$(HTSLIB_INC) -I$(BOOST_INC)

clean:
        rm -f obj/*.o $(BFILE)
scimerc commented 4 years ago

BOOST_ROOT may be undefined.

pcarbo commented 4 years ago

Ah, right---please fix as needed.

lassefolkersen commented 4 years ago

I had a lot of problems with this as well. Here's the make file that worked for me eventually:

#COMPILER MODE C++11
CXX=g++ -std=c++11

HTSLIB_ROOT=/home/ubuntu/programs/htslib-1.9
HTSLIB_INC=$(HTSLIB_ROOT)/include
HTSLIB_LIB=-L$(HTSLIB_ROOT)/lib -lhts

BOOST_ROOT=/usr/lib/x86_64-linux-gnu
BOOST_INC=$(BOOST_ROOT)/include
BOOST_LIB_IO=-L$(BOOST_ROOT)/lib -lboost_iostreams
BOOST_LIB_PO=-L$(BOOST_ROOT)/lib -lboost_program_options

#Best performance is achieved with this. Use it if running on the same plateform you're compiling, it's definitely worth it!
CXXFLAG=-O3 -march=native

LDFLAG=-O3

#DYNAMIC LIBRARIES
DYN_LIBS=-lz -lbz2 -lm -lpthread -llzma

#SHAPEIT SOURCES & BINARY
BFILE=bin/shapeit4
HFILE=$(shell find src -name *.h)
CFILE=$(shell find src -name *.cpp)
OFILE=$(shell for file in `find src -name *.cpp`; do echo obj/$$(basename $$file .cpp).o; done)
VPATH=$(shell for file in `find src -name *.cpp`; do echo $$(dirname $$file); done)

#COMPILATION RULES
all: $(BFILE)

$(BFILE): $(OFILE)
$(CXX) $(LDFLAG) $^ $(HTSLIB_LIB) $(BOOST_LIB_IO) $(BOOST_LIB_PO) -o $@ $(DYN_LIBS)

obj/%.o: %.cpp $(HFILE)
$(CXX) $(CXXFLAG) -c $< -o $@ -Isrc -I$(HTSLIB_INC) -I$(BOOST_INC)

clean:
  rm -f obj/*.o $(BFILE)

Quite similar to @pcarbo - just with BOOST_ROOT defined. Thanks a lot for the solution! Also when doing it, I afterwards had to export

export LD_LIBRARY_PATH=/home/ubuntu/programs/htslib-1.9/

Because it had trouble linking it otherwise (I think, I'm no makefile expert)

macsx82 commented 4 years ago

Thanks guys! This fixed compiling errors with htslib for me on release 4.1.3 .