zoukankan      html  css  js  c++  java
  • eclipse 创建Makefile工程生成多个执行文件

    1.创建Makefile工程

    2.创建inc src Debug 目录

    用于存放头文件源文件

     3.编写Makefile

    需要在有源文件的目标天剑Makefile文件,如下给出一个生成两个target的模板

    ######################################
    #
    #######################################
    #source file
    #源文件,自动找所有.c和.cpp文件,并将目标定义为同名.o文件
    SOURCE  := $(wildcard *.c) $(wildcard *.cpp)
    OBJS    := $(patsubst %.c,%.o,$(patsubst %.cpp,%.o,$(SOURCE)))
    
    #target you can change test to what you want
    #目标文件名,输入任意你想要的执行文件名
    TARGET  := client server 
    APP1    := client
    APP2    := server
    
    MAINS    :=$(APP1).o $(APP2).o
    #compile and lib parameter
    #编译参数
    CC      := g++
    LIBS    := -lpthread -lrt -levent
    LDFLAGS := -L/usr/local/libevent/lib
    DEFINES :=
    INCLUDE := -I. -I./inc -I/usr/local/libevent/include
    CFLAGS  := -g -Wall -O3 $(DEFINES) $(INCLUDE)
    CXXFLAGS:= $(CFLAGS) -DHAVE_CONFIG_H
    
    #i think you should do anything here
    #下面的基本上不需要做任何改动了
    .PHONY : everything objs clean rebuild
    
    everything : $(TARGET)
    
    all : $(TARGET)
    
    objs : $(OBJS)
    
    rebuild: veryclean everything
    
    clean :
        rm -fr *.so
        rm -fr *.o
        rm -fr ./Debug/$(APP1)
        rm -fr ./Debug/$(APP2)
    
    $(APP1) :$(APP1).o $(filter-out $(MAINS), $(OBJS))
        $(CC)  $(CXXFLAGS) -o ./Debug/$@ $^  $(LDFLAGS) $(LIBS)
    $(APP2) :$(APP2).o $(filter-out $(MAINS), $(OBJS))
        $(CC)  $(CXXFLAGS) -o ./Debug/$@ $^  $(LDFLAGS) $(LIBS)

    注意:配置头文件目录 链接库目录 链接库名称

    4.配置eclipse索引目录

    此时,如果Makefile配置正确,可以正常编译,但是eclipse里因为没有配置头文件目录,一些库函数会找不到,需要进行以下配置

  • 相关阅读:
    ZOJ 1002 Fire Net (火力网)
    UVa OJ 117 The Postal Worker Rings Once (让邮差只走一圈)
    UVa OJ 118 Mutant Flatworld Explorers (变体扁平世界探索器)
    UVa OJ 103 Stacking Boxes (嵌套盒子)
    UVa OJ 110 MetaLoopless Sorts (无循环元排序)
    第一次遇到使用NSNull的场景
    NSURL使用浅析
    从CNTV下载《小小智慧树》
    NSDictionary and NSMutableDictionary
    Category in static library
  • 原文地址:https://www.cnblogs.com/tla001/p/6950858.html
Copyright © 2011-2022 走看看