JeanLucPons / BSGS

Baby Step Giant Step for SECPK1
GNU General Public License v3.0
56 stars 29 forks source link

Compilation on OSX #7

Open Mathematician09183 opened 4 years ago

Mathematician09183 commented 4 years ago

Is it possible to compile on OSX? I am stuck on 2 errors in BSGS.h - unknown type p_thread and _mutex.

devtronic commented 3 years ago

This worked for me:

diff --git a/BSGS.cpp b/BSGS.cpp
index 9b035a3..e9117c3 100644
--- a/BSGS.cpp
+++ b/BSGS.cpp
@@ -59,7 +59,7 @@ BSGS::BSGS(Secp256K1 *secp) {
 #ifdef WIN64
   ghMutex = CreateMutex(NULL,FALSE,NULL);
 #else
-  ghMutex = PTHREAD_MUTEX_INITIALIZER;
+  pthread_mutex_init ( &ghMutex, NULL);
 #endif

 }
diff --git a/BSGS.h b/BSGS.h
index c483c57..a96b7dc 100644
--- a/BSGS.h
+++ b/BSGS.h
@@ -23,6 +23,8 @@
 #include "SECPK1/SECP256k1.h"
 #include "HashTable.h"
 #include "SECPK1/IntGroup.h"
+#include <pthread.h>
+#include <errno.h>

 #ifdef WIN64
 #include <Windows.h>
diff --git a/Makefile b/Makefile
index 083af13..17fafa7 100644
--- a/Makefile
+++ b/Makefile
@@ -23,7 +23,7 @@ CXXFLAGS   = -m64 -mssse3 -Wno-unused-result -Wno-write-strings -g -I. -I$(CUDA)
 else
 CXXFLAGS   =  -m64 -mssse3 -Wno-unused-result -Wno-write-strings -O2 -I. -I$(CUDA)/include
 endif
-LFLAGS     = -lpthread
+LFLAGS     = -lpthread -pthreads

 #--------------------------------------------------------------------

diff --git a/SECPK1/Int.h b/SECPK1/Int.h
index 0db269c..5073417 100644
--- a/SECPK1/Int.h
+++ b/SECPK1/Int.h
@@ -217,7 +217,7 @@ static uint64_t inline __shiftleft128(uint64_t a, uint64_t b,unsigned char n) {
   return  c;
 }

-#define _subborrow_u64(a,b,c,d) __builtin_ia32_sbb_u64(a,b,c,(long long unsigned int*)d);
+#define _subborrow_u64(a,b,c,d) __builtin_ia32_subborrow_u64(a,b,c,(long long unsigned int*)d);
 #define _addcarry_u64(a,b,c,d) __builtin_ia32_addcarryx_u64(a,b,c,(long long unsigned int*)d);
 #define _byteswap_uint64 __builtin_bswap64
 #else
diff --git a/Timer.h b/Timer.h
index c9ce63a..d34b35b 100644
--- a/Timer.h
+++ b/Timer.h
@@ -20,6 +20,8 @@

 #include <time.h>
 #include <string>
+#include <errno.h>
+
 #ifdef WIN64
 #include <windows.h>
 #endif