Linux C++ 开发环境基本架构

1,文件目录,test01

rose@rose:~/test01$ tree
.
├── bin                          # 目录
├── CMakeLists.txt
├── include                      # 目录
│   └── hello_world.h
├── main.cpp
├── makefile                  
└── src                          # 目录
    └── hello_world.cpp

2,相关文件

2.1 include/hello_world.h

// hello_world.h
#ifndef HELLO_WORLD_H_
#define HELLO_WORLD_H_

#include <iostream>

class helloworld
{
public:
    void outputWord();
};

#endif

2.2 include/hello_world.h

#include "../include/hello_world.h"

void helloworld::outputWord()
{
    std::cout << "hello world" << std::endl;
}

2.3 main.cpp

#include <iostream>
#include "include/hello_world.h"

int main(void)
{
    helloworld obt;
    obt.outputWord();
    return 0;
}

2.4 CMakeLists.txt

cmake_minimum_required(VERSION 3.2)
project(demo)
include_directories(include)

# set(CMAKE_PREFIX_PATH /home/rose/Lib-dev/libtorch-shared-with-deps-latest/libtorch)

AUX_SOURCE_DIRECTORY(src DIR_SRCS)
add_executable(${PROJECT_NAME} ${DIR_SRCS} main.cpp)

2.5 makefile

.PHONY:all clean
 
PATH_BIN=bin
 
all:
	@cd ./$(PATH_BIN) && cmake .. && make
 
clean:
	rm -rf $(PATH_BIN)
	mkdir $(PATH_BIN)

3,编译

rose@rose:~/test01$ make
-- The C compiler identification is GNU 5.4.0
-- The CXX compiler identification is GNU 5.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/rose/c++ STL/test02/bin
make[1]: Entering directory '/home/rose/c++ STL/test02/bin'
make[2]: Entering directory '/home/rose/c++ STL/test02/bin'
make[3]: Entering directory '/home/rose/c++ STL/test02/bin'
Scanning dependencies of target demo
make[3]: Leaving directory '/home/rose/c++ STL/test02/bin'
make[3]: Entering directory '/home/rose/c++ STL/test02/bin'
[ 33%] Building CXX object CMakeFiles/demo.dir/src/hello_world.cpp.o
[ 66%] Building CXX object CMakeFiles/demo.dir/main.cpp.o
[100%] Linking CXX executable demo
make[3]: Leaving directory '/home/rose/c++ STL/test02/bin'
[100%] Built target demo
make[2]: Leaving directory '/home/rose/c++ STL/test02/bin'
make[1]: Leaving directory '/home/rose/c++ STL/test02/bin'

4,执行

rose@rose:~/test01$ ./bin/demo 
hello world
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值