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
Powered by ddoss.cn 12.0
©2015 - 2025 ddoss
渝公网安备50011302222260号
渝ICP备2024035333号
【实验平台安全承诺书】
小绿叶技术社区,优化网络中,点击查看配置信息
主机监控系统: 安全防火墙已开启检查cc攻击-下载文件完成后等待10s 恢复访问,检查连接数低于峰值恢复访问
您的IP:10.8.103.62,2025-12-09 05:46:47,Processed in 0.01796 second(s).