栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

CMAKE

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

CMAKE

1 文件目录结构

2 ./

CMakeLists.txt

cmake_minimum_required (VERSION 3.9)

if (WIN32)
	message (STATUS "Now is windows !")
elseif (UNIX)
	message (STATUS "Now is linux !")
elseif (APPLE)
	message (STATUS "Now is Apple system !")
endif ()

project (Demo_0 LANGUAGES CXX CUDA)

set (CUDA_NVCC_FLAGS -gencode arch=compute_60, code=sm_60; -G; -g)

set (EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
set (LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)

link_directories (${PROJECT_SOURCE_DIR}/lib)

add_subdirectory (lib)
add_subdirectory (src)

common.h

#ifndef __COMMON_H__
#define __COMMON_H__
#include "func0.h"
#include "func1.h"

#endif
3 ./src

CMakeLists.txt

set (target_name cute)
aux_source_directory (./ source_list)
add_executable (${target_name} ${source_list})
set (
	lib_dir
	../include
	${PROJECT_SOURCE_DIR}/lib/func0/include
	${PROJECT_SOURCE_DIR}/lib/func1/include
)
include_directories (${lib_dir})
target_link_libraries (${target_name} FUNC0 FUNC1 FUNC2)

main.cpp

#include "common.h"
extern void show();
int main(){
	GO_0 bys0;
	bys0.go_0();
	
	GO_1 bys1;
	bys1.go_1();
	
	bys0.go_0();
	
	show();
	
	return 0;
}
4 ./lib

CMakeLists.txt

add_subdirectory (func0)
add_subdirectory (func1)
add_subdirectory (func2)
5 ./lib/func0

CMakeLists.txt

include_directories (./include)
aux_source_directory (./src source_list)
add_library (FUNC0 SHARED ${source_list})

func0.cu

#include 
#include 
#include 
#include "func0.h"

using namespace std;

__global__ void hello_from_gpu(){
	const int bid = blockIdx.x;
	const int tid = threadIdx.x;
	
	printf("Hello World from block %d and thread %d !n", bid, tid);
}

extern "C"
int GO_0::go_0(){
	hello_from_gpu<<<2, 4>>>();
	cudaDeviceSynchronize();
	
	return 0;
}

func0.h

#ifndef __FUNC0_H__
#define __FUNC0_H__

class GO_0{
	public:
		int go_0();
};

#endif
6 ./lib/func1

CMakeLists.txt

include_directories (./include)
aux_source_directory (./src source_list)
add_library (FUNC1 SHARED ${source_list})

func1.cpp

#include "func1.h"
#include 

void GO_1::go_1(){
	printf("Link Lib FUNC1 success !n");
}

func1.h

#ifndef __FUNC1_H__
#define __FUNC1_H__

class GO_1{
	public:
		void go_1();
};

#endif
7 ./lib/func2

CMakeLists.txt

aux_source_directory (./src source_list)
add_library (FUNC2 SHARED ${source_list})

func2.cpp

#include 

void show(){
	printf("Link Lib FUNC2 success !n");
}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/925481.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号