From da1113ff50127a71ee166995335911ec65f24fcd Mon Sep 17 00:00:00 2001 From: andreimesquita Date: Mon, 3 Aug 2020 16:41:31 -0300 Subject: [PATCH 1/6] Adding library and export option --- CMakeLists.txt | 3 +++ Export/Exporter.cpp | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 Export/Exporter.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 5d8a7ee..d56ce77 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,3 +6,6 @@ add_subdirectory(AdversarialSearch/Minimax) add_subdirectory(NeuralNetwork/Common) add_subdirectory(NeuralNetwork/Perceptron) add_subdirectory(NeuralNetwork/MLP) +add_definitions(-D_EXPORT_DLL_) +set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/dll) +add_library(AIEngine SHARED Export/Exporter.cpp) diff --git a/Export/Exporter.cpp b/Export/Exporter.cpp new file mode 100644 index 0000000..514282f --- /dev/null +++ b/Export/Exporter.cpp @@ -0,0 +1,20 @@ +#ifndef AIENGINE_EXPORTER_C +#define AIENGINE_EXPORTER_C + +#ifdef _EXPORT_DLL_ +#define API __declspec(dllexport) +#else +#define API __declspec(dllimport) +#endif // _EXPORT_DLL_ + +#include "../AdversarialSearch/Minimax/BitMath.h" +#include "../AdversarialSearch/Minimax/TicTacToeMinimax.h" +#include "../NeuralNetwork/Common/Random.h" +#include "../NeuralNetwork/Common/Matrix.h" +#include "../NeuralNetwork/Common/ActivationFunctions.h" +#include "../NeuralNetwork/Perceptron/Neuron.h" +#include "../NeuralNetwork/Perceptron/Perceptron.h" +#include "../NeuralNetwork/MLP/Layer.h" +#include "../NeuralNetwork/MLP/MLP.h" + +#endif //AIENGINE_EXPORTER_C From 9548665d42812f7c0568706b5684c766d7a2f101 Mon Sep 17 00:00:00 2001 From: andreimesquita Date: Mon, 17 Aug 2020 14:24:17 -0300 Subject: [PATCH 2/6] Using pragma once in header files --- AdversarialSearch/Minimax/MinimaxBenchmarker.h | 4 +--- AdversarialSearch/Minimax/TicTacToeMinimax.h | 4 +--- Export/Exporter.cpp | 5 ----- NeuralNetwork/Common/ActivationFunctions.h | 6 ++---- NeuralNetwork/Common/Matrix.h | 5 ++--- NeuralNetwork/Common/Random.h | 5 ++--- NeuralNetwork/MLP/Layer.h | 5 +---- NeuralNetwork/MLP/MLP.h | 6 ++---- NeuralNetwork/Perceptron/Neuron.h | 5 +---- NeuralNetwork/Perceptron/Perceptron.h | 5 ++--- 10 files changed, 14 insertions(+), 36 deletions(-) diff --git a/AdversarialSearch/Minimax/MinimaxBenchmarker.h b/AdversarialSearch/Minimax/MinimaxBenchmarker.h index 2a816d6..2e8cda8 100644 --- a/AdversarialSearch/Minimax/MinimaxBenchmarker.h +++ b/AdversarialSearch/Minimax/MinimaxBenchmarker.h @@ -1,5 +1,4 @@ -#ifndef _MINIMAX_BENCHMARKER_H -#define _MINIMAX_BENCHMARKER_H +#pragma once #include #include @@ -21,4 +20,3 @@ class MinimaxBenchmarker void printBoard(unsigned int board); void printState(int state); }; -#endif diff --git a/AdversarialSearch/Minimax/TicTacToeMinimax.h b/AdversarialSearch/Minimax/TicTacToeMinimax.h index df387f4..11de0d4 100644 --- a/AdversarialSearch/Minimax/TicTacToeMinimax.h +++ b/AdversarialSearch/Minimax/TicTacToeMinimax.h @@ -1,5 +1,4 @@ -#ifndef _TIC_TAC_TOE_MINIMAX_H -#define _TIC_TAC_TOE_MINIMAX_H +#pragma once #include #include @@ -27,4 +26,3 @@ class TicTacToeMinimax unsigned int evaluate(unsigned int board, bool isMaxTurn); std::vector evaluateAll(unsigned int board, bool isMaxTurn); }; -#endif diff --git a/Export/Exporter.cpp b/Export/Exporter.cpp index 514282f..85104d4 100644 --- a/Export/Exporter.cpp +++ b/Export/Exporter.cpp @@ -1,6 +1,3 @@ -#ifndef AIENGINE_EXPORTER_C -#define AIENGINE_EXPORTER_C - #ifdef _EXPORT_DLL_ #define API __declspec(dllexport) #else @@ -16,5 +13,3 @@ #include "../NeuralNetwork/Perceptron/Perceptron.h" #include "../NeuralNetwork/MLP/Layer.h" #include "../NeuralNetwork/MLP/MLP.h" - -#endif //AIENGINE_EXPORTER_C diff --git a/NeuralNetwork/Common/ActivationFunctions.h b/NeuralNetwork/Common/ActivationFunctions.h index 689484c..4a1ee77 100644 --- a/NeuralNetwork/Common/ActivationFunctions.h +++ b/NeuralNetwork/Common/ActivationFunctions.h @@ -1,5 +1,5 @@ -#ifndef AIENGINE_ACTIVATIONFUNCTIONS_H -#define AIENGINE_ACTIVATIONFUNCTIONS_H +#pragma once + #include float sigmoid(float value); @@ -7,5 +7,3 @@ float sign(float value); float zeroOrOne(float value); float noActivation(float value); void setZeroOrOneThreshold(float threshold); - -#endif //AIENGINE_ACTIVATIONFUNCTIONS_H diff --git a/NeuralNetwork/Common/Matrix.h b/NeuralNetwork/Common/Matrix.h index c9917e3..fd518b8 100644 --- a/NeuralNetwork/Common/Matrix.h +++ b/NeuralNetwork/Common/Matrix.h @@ -1,5 +1,5 @@ -#ifndef NEURALNETWORK_MATRIX_H -#define NEURALNETWORK_MATRIX_H +#pragma once + #include #include #include @@ -32,4 +32,3 @@ class Matrix static void multiply(Matrix& target, float scalar); static void add(Matrix& target, float value); }; -#endif //NEURALNETWORK_MATRIX_H diff --git a/NeuralNetwork/Common/Random.h b/NeuralNetwork/Common/Random.h index fc7a352..b267e0d 100644 --- a/NeuralNetwork/Common/Random.h +++ b/NeuralNetwork/Common/Random.h @@ -1,8 +1,7 @@ -#ifndef AIENGINE_RANDOM_H -#define AIENGINE_RANDOM_H +#pragma once + namespace random { void initRandomSeed(); float range(float a, float b); } -#endif //AIENGINE_RANDOM_H diff --git a/NeuralNetwork/MLP/Layer.h b/NeuralNetwork/MLP/Layer.h index a6875f2..fba14fa 100644 --- a/NeuralNetwork/MLP/Layer.h +++ b/NeuralNetwork/MLP/Layer.h @@ -1,5 +1,4 @@ -#ifndef AIENGINE_LAYER_H -#define AIENGINE_LAYER_H +#pragma once #include #include "../Perceptron/Perceptron.h" @@ -19,5 +18,3 @@ class Layer void feedforward(const Matrix& inputs); Matrix& getOutputs() const; }; - -#endif //AIENGINE_LAYER_H diff --git a/NeuralNetwork/MLP/MLP.h b/NeuralNetwork/MLP/MLP.h index 48d8701..f7b2831 100644 --- a/NeuralNetwork/MLP/MLP.h +++ b/NeuralNetwork/MLP/MLP.h @@ -1,5 +1,5 @@ -#ifndef AIENGINE_MLP_H -#define AIENGINE_MLP_H +#pragma once + #include "Layer.h" class MultiLayerPerceptron @@ -22,5 +22,3 @@ class MultiLayerPerceptron void recover(std::istream& stream); void setOutputActivationFunction(FloatFunction function); }; - -#endif //AIENGINE_MLP_H diff --git a/NeuralNetwork/Perceptron/Neuron.h b/NeuralNetwork/Perceptron/Neuron.h index c7afb1f..82f444f 100644 --- a/NeuralNetwork/Perceptron/Neuron.h +++ b/NeuralNetwork/Perceptron/Neuron.h @@ -1,5 +1,4 @@ -#ifndef NEURALNETWORK_NEURON_H -#define NEURALNETWORK_NEURON_H +#pragma once #include "../Common/Matrix.h" @@ -18,5 +17,3 @@ class Neuron float getBias() const; void setBias(float bias); }; - -#endif //NEURALNETWORK_NEURON_H diff --git a/NeuralNetwork/Perceptron/Perceptron.h b/NeuralNetwork/Perceptron/Perceptron.h index 40c84cc..7bc70f6 100644 --- a/NeuralNetwork/Perceptron/Perceptron.h +++ b/NeuralNetwork/Perceptron/Perceptron.h @@ -1,5 +1,5 @@ -#ifndef NEURALNETWORK_PERCEPTRON_H -#define NEURALNETWORK_PERCEPTRON_H +#pragma once + #include "Neuron.h" #include "../Common/ActivationFunctions.h" @@ -21,4 +21,3 @@ class Perceptron void train(const Matrix& inputs, const float output); Neuron& getNeuron(); }; -#endif //NEURALNETWORK_PERCEPTRON_H From 3a01849d5825ffbf1d14e892e8ed3cdee1db7329 Mon Sep 17 00:00:00 2001 From: andreimesquita Date: Sat, 28 Nov 2020 22:26:03 -0300 Subject: [PATCH 3/6] Implementing simple methods in the export API (working example) --- .gitignore | 1 + CMakeLists.txt | 4 +--- Export/CMakeLists.txt | 3 +++ Export/Exporter.cpp | 23 +++++++++++++---------- 4 files changed, 18 insertions(+), 13 deletions(-) create mode 100644 Export/CMakeLists.txt diff --git a/.gitignore b/.gitignore index f28f2b5..7f9110d 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ build *.asta.lock *.jude *.idea +cmake-build-release \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index d56ce77..78f8a82 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,6 +6,4 @@ add_subdirectory(AdversarialSearch/Minimax) add_subdirectory(NeuralNetwork/Common) add_subdirectory(NeuralNetwork/Perceptron) add_subdirectory(NeuralNetwork/MLP) -add_definitions(-D_EXPORT_DLL_) -set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/dll) -add_library(AIEngine SHARED Export/Exporter.cpp) +add_subdirectory(Export) diff --git a/Export/CMakeLists.txt b/Export/CMakeLists.txt new file mode 100644 index 0000000..d6bb5e3 --- /dev/null +++ b/Export/CMakeLists.txt @@ -0,0 +1,3 @@ +add_definitions(-D_EXPORT_DLL_) +set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/dll) +add_library(DLL SHARED Exporter.cpp) diff --git a/Export/Exporter.cpp b/Export/Exporter.cpp index 85104d4..32583f5 100644 --- a/Export/Exporter.cpp +++ b/Export/Exporter.cpp @@ -2,14 +2,17 @@ #define API __declspec(dllexport) #else #define API __declspec(dllimport) -#endif // _EXPORT_DLL_ +#endif -#include "../AdversarialSearch/Minimax/BitMath.h" -#include "../AdversarialSearch/Minimax/TicTacToeMinimax.h" -#include "../NeuralNetwork/Common/Random.h" -#include "../NeuralNetwork/Common/Matrix.h" -#include "../NeuralNetwork/Common/ActivationFunctions.h" -#include "../NeuralNetwork/Perceptron/Neuron.h" -#include "../NeuralNetwork/Perceptron/Perceptron.h" -#include "../NeuralNetwork/MLP/Layer.h" -#include "../NeuralNetwork/MLP/MLP.h" +extern "C" +{ +API int sum(int lhs, int rhs) +{ + return lhs + rhs; +} + +API int getOne() +{ + return 1; +} +} From 17eb885e90cad0b5292d1841d661162b1fb14a62 Mon Sep 17 00:00:00 2001 From: andreimesquita Date: Sat, 28 Nov 2020 22:34:44 -0300 Subject: [PATCH 4/6] Adding forgotten spacings --- Export/Exporter.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Export/Exporter.cpp b/Export/Exporter.cpp index 32583f5..29b492c 100644 --- a/Export/Exporter.cpp +++ b/Export/Exporter.cpp @@ -6,13 +6,13 @@ extern "C" { -API int sum(int lhs, int rhs) -{ - return lhs + rhs; -} + API int sum(int lhs, int rhs) + { + return lhs + rhs; + } -API int getOne() -{ - return 1; -} + API int getOne() + { + return 1; + } } From dea42149e267e54bb02ebc7d6e76029c62521632 Mon Sep 17 00:00:00 2001 From: AndreiSchuch Date: Mon, 24 Jan 2022 15:41:53 -0300 Subject: [PATCH 5/6] Creating a MathLibrary to be used as an example when exporting shared libraries from this project --- Export/CMakeLists.txt | 10 ++++++++-- Export/Exporter.cpp | 18 ------------------ Export/MathLibrary.cpp | 16 ++++++++++++++++ Export/MathLibrary.h | 12 ++++++++++++ 4 files changed, 36 insertions(+), 20 deletions(-) delete mode 100644 Export/Exporter.cpp create mode 100644 Export/MathLibrary.cpp create mode 100644 Export/MathLibrary.h diff --git a/Export/CMakeLists.txt b/Export/CMakeLists.txt index d6bb5e3..f5561df 100644 --- a/Export/CMakeLists.txt +++ b/Export/CMakeLists.txt @@ -1,3 +1,9 @@ -add_definitions(-D_EXPORT_DLL_) +add_definitions(-D MATHLIBRARY_EXPORTS) set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/dll) -add_library(DLL SHARED Exporter.cpp) + +set(FILES + MathLibrary.cpp + ) +add_executable(MathLibrary ${FILES}) + +add_library(MathLibrary_DLL SHARED MathLibrary.cpp) diff --git a/Export/Exporter.cpp b/Export/Exporter.cpp deleted file mode 100644 index 29b492c..0000000 --- a/Export/Exporter.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#ifdef _EXPORT_DLL_ -#define API __declspec(dllexport) -#else -#define API __declspec(dllimport) -#endif - -extern "C" -{ - API int sum(int lhs, int rhs) - { - return lhs + rhs; - } - - API int getOne() - { - return 1; - } -} diff --git a/Export/MathLibrary.cpp b/Export/MathLibrary.cpp new file mode 100644 index 0000000..aac091f --- /dev/null +++ b/Export/MathLibrary.cpp @@ -0,0 +1,16 @@ +#include "MathLibrary.h" + +int sum(int lhs, int rhs) +{ + return lhs + rhs; +} + +int getOne() +{ + return 1; +} + +int main(int argc, char *argv[]) +{ + return 0; +} \ No newline at end of file diff --git a/Export/MathLibrary.h b/Export/MathLibrary.h new file mode 100644 index 0000000..a0d5bd9 --- /dev/null +++ b/Export/MathLibrary.h @@ -0,0 +1,12 @@ +// MathLibrary.h - Contains declarations of math functions +#pragma once + +#ifdef MATHLIBRARY_EXPORTS +#define MATHLIBRARY_API __declspec(dllexport) +#else +#define MATHLIBRARY_API __declspec(dllimport) +#endif + +extern "C" MATHLIBRARY_API int sum(int lhs, int rhs); + +extern "C" MATHLIBRARY_API int getOne(); From 3a3a746b51482ffa92035081f0659e46be325b6d Mon Sep 17 00:00:00 2001 From: AndreiSchuch Date: Fri, 4 Feb 2022 18:51:21 -0300 Subject: [PATCH 6/6] Updating LIBRARY_OUTPUT_PATH to be in UPPERCASE --- Export/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Export/CMakeLists.txt b/Export/CMakeLists.txt index f5561df..09f76a5 100644 --- a/Export/CMakeLists.txt +++ b/Export/CMakeLists.txt @@ -1,5 +1,5 @@ add_definitions(-D MATHLIBRARY_EXPORTS) -set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/dll) +set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/DLL) set(FILES MathLibrary.cpp