cmake

file tree is

├── CMakeLists.txt
├── main.cpp
├── mindspore
│   ├── CMakeLists.txt
│   ├── kernel_registry.cpp
│   └── kernel_registry.h
└── nnie
    ├── CMakeLists.txt
    └── nnie.cpp

main.cpp

#include <iostream>
#include "mindspore/kernel_registry.h"
int main()
{
    auto handle = dynamicOpen();
    auto res = KernelRegistry::GetInstance()->getReg();
    std::cout << res[0] << std::endl;
    std::cout << res[1] << std::endl;
    std::cout<<"Hello, World!"<<std::endl;
    return 0;
}

CMakeLists.txt in main

cmake_minimum_required(VERSION 3.19)
project(untitled10)

set(CMAKE_CXX_STANDARD 14)
add_subdirectory(nnie)
add_subdirectory(mindspore)

add_executable(untitled10 main.cpp)
target_link_libraries(untitled10 mindspore)
#target_link_libraries(untitled10 /home/huawei/CLionProjects/untitled10/cmake-build-debug/mindspore/libmindspore.so)

kernel_registry.h

#include <vector>
#include <string>
using namespace std;

void *dynamicOpen();

class KernelRegistry {
public:
    static KernelRegistry *GetInstance();
    void RegKernel(const string &name);
    vector<string> getReg();
private:
    vector<string> names_;
};

class KernelRegistrar {
public:
    KernelRegistrar(const string &name) {
        KernelRegistry::GetInstance()->RegKernel(name);
    }
};

kernel_registry.cpp

#include "kernel_registry.h"
#include <dlfcn.h>

static KernelRegistrar Jianghui("jianghui");
KernelRegistry *KernelRegistry::GetInstance() {
    static KernelRegistry instance;
    return &instance;
}

void KernelRegistry::RegKernel(const string &name) {
    names_.push_back(name);
}

vector<string> KernelRegistry::getReg() {
    return names_;
}

void *dynamicOpen() {
    auto handle = dlopen("/home/huawei/CLionProjects/untitled10/cmake-build-debug/nnie/libnnie.so", RTLD_LAZY);
    dlclose(handle);
    return handle;
}

CMakeLists.txt in mindspore

aux_source_directory(. DIR_MINDSPORE_SRCS)
add_library(mindspore SHARED ${DIR_MINDSPORE_SRCS})
target_link_libraries(mindspore dl)

nnie.cpp

#include "../mindspore/kernel_registry.h"
static KernelRegistrar Zhaodezan("zhaodezan");

CMakeLists.txt in nnie

aux_source_directory(. DIR_NNIE_SRCS)
add_library(nnie SHARED ${DIR_NNIE_SRCS})
target_link_libraries(nnie mindspore)
#target_link_libraries(nnie /home/huawei/CLionProjects/untitled10/cmake-build-debug/mindspore/libmindspore.so)

1. in clion you can generator so file, select the project name then compile

2. commit using #

3. if in the project the link so no need say the path

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

andeyeluguo

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值