• [Makefile]多文件的通用Makefile


    下面是一个糅合多线程和多文件的示例

    emc-test.c

    #include <stdio.h>
    #include <pthread.h>
    #include "charge-test.h"
    #include "rs485-test.h"
    
    pthread_mutex_t mutex;
    pthread_cond_t cond;
    
    int main()
    {
        pthread_t thread1, thread2;
    
        pthread_mutex_init(&mutex, NULL);
        pthread_cond_init(&cond, NULL);
        
        pthread_create(&thread1, NULL, (void*)thread1_rs485, NULL);
        pthread_create(&thread2, NULL, (void*)thread2_charge, NULL);
        
        do{
            pthread_cond_signal(&cond);
        }while(1);
    
        sleep(20);
        pthread_exit(0);
    
        return 0;
    }

     emc-test.h

    #ifndef __EMC_TEST_H
    #define __EMC_TEST_H
    
    
    #endif

    charge-test.c

    #include <stdio.h>
    #include <pthread.h>
    #include "charge-test.h"
    
    void *thread2_charge(void *arg)
    {
    
    }

    charge-test.h

    #ifndef __CHARGE_TEST_H
    #define __CHARGE_TEST_H
    
    
    void *thread2_charge(void *arg);
    
    #endif

    rs485-test.c

    #include <stdio.h>
    #include <pthread.h>
    #include "rs485-test.h"
    
    void *thread1_rs485(void *arg)
    {
    
    }

    rs485-test.h

    #ifndef __RS485_H
    #define __RS485_H
    
    void *thread1_rs485(void *arg);
    
    #endif

    Makefile

    CC=gcc #arm-linux-gnueabihf-gcc
    CFLAGS=-Wall 
    
    TARGET=emc-test
    SRCS=$(wildcard *.c)
    OBJS=$(SRCS:.c=.o)
    #$(shell echo $(OBJS) > a.txt)
    
    ${TARGET}:${OBJS}
        $(CC) $(OBJS) -pthread -o $@ 
    
    clean:
        rm -rf $(TARGET) $(OBJS) *.o *~
    
    %.o:%.c %.h
        $(CC) -c $< -o $@ 
  • 相关阅读:
    python 学习分享-进程
    python 学习分享-实战篇类 Fabric 主机管理程序开发
    python 学习分享-线程
    python 学习分享-paramiko模块
    linux ubuntu开启sshd
    python 学习分享-实战篇高级的ftp
    python 学习分享-socketserver
    python 学习分享-socket编程
    Java学习笔记--Java开发坏境搭建
    C# 泛型
  • 原文地址:https://www.cnblogs.com/aaronLinux/p/7078178.html
Copyright © 2020-2023  润新知