收藏文章 楼主

Ubuntu下Cmake编译C++程序Helloworld

版块:摄像头 RV1126   类型:普通   作者:小绿叶技术博客   查看:1689   回复:1   获赞:0   时间:2022-04-14 10:47:24


vi  eisc.sh


#!/bin/bash

mkdir -p ~/cs/helloworld

mkdir ~/cs/helloworld/bin

mkdir ~/cs/helloworld/lib

mkdir ~/cs/helloworld/src

mkdir ~/cs/helloworld/include

mkdir ~/cs/helloworld/build

touch ~/cs/helloworld/CMakeLists.txt

# bin 可执行文件 ; lib 生成的链接库 ; src 原文件; include 头文件;  build 编译生成的文件

touch  ~/cs/helloworld/src/main.cpp

touch  ~/cs/helloworld/src/helloworld.cpp

touch ~/cs/helloworld/include/helloworld.h

cat > ~/cs/helloworld/src/main.cpp << EOF

#include <helloworld.h>

int main()

{

    helloworld obt;

    obt.outputWord();

    return 0;

}

 

EOF

cat > ~/cs/helloworld/src/helloworld.cpp << EOF

#include "helloworld.h"

void helloworld::outputWord()

{

    std::cout << "hello world! 开始的搭建环境-------!!!" << std::endl;

}

 

EOF

cat > ~/cs/helloworld/include/helloworld.h << EOF

#ifndef HELLOWORLD_H_

#define HELLOWORLD_H_

#include <iostream>

class helloworld

{

public:

    void outputWord();

};

#endif

EOF

cat > ~/cs/helloworld/CMakeLists.txt << EOF

cmake_minimum_required(VERSION 2.8)

project(helloworld)

SET(CMAKE_BUILD_TYPE Release)

set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)

set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)

include_directories(

\${PROJECT_SOURCE_DIR}/include

)

add_executable(helloworld src/helloworld.cpp src/main.cpp)

EOF


cd ~/cs/helloworld/build

cmake ..

sudo make 

# 编译 C 


# makefile :  

# ①cmake最低版本以及工程名称

# ②设置编译方式(“debug”与“Release“

# ③设置可执行文件与链接库保存的路径

# 设置头文件目录使得系统可以找到对应的头文件

# 选择需要编译的源文件,凡是要编译的源文件都需要列举出来

# https://www.cnblogs.com/haijian/p/12039160.html



# ubuntu 执行脚本:   chmod +x eisc.sh && ./eisc.sh  

# 错误执行: bash    正确执行:          ./eisc.sh


提供企业建站服务,免费网防系统,提交信息登录 http://yundun.ddoss.cn 邮箱: proposal@ddoss.cn 
回复列表
默认   热门   正序   倒序

回复:Ubuntu下Cmake编译C++程序Helloworld

头像

用户名:

粉丝数:

签名:

资料 关注 好友 消息