• [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 $@ 
  • 相关阅读:
    Linux kernel pwn (四): Bypass SMEP
    Linux kernel pwn(三):Double Fetch
    Linux kernel pwn (二):UAF
    vue安装
    html标签
    javascript简介
    html样式 CSS(Cascading Style Sheets)
    html标签
    scala基础——scala变量
    elasticsearch日常维护
  • 原文地址:https://www.cnblogs.com/aaronLinux/p/7078178.html
Copyright © 2020-2023  润新知