• 一个小例子学习makefile


    前言

    makefile推荐资料为陈皓的跟我一起写makefile,需要pdf资源的可以私我

    正文

    目录结构

    ---include

    ------student.h

    ---src

    ------student.cc

    ------main.cc

    ---makefile

    makefile文件

    vpath %.h ./include
    vpath %.cc ./src
    CC = g++
    object = main.o student.o 
    all: exe
    exe: ${object}
        ${CC} -o $@ ${object}        
    #main.o: main.cc student.h
    #    g++ -c $< -I./include     
    #student.o: student.cc student.h
    #    g++ -c $< -I./include
    ${object}: %.o: %.cc student.h
        ${CC} -c $< -I./include    
    .PHONE:clean
    clean:
        rm -rf ${object} exe 

    student.h代码

    #ifndef _STUDENT
    #define _STUDENT
    #include <string>
    class Student
    {
    public:
        Student(int id,std::string name);
        std::string getName();
    private:
        int id;
        std::string name;
    };
    #endif

    student.cc代码

    #include "student.h"
    Student::Student(int id,std::string name):id(id),name(name){
    
    }
    std::string Student::getName()
    {
        return name;
    }

    main.cc代码

    #include<iostream>
    #include"student.h"
    using namespace std;
    int main()
    {
        int id = 121;
        std::string name = "pcxie";
        Student pcxie(id,name);
        cout<<"hello world"<<endl;
        cout<<pcxie.getName()<<endl;
        return 0;
    }

    执行make all后的目录结构

    ---include

    ------student.h

    ---src

    ------student.cc

    ------main.cc

    ---makefile

    ---main.o

    ---student.o

    ---exe

  • 相关阅读:
    java并发AtomicIntegerArray
    java并发:原子类之AtomicLong
    java并发:初探消费者和生产者模式
    java并发:初探用户线程和守护线程
    java并发:interrupt进程终止
    java并发:join源码分析
    java并发:初探sleep方法
    java并发(二):初探syncronized
    java并发(一):初探线程的创建
    Git 操作
  • 原文地址:https://www.cnblogs.com/pcxie/p/7985432.html
Copyright © 2020-2023  润新知