From 61fe2a87f8631bef94462a84d7286e4313bab222 Mon Sep 17 00:00:00 2001 From: Sammy Libre Date: Tue, 6 Dec 2016 14:37:21 +0500 Subject: [PATCH] Fix cmake and linking --- README.md | 45 +++++++++----------- cnutil/CMakeLists.txt | 28 ++++++------ cnutil/cnutil.c | 13 ------ cnutil/cnutil.go | 5 ++- cnutil/cnutilxx/main.h | 12 ------ cnutil/{cnutilxx/main.cpp => src/cnutil.cpp} | 4 +- cnutil/{ => src}/cnutil.h | 10 ++++- hashing/CMakeLists.txt | 7 +-- hashing/hashing.go | 2 +- 9 files changed, 52 insertions(+), 74 deletions(-) delete mode 100644 cnutil/cnutil.c delete mode 100644 cnutil/cnutilxx/main.h rename cnutil/{cnutilxx/main.cpp => src/cnutil.cpp} (80%) rename cnutil/{ => src}/cnutil.h (70%) diff --git a/README.md b/README.md index a89b360..1ad1a8b 100644 --- a/README.md +++ b/README.md @@ -8,55 +8,52 @@ High performance CryptoNote mining stratum written in Golang. * AES-NI enabled share validation code with fallback to slow implementation * Integrated NewRelic performance monitoring plugin -### Installation +## Installation Dependencies: * go-1.6 * Everything required to build monero - * Monero **v0.10.0** + * Monero >= **v0.10.0** -#### Mac OS X +### Linux -Install required packages: +Use Ubuntu 16.04 LTS. - brew update && brew install go - export GOPATH=~/go - go get github.com/yvasiyarov/gorelic +Compile Monero source (with libraries option): -Download and compile [Monero](https://github.com/monero-project/monero) **v0.10.0**. + cmake -DBUILD_SHARED_LIBS=1 . + make -Now clone stratum repo and compile it: +Install Golang and packages: - git clone https://github.com/sammy007/go-cryptonote-pool.git - cmake . - make + sudo apt-get install golang + export GOPATH=~/go + go get github.com/yvasiyarov/gorelic -Notice that for share validation stratum requires monero source tree where .a libs already compiled. By default stratum will use ../monero directory. You can override this behavior by passing MONERO_DIR env variable: +Build CGO extensions: - MONERO_DIR=/path/to/monero cmake . + MONERO_DIR=/opt/src/monero cmake . make Build stratum: go build -o pool main.go -#### Linux +### Mac OS X -I would recommend you to use Ubuntu 16.04 LTS. +Install Golang and packages packages: -Install required packages: - - sudo apt-get install golang + brew update && brew install go export GOPATH=~/go go get github.com/yvasiyarov/gorelic -In order to successfully link with monero libs, recompile monero with: +Compile Monero source: cmake . - CXXFLAGS="-fPIC" CFLAGS="-fPIC" make + make -Build CGO extensions: +Now clone stratum repo and compile it: MONERO_DIR=/opt/src/monero cmake . make @@ -65,11 +62,11 @@ Build stratum: go build -o pool main.go -#### Running Stratum +### Running Stratum ./pool config.json -### Configuration +## Configuration Configuration is self-describing, just copy *config.example.json* to *config.json* and run stratum with path to config file as 1st argument. diff --git a/cnutil/CMakeLists.txt b/cnutil/CMakeLists.txt index 73e951d..2f0ee03 100644 --- a/cnutil/CMakeLists.txt +++ b/cnutil/CMakeLists.txt @@ -1,4 +1,4 @@ -set(CXXLIB "cnutilxx") +set(CXXLIB "cnutil") find_package(Boost COMPONENTS thread system program_options date_time filesystem REQUIRED) @@ -9,14 +9,21 @@ include_directories(${Boost_INCLUDE_DIRS}) include_directories("${MONERO_DIR}/contrib/epee/include") include_directories("${MONERO_DIR}/src") +link_directories( + ${MONERO_DIR}/src/cryptonote_core + ${MONERO_DIR}/src/crypto + ${MONERO_DIR}/src/common + ${MONERO_DIR}/src/ringct +) + # Build library -add_library(${CXXLIB} SHARED cnutilxx/main.cpp) +add_library(${CXXLIB} SHARED src/cnutil.cpp) target_link_libraries(${CXXLIB} - ${MONERO_DIR}/src/cryptonote_core/libcryptonote_core.a - ${MONERO_DIR}/src/crypto/libcrypto.a - ${MONERO_DIR}/src/common/libcommon.a - ${MONERO_DIR}/src/ringct/libringct.a + cryptonote_core + crypto + common + ringct ) target_link_libraries(${CXXLIB} @@ -26,12 +33,3 @@ target_link_libraries(${CXXLIB} ${Boost_DATE_TIME_LIBRARY} ${Boost_FILESYSTEM_LIBRARY} ) - -set(LIB "cnutil") - -# Flags -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11 -D_GNU_SOURCE") - -# Build library -add_library(${LIB} SHARED cnutil.c) -target_link_libraries(${LIB} ${CXXLIB}) diff --git a/cnutil/cnutil.c b/cnutil/cnutil.c deleted file mode 100644 index 20f45f1..0000000 --- a/cnutil/cnutil.c +++ /dev/null @@ -1,13 +0,0 @@ -#include -#include "stdbool.h" -#include -#include -#include "cnutilxx/main.h" - -uint32_t convert_blob(const char *blob, size_t len, char *out) { - return cn_convert_blob(blob, len, out); -} - -bool validate_address(const char *addr, size_t len) { - return cn_validate_address(addr, len); -} diff --git a/cnutil/cnutil.go b/cnutil/cnutil.go index 4fb1892..a52c38a 100644 --- a/cnutil/cnutil.go +++ b/cnutil/cnutil.go @@ -1,8 +1,9 @@ package cnutil // #cgo CFLAGS: -std=c11 -D_GNU_SOURCE -// #cgo LDFLAGS: -L${SRCDIR} -lcnutil -lcnutilxx -lstdc++ -// #include "cnutil.h" +// #cgo LDFLAGS: -L${SRCDIR} -lcnutil -Wl,-rpath ${SRCDIR} -lstdc++ +// #include +// #include "src/cnutil.h" import "C" import "unsafe" diff --git a/cnutil/cnutilxx/main.h b/cnutil/cnutilxx/main.h deleted file mode 100644 index e4a58f8..0000000 --- a/cnutil/cnutilxx/main.h +++ /dev/null @@ -1,12 +0,0 @@ -#include - -#ifdef __cplusplus -extern "C" { -#endif - -uint32_t cn_convert_blob(const char *blob, uint32_t len, char *out); -bool cn_validate_address(const char *addr, uint32_t len); - -#ifdef __cplusplus -} -#endif diff --git a/cnutil/cnutilxx/main.cpp b/cnutil/src/cnutil.cpp similarity index 80% rename from cnutil/cnutilxx/main.cpp rename to cnutil/src/cnutil.cpp index 6db911a..22796b2 100644 --- a/cnutil/cnutilxx/main.cpp +++ b/cnutil/src/cnutil.cpp @@ -5,7 +5,7 @@ using namespace cryptonote; -extern "C" uint32_t cn_convert_blob(const char *blob, size_t len, char *out) { +extern "C" uint32_t convert_blob(const char *blob, size_t len, char *out) { std::string input = std::string(blob, len); std::string output = ""; @@ -19,7 +19,7 @@ extern "C" uint32_t cn_convert_blob(const char *blob, size_t len, char *out) { return output.length(); } -extern "C" bool cn_validate_address(const char *addr, size_t len) { +extern "C" bool validate_address(const char *addr, size_t len) { std::string input = std::string(addr, len); std::string output = ""; uint64_t prefix; diff --git a/cnutil/cnutil.h b/cnutil/src/cnutil.h similarity index 70% rename from cnutil/cnutil.h rename to cnutil/src/cnutil.h index 665e0b9..b8cafbf 100644 --- a/cnutil/cnutil.h +++ b/cnutil/src/cnutil.h @@ -1,7 +1,13 @@ -#include #include -#include #include "stdbool.h" +#ifdef __cplusplus +extern "C" { +#endif + uint32_t convert_blob(const char *blob, uint32_t len, char *out); bool validate_address(const char *addr, uint32_t len); + +#ifdef __cplusplus +} +#endif diff --git a/hashing/CMakeLists.txt b/hashing/CMakeLists.txt index 14fd506..2cdc7fd 100644 --- a/hashing/CMakeLists.txt +++ b/hashing/CMakeLists.txt @@ -5,7 +5,8 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11 -D_GNU_SOURCE") include_directories("${MONERO_DIR}/contrib/epee/include") include_directories("${MONERO_DIR}/src") +link_directories(${MONERO_DIR}/src/crypto) + add_library(${LIB} SHARED src/hashing.c) -target_link_libraries(${LIB} - ${MONERO_DIR}/src/crypto/libcrypto.a -) + +target_link_libraries(${LIB} crypto) diff --git a/hashing/hashing.go b/hashing/hashing.go index 803f50a..412eed5 100644 --- a/hashing/hashing.go +++ b/hashing/hashing.go @@ -1,7 +1,7 @@ package hashing // #cgo CFLAGS: -std=c11 -D_GNU_SOURCE -// #cgo LDFLAGS: -L${SRCDIR} -lhashing -lstdc++ +// #cgo LDFLAGS: -L${SRCDIR} -lhashing -Wl,-rpath ${SRCDIR} -lstdc++ // #include // #include // #include "src/hashing.h"