5 个解决方案
#1
在父目录的Makefile.am加入
SUBDIRS = 子目录1 子目录2
automake手册不能不看,最好的例子是开源软件源代码。
SUBDIRS = 子目录1 子目录2
automake手册不能不看,最好的例子是开源软件源代码。
#2
bin_PROGRAMS= xx.o
xx_SOURCES= 1.cc 2.cc
#3
给你一个示例:
针对 include 目录,写一个makefile, 我这里命名为common.mk
# Add inputs and outputs from these tool invocations to the build variables
CPP_SRCS += \
../common/Condition.cpp \
../common/Mutex.cpp \
../common/Thread.cpp \
../common/ThreadPool.cpp \
../common/WorkThread.cpp \
../common/WorkThreadOfPool.cpp
OBJS += \
./Condition.o \
./Mutex.o \
./Thread.o \
./ThreadPool.o \
./WorkThread.o \
./WorkThreadOfPool.o
CPP_DEPS += \
./Condition.d \
./Mutex.d \
./Thread.d \
./ThreadPool.d \
./WorkThread.d \
./WorkThreadOfPool.d
# Each subdirectory must supply rules for building sources it contributes
%.o: ../common/%.cpp
@echo 'Building file: $<'
@echo 'Invoking: Cygwin C++ Compiler'
g++ -O2 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o"$@" "$<" $(INCLUDES)
@echo 'Finished building: $<'
@echo ' '
针对 include 目录,写一个makefile, 我这里命名为common.mk
# Add inputs and outputs from these tool invocations to the build variables
CPP_SRCS += \
../common/Condition.cpp \
../common/Mutex.cpp \
../common/Thread.cpp \
../common/ThreadPool.cpp \
../common/WorkThread.cpp \
../common/WorkThreadOfPool.cpp
OBJS += \
./Condition.o \
./Mutex.o \
./Thread.o \
./ThreadPool.o \
./WorkThread.o \
./WorkThreadOfPool.o
CPP_DEPS += \
./Condition.d \
./Mutex.d \
./Thread.d \
./ThreadPool.d \
./WorkThread.d \
./WorkThreadOfPool.d
# Each subdirectory must supply rules for building sources it contributes
%.o: ../common/%.cpp
@echo 'Building file: $<'
@echo 'Invoking: Cygwin C++ Compiler'
g++ -O2 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o"$@" "$<" $(INCLUDES)
@echo 'Finished building: $<'
@echo ' '
#4
在主程序目录,编写一个makefile文件,如下
-include common.mk
# Add inputs and outputs from these tool invocations to the build variables
#INCLUDES = -I"D:\cygwin\home\mingjun\net-snmp-5.3.2\include"
#LIBS = -L"D:\cygwin\lib" -L"D:\cygwin\usr\lib" -lpthread
INCLUDES = -I/usr/include/rpm -I. -I/usr/local/include
LIBS = -lpthread -ldl -lc -lstdc++ -L/usr/local/lib -lnetsnmpmibs -lnetsnmpagent -lnetsnmphelpers -lnetsnmp -ldl -lrpm -lrpmio -lpopt -lz -lcrypto -lm
CFLAGS = -g -O2 -Dlinux -Wall -c -fmessage-length=0 -MMD -MP
DFLAGS = -shared -fPIC
CC = gcc
CPP_SRCS += \
./QueryCPUInfo.cpp \
./proc_cpu.cpp
OBJS += \
./QueryCPUInfo.o \
./proc_cpu.o
CPP_DEPS += \
./QueryCPUInfo.d \
./proc_cpu.d
# Each subdirectory must supply rules for building sources it contributes
%.o: %.cpp
@echo 'Building file: $<'
@echo 'Invoking: Cygwin C++ Compiler'
$(CC) $(CFLAGS) $(DFLAGS) -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o"$@" "$<" $(INCLUDES)
@echo 'Finished building: $<'
@echo ' '
EXEC = libproc_cpu.so
# All Target
all: $(EXEC)
# Tool invocations
$(EXEC): $(OBJS) $(USER_OBJS)
@echo 'Building target: $@'
@echo 'Invoking: Cygwin C++ Linker'
$(CC) -shared -o$(EXEC) $(OBJS) $(USER_OBJS) $(LIBS)
@echo 'Finished building target: $@'
@echo ' '
# Other Targets
clean:
-$(RM) $(C++_DEPS)$(OBJS)$(CPP_DEPS) $(EXEC)
-@echo ' '
.PHONY: all clean dependents
.SECONDARY:
-include common.mk
# Add inputs and outputs from these tool invocations to the build variables
#INCLUDES = -I"D:\cygwin\home\mingjun\net-snmp-5.3.2\include"
#LIBS = -L"D:\cygwin\lib" -L"D:\cygwin\usr\lib" -lpthread
INCLUDES = -I/usr/include/rpm -I. -I/usr/local/include
LIBS = -lpthread -ldl -lc -lstdc++ -L/usr/local/lib -lnetsnmpmibs -lnetsnmpagent -lnetsnmphelpers -lnetsnmp -ldl -lrpm -lrpmio -lpopt -lz -lcrypto -lm
CFLAGS = -g -O2 -Dlinux -Wall -c -fmessage-length=0 -MMD -MP
DFLAGS = -shared -fPIC
CC = gcc
CPP_SRCS += \
./QueryCPUInfo.cpp \
./proc_cpu.cpp
OBJS += \
./QueryCPUInfo.o \
./proc_cpu.o
CPP_DEPS += \
./QueryCPUInfo.d \
./proc_cpu.d
# Each subdirectory must supply rules for building sources it contributes
%.o: %.cpp
@echo 'Building file: $<'
@echo 'Invoking: Cygwin C++ Compiler'
$(CC) $(CFLAGS) $(DFLAGS) -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o"$@" "$<" $(INCLUDES)
@echo 'Finished building: $<'
@echo ' '
EXEC = libproc_cpu.so
# All Target
all: $(EXEC)
# Tool invocations
$(EXEC): $(OBJS) $(USER_OBJS)
@echo 'Building target: $@'
@echo 'Invoking: Cygwin C++ Linker'
$(CC) -shared -o$(EXEC) $(OBJS) $(USER_OBJS) $(LIBS)
@echo 'Finished building target: $@'
@echo ' '
# Other Targets
clean:
-$(RM) $(C++_DEPS)$(OBJS)$(CPP_DEPS) $(EXEC)
-@echo ' '
.PHONY: all clean dependents
.SECONDARY:
#5
然后make 就ok了
要点是makefile中的第一行:
-include common.mk
表明预先处理这个makefile
注意目录层次在文件中的指定
要点是makefile中的第一行:
-include common.mk
表明预先处理这个makefile
注意目录层次在文件中的指定
#1
在父目录的Makefile.am加入
SUBDIRS = 子目录1 子目录2
automake手册不能不看,最好的例子是开源软件源代码。
SUBDIRS = 子目录1 子目录2
automake手册不能不看,最好的例子是开源软件源代码。
#2
bin_PROGRAMS= xx.o
xx_SOURCES= 1.cc 2.cc
#3
给你一个示例:
针对 include 目录,写一个makefile, 我这里命名为common.mk
# Add inputs and outputs from these tool invocations to the build variables
CPP_SRCS += \
../common/Condition.cpp \
../common/Mutex.cpp \
../common/Thread.cpp \
../common/ThreadPool.cpp \
../common/WorkThread.cpp \
../common/WorkThreadOfPool.cpp
OBJS += \
./Condition.o \
./Mutex.o \
./Thread.o \
./ThreadPool.o \
./WorkThread.o \
./WorkThreadOfPool.o
CPP_DEPS += \
./Condition.d \
./Mutex.d \
./Thread.d \
./ThreadPool.d \
./WorkThread.d \
./WorkThreadOfPool.d
# Each subdirectory must supply rules for building sources it contributes
%.o: ../common/%.cpp
@echo 'Building file: $<'
@echo 'Invoking: Cygwin C++ Compiler'
g++ -O2 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o"$@" "$<" $(INCLUDES)
@echo 'Finished building: $<'
@echo ' '
针对 include 目录,写一个makefile, 我这里命名为common.mk
# Add inputs and outputs from these tool invocations to the build variables
CPP_SRCS += \
../common/Condition.cpp \
../common/Mutex.cpp \
../common/Thread.cpp \
../common/ThreadPool.cpp \
../common/WorkThread.cpp \
../common/WorkThreadOfPool.cpp
OBJS += \
./Condition.o \
./Mutex.o \
./Thread.o \
./ThreadPool.o \
./WorkThread.o \
./WorkThreadOfPool.o
CPP_DEPS += \
./Condition.d \
./Mutex.d \
./Thread.d \
./ThreadPool.d \
./WorkThread.d \
./WorkThreadOfPool.d
# Each subdirectory must supply rules for building sources it contributes
%.o: ../common/%.cpp
@echo 'Building file: $<'
@echo 'Invoking: Cygwin C++ Compiler'
g++ -O2 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o"$@" "$<" $(INCLUDES)
@echo 'Finished building: $<'
@echo ' '
#4
在主程序目录,编写一个makefile文件,如下
-include common.mk
# Add inputs and outputs from these tool invocations to the build variables
#INCLUDES = -I"D:\cygwin\home\mingjun\net-snmp-5.3.2\include"
#LIBS = -L"D:\cygwin\lib" -L"D:\cygwin\usr\lib" -lpthread
INCLUDES = -I/usr/include/rpm -I. -I/usr/local/include
LIBS = -lpthread -ldl -lc -lstdc++ -L/usr/local/lib -lnetsnmpmibs -lnetsnmpagent -lnetsnmphelpers -lnetsnmp -ldl -lrpm -lrpmio -lpopt -lz -lcrypto -lm
CFLAGS = -g -O2 -Dlinux -Wall -c -fmessage-length=0 -MMD -MP
DFLAGS = -shared -fPIC
CC = gcc
CPP_SRCS += \
./QueryCPUInfo.cpp \
./proc_cpu.cpp
OBJS += \
./QueryCPUInfo.o \
./proc_cpu.o
CPP_DEPS += \
./QueryCPUInfo.d \
./proc_cpu.d
# Each subdirectory must supply rules for building sources it contributes
%.o: %.cpp
@echo 'Building file: $<'
@echo 'Invoking: Cygwin C++ Compiler'
$(CC) $(CFLAGS) $(DFLAGS) -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o"$@" "$<" $(INCLUDES)
@echo 'Finished building: $<'
@echo ' '
EXEC = libproc_cpu.so
# All Target
all: $(EXEC)
# Tool invocations
$(EXEC): $(OBJS) $(USER_OBJS)
@echo 'Building target: $@'
@echo 'Invoking: Cygwin C++ Linker'
$(CC) -shared -o$(EXEC) $(OBJS) $(USER_OBJS) $(LIBS)
@echo 'Finished building target: $@'
@echo ' '
# Other Targets
clean:
-$(RM) $(C++_DEPS)$(OBJS)$(CPP_DEPS) $(EXEC)
-@echo ' '
.PHONY: all clean dependents
.SECONDARY:
-include common.mk
# Add inputs and outputs from these tool invocations to the build variables
#INCLUDES = -I"D:\cygwin\home\mingjun\net-snmp-5.3.2\include"
#LIBS = -L"D:\cygwin\lib" -L"D:\cygwin\usr\lib" -lpthread
INCLUDES = -I/usr/include/rpm -I. -I/usr/local/include
LIBS = -lpthread -ldl -lc -lstdc++ -L/usr/local/lib -lnetsnmpmibs -lnetsnmpagent -lnetsnmphelpers -lnetsnmp -ldl -lrpm -lrpmio -lpopt -lz -lcrypto -lm
CFLAGS = -g -O2 -Dlinux -Wall -c -fmessage-length=0 -MMD -MP
DFLAGS = -shared -fPIC
CC = gcc
CPP_SRCS += \
./QueryCPUInfo.cpp \
./proc_cpu.cpp
OBJS += \
./QueryCPUInfo.o \
./proc_cpu.o
CPP_DEPS += \
./QueryCPUInfo.d \
./proc_cpu.d
# Each subdirectory must supply rules for building sources it contributes
%.o: %.cpp
@echo 'Building file: $<'
@echo 'Invoking: Cygwin C++ Compiler'
$(CC) $(CFLAGS) $(DFLAGS) -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o"$@" "$<" $(INCLUDES)
@echo 'Finished building: $<'
@echo ' '
EXEC = libproc_cpu.so
# All Target
all: $(EXEC)
# Tool invocations
$(EXEC): $(OBJS) $(USER_OBJS)
@echo 'Building target: $@'
@echo 'Invoking: Cygwin C++ Linker'
$(CC) -shared -o$(EXEC) $(OBJS) $(USER_OBJS) $(LIBS)
@echo 'Finished building target: $@'
@echo ' '
# Other Targets
clean:
-$(RM) $(C++_DEPS)$(OBJS)$(CPP_DEPS) $(EXEC)
-@echo ' '
.PHONY: all clean dependents
.SECONDARY:
#5
然后make 就ok了
要点是makefile中的第一行:
-include common.mk
表明预先处理这个makefile
注意目录层次在文件中的指定
要点是makefile中的第一行:
-include common.mk
表明预先处理这个makefile
注意目录层次在文件中的指定