• 一个小例子学习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

  • 相关阅读:
    对象接口
    final关键字
    面向对象----多态,抽象,接口
    面向对象中的继承、封装、构造与析构函数
    PHP类与对象
    JS项目
    AppStore IAP 客户端校验代码
    Android线程计时器实现
    Cocos2d-x java 通过jni调用c++的方法
    ios7 uuid的获取方法
  • 原文地址:https://www.cnblogs.com/pcxie/p/7985432.html
Copyright © 2020-2023  润新知