From 342c7e63be38724aa1c3ca09a1b5e65703835596 Mon Sep 17 00:00:00 2001 From: Takayuki Matsuoka Date: Thu, 11 Jul 2013 22:32:25 +0900 Subject: [PATCH] Fix compile and link error for OSX --- Makefile | 11 ++++++++++- src/lz4mt_compat.cpp | 4 ++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index c02fd3c..bd3c84e 100644 --- a/Makefile +++ b/Makefile @@ -7,12 +7,21 @@ OBJDIR = obj CC = gcc CXX = g++ ##CXX = g++-4.6 +DUMPMACHINE = $(shell gcc -dumpmachine) CFLAGS = -Wall -W -Wextra -pedantic -O2 -std=c99 CXXFLAGS = -Wall -W -Wextra -pedantic -Weffc++ -Wno-missing-field-initializers -O2 -std=c++0x -Ilz4/ LD = $(CXX) -LDFLAGS = -lrt -pthread +LDFLAGS = + +ifneq(, $(findstring darwin, $(DUMPMACHINE))) + ## Mac OS X + LDFLAGS += -pthread +else + ## Linux, etc + LDFLAGS += -lrt -pthread +endif SRCS = $(wildcard $(SRCDIR)/*.cpp) OBJS = $(addprefix $(OBJDIR)/,$(notdir $(SRCS:.cpp=.o))) diff --git a/src/lz4mt_compat.cpp b/src/lz4mt_compat.cpp index e8d0b99..cffe6b6 100644 --- a/src/lz4mt_compat.cpp +++ b/src/lz4mt_compat.cpp @@ -40,10 +40,10 @@ unsigned Lz4Mt::getHardwareConcurrency() { // following code is borrowed from boost-1.53.0/libs/thread/src/pthread/thread.cpp #if defined(__APPLE__) || defined(__FreeBSD__) - { // ## NOT TESTED ## + { int c = 0; size_t size = sizeof(c); - if(0 == sysctlbyname("hw.ncpu", &count, &size, NULL, 0)) { + if(0 == sysctlbyname("hw.ncpu", &c, &size, NULL, 0)) { return static_cast(c); } }