Skip to content

Commit

Permalink
Merge pull request #6 from andriytk/fix-linking
Browse files Browse the repository at this point in the history
Fix linking issues on Linux and FreeBSD
  • Loading branch information
yosukehara authored Sep 5, 2024
2 parents 2373961 + aeb69a8 commit 0694802
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ clean:
distclean:
@$(REBAR) clean
@rm -rf c_src/*.o
@rm -rf _build/ priv/ blocks/ .eunit/ rebar.lock
@rm -rf _build/ priv/ blocks/ rebar.lock
6 changes: 4 additions & 2 deletions c_src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,26 @@ ifeq ($(UNAME_SYS), Darwin)
CFLAGS ?= -O3 -std=c99 -finline-functions -Wall -Wmissing-prototypes
CXXFLAGS ?= -O3 -finline-functions -Wall
LDFLAGS ?= -flat_namespace -undefined suppress
LDFLAGS += gf-complete/src/.libs/*.o jerasure/src/.libs/*.o -Wl,-load_hidden,isa-l/.libs/libisal.a
else ifeq ($(UNAME_SYS), FreeBSD)
CC ?= cc
CFLAGS ?= -O3 -std=c99 -finline-functions -Wall -Wmissing-prototypes
CXXFLAGS ?= -O3 -finline-functions -Wall
CXXFLAGS ?= -O3 -finline-functions -Wall -Wno-vla-cxx-extension
LDFLAGS ?= -lstdc++
LDFLAGS += gf-complete/src/.libs/*.o jerasure/src/.libs/*.o isa-l/.libs/libisal.a
else ifeq ($(UNAME_SYS), Linux)
CC ?= gcc
CFLAGS ?= -O3 -std=c99 -finline-functions -Wall -Wmissing-prototypes
CXXFLAGS ?= -O3 -finline-functions -Wall
LDFLAGS ?= -lstdc++
LDFLAGS += gf-complete/src/.libs/*.o jerasure/src/.libs/*.o isa-l/.libs/libisal.a
endif

CFLAGS += -fPIC -I $(ERTS_INCLUDE_DIR) -I $(ERL_INTERFACE_INCLUDE_DIR)
CXXFLAGS += -fPIC -I $(ERTS_INCLUDE_DIR) -I $(ERL_INTERFACE_INCLUDE_DIR)
CXXFLAGS += -I isa-l/include -I jerasure/include -I gf-complete/include

LDLIBS += -L $(ERL_INTERFACE_LIB_DIR) -lei
LDFLAGS += gf-complete/src/.libs/*.o jerasure/src/.libs/*.o -Wl,-load_hidden,isa-l/.libs/libisal.a
LDFLAGS += -shared

# Verbosity.
Expand Down
8 changes: 7 additions & 1 deletion c_src/build_deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,16 @@ fi
# (code from github.com/tuncer/re2/c_src/build_deps.sh
which gmake 1>/dev/null 2>/dev/null && MAKE=gmake
MAKE=${MAKE:-make}
if [ `uname` = 'FreeBSD' -a "$MAKE" = 'make' ]; then
echo "WARNING: make may not work for some libs, install gmake."
fi

which glibtoolize 1>/dev/null 2>/dev/null && LIBTOOLIZE=glibtoolize
LIBTOOLIZE=${LIBTOOLIZE:-libtoolize}

# Changed "make" to $MAKE
if [ `uname` = 'FreeBSD' ]; then
CONFIG="$CONFIG CFLAGS=-fPIC"
fi

case "$1" in
clean)
Expand All @@ -60,6 +65,7 @@ case "$1" in
git clone -b v2.31.0 -c advice.detachedHead=false https://github.com/intel/isa-l.git
cd isa-l
(./autogen.sh && $CONFIG && $MAKE)
cd ..
fi
;;
esac
4 changes: 2 additions & 2 deletions c_src/cauchycoding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ ERL_NIF_TERM CauchyCoding::doDecode(vector<ERL_NIF_TERM> blockList, vector<int>
throw std::invalid_argument("Blocks should be unique");
}

size_t blockSize;
size_t blockSize = 0;

ErlNifBinary blocks[k + m];
for(size_t i = 0; i < blockIdList.size(); ++i) {
Expand Down Expand Up @@ -165,7 +165,7 @@ vector<ERL_NIF_TERM> CauchyCoding::doRepair(vector<ERL_NIF_TERM> blockList, vect
throw std::invalid_argument("Blocks should be unique");
}

size_t blockSize;
size_t blockSize = 0;

ErlNifBinary blocks[k + m];
for(size_t i = 0; i < blockIdList.size(); ++i) {
Expand Down
6 changes: 3 additions & 3 deletions c_src/irscoding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ using namespace std;
void IRSCoding::checkParams() {
if (k <= 0 || m <= 0 || w <= 0)
throw std::invalid_argument("Invalid Coding Parameters");
if (w != 8)
if (w != 8)
throw std::invalid_argument("Invalid Coding Parameters (w = 8)");
}

Expand Down Expand Up @@ -91,7 +91,7 @@ ERL_NIF_TERM IRSCoding::doDecode(vector<ERL_NIF_TERM> blockList, vector<int> blo
throw std::invalid_argument("Blocks should be unique");
}

size_t blockSize;
size_t blockSize = 0;
unsigned char* availBlocks[k + m];

ErlNifBinary blocks[k + m];
Expand Down Expand Up @@ -147,7 +147,7 @@ vector<ERL_NIF_TERM> IRSCoding::doRepair(vector<ERL_NIF_TERM> blockList, vector<
throw std::invalid_argument("Blocks should be unique");
}

size_t blockSize;
size_t blockSize = 0;
unsigned char* availBlocks[k + m];

ErlNifBinary blocks[k + m];
Expand Down
6 changes: 3 additions & 3 deletions c_src/liberationcoding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void LiberationCoding::checkParams() {
throw std::invalid_argument("Invalid Coding Parameters (m = 2)");
if (k > w)
throw std::invalid_argument("Invalid Coding Parameters (k <= w)");
if (w <= 2 || !(w%2) || !is_prime(w))
if (w <= 2 || !(w%2) || !is_prime(w))
throw std::invalid_argument("Invalid Coding Parameters (w is prime)");
}

Expand Down Expand Up @@ -95,7 +95,7 @@ ERL_NIF_TERM LiberationCoding::doDecode(vector<ERL_NIF_TERM> blockList, vector<i
throw std::invalid_argument("Blocks should be unique");
}

size_t blockSize;
size_t blockSize = 0;

ErlNifBinary blocks[k + m];
for(size_t i = 0; i < blockIdList.size(); ++i) {
Expand Down Expand Up @@ -162,7 +162,7 @@ vector<ERL_NIF_TERM> LiberationCoding::doRepair(vector<ERL_NIF_TERM> blockList,
throw std::invalid_argument("Blocks should be unique");
}

size_t blockSize;
size_t blockSize = 0;

ErlNifBinary blocks[k + m];
for(size_t i = 0; i < blockIdList.size(); ++i) {
Expand Down
2 changes: 1 addition & 1 deletion c_src/rscoding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
void RSCoding::checkParams() {
if (k <= 0 || m <= 0 || w <= 0)
throw std::invalid_argument("Invalid Coding Parameters");
if (w != 8 && w != 16 && w != 32)
if (w != 8 && w != 16 && w != 32)
throw std::invalid_argument("Invalid Coding Parameters (w = 8/16/32)");
}

Expand Down

0 comments on commit 0694802

Please sign in to comment.