zoukankan      html  css  js  c++  java
  • 一个小例子学习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

  • 相关阅读:
    windows任务计划
    PHP创建多级文件夹
    js正则表达式(不断总结中....)
    js随机改变背景颜色
    提高PHP代码质量36计
    PHP中使用Filter进行数据安全过滤
    CSS颜色代码大全
    正则表达式的修饰符
    创建索引视图
    读取xml中的所有文件名
  • 原文地址:https://www.cnblogs.com/pcxie/p/7985432.html
Copyright © 2011-2022 走看看