Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please help to create a project on vscode + cmake #246

Open
alex290 opened this issue Nov 4, 2022 · 3 comments
Open

Please help to create a project on vscode + cmake #246

alex290 opened this issue Nov 4, 2022 · 3 comments

Comments

@alex290
Copy link

alex290 commented Nov 4, 2022

Hello. I am very interested in your library. Tried to run an empty project on vscode + cmake linux

here is the cmake code

cmake_minimum_required(VERSION 3.20.0)
set(PROJECT_NAME "OpenNNTest")

project (${PROJECT_NAME})


set_property (GLOBAL PROPERTY USE_FOLDERS ON)
set (CMAKE_CXX_STANDARD 20)
set (CMAKE_CXX_STANDARD_REQUIRED ON)

if(UNIX)
	set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
endif()


add_subdirectory("${CMAKE_SOURCE_DIR}/opennn/opennn")

file(GLOB project
    src/*
)

add_executable(${PROJECT_NAME} ${project})

target_link_libraries(${PROJECT_NAME} PUBLIC opennn)

code main.cpp

#include <iostream>
#include <sstream>
#include <time.h>
#include <stdexcept>

#include "../opennn/opennn/opennn.h"

using namespace opennn;

int main(int argc, char *argv[])
{
    try
    {
        cout << "Hello OpenNN!" << endl;
        cout << "Bye OpenNN!" << endl;
    }
    catch(const exception& e)
    {
        cerr << e.what() << endl;

        return 1;
    }
}

There are a lot of warnings during assembly, but it is assembled without errors

As soon as I add to main.cpp

....
 try
    {
        cout << "Hello OpenNN!" << endl;
        DataSet data_set("data/iris_flowers.csv",',',true);
        cout << "Bye OpenNN!" << endl;
    }

Stops working

Is there a ready-made empty example for a clean cmake project so that I can put the code.

@MohammadFakhreddin
Copy link

Hey @alex290 ,
This is my cmake for both windows and Linux. I have managed to integrate opennn into my project:

cmake_minimum_required(VERSION 3.16.0)

set(PROJECT_NAME "MachineLearningCpp")

project (${PROJECT_NAME} CXX C)

set_property (GLOBAL PROPERTY USE_FOLDERS ON)

set (CMAKE_CXX_STANDARD 20)

set (CMAKE_CXX_STANDARD_REQUIRED ON)

if(MSVC)
    # add_definitions (/WX)           # Warnings as errors
    add_definitions (-D_CRT_SECURE_NO_WARNINGS)
else()
    set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g")
    set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2")
    # TODO
    # add_definitions(-Werror)
endif()

if(LINUX)
    set(CMAKE_THREAD_LIBS_INIT "-lpthread")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
    set(CMAKE_HAVE_THREADS_LIBRARY 1)
    set(CMAKE_USE_WIN32_THREADS_INIT 0)
    set(CMAKE_USE_PTHREADS_INIT 1)
    set(THREADS_PREFER_PTHREAD_FLAG ON)
endif()

find_package(OpenMP)
if (OPENMP_FOUND)
    message(STATUS "OpenMP found")
    set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
    set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
    set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
endif()

### Eigen

set(EIGEN_SPLIT_LARGE_TESTS OFF CACHE BOOL "Split large tests into smaller executables")
add_subdirectory("${CMAKE_SOURCE_DIR}/libs/eigen")
include_directories("${CMAKE_SOURCE_DIR}/libs/eigen")

#### OPENNN

set(OpenNN_BUILD_EXAMPLES OFF CACHE BOOL "Build OpenNN examples")
set(OpenNN_BUILD_BLANK OFF CACHE BOOL "Build OpenNN blank")
set(OpenNN_BUILD_TESTS OFF CACHE BOOL "Build OpenNN tests")
add_subdirectory("${CMAKE_SOURCE_DIR}/libs/opennn")
include_directories("${CMAKE_SOURCE_DIR}/libs/opennn")

########################################

add_subdirectory("src/Leaf-Dense")

This is my project if you are looking for a template. Although I might make it private later.
https://github.com/MohammadFakhreddin/MachineLearningCPP

@alex290
Copy link
Author

alex290 commented Nov 5, 2022

It doesn't work anyway. A lot of mistakes fall out. Apparently I have MinGW. killed a lot of time. There is no forum, no support. Sadly. So I wanted to try this library, apparently I will have to look for something else

@leondavi
Copy link

leondavi commented Apr 19, 2023

We work with openNN
You can look at our CMake as an example.
https://github.com/leondavi/NErlNet/tree/onn600/src_cpp/opennnBridge
It works for Linux: Ubuntu and Raspbian and compiles successfully with g++8/11, although we have never tried it with mingw32.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants