目录:
cv2x@cv2x-virtual-machine:~/test/dir_mul_cpp$ ls
main main.cpp Makefile rootfs test
代码:
cv2x@cv2x-virtual-machine:~/test/dir_mul_cpp/test$ vim test.c
#include <stdio.h>
void test_printf(void)
{
printf(“test\n”);
return;
}
cv2x@cv2x-virtual-machine:~/test/dir_mul_cpp$ vim main.cpp
#include <stdio.h>
extern void test_printf(void);
int main()
{
printf(“111\n”);
test_printf();
return 0;
}
makefile 编写:
CC = g++
C_FLAGS = -g -Wall
INCLUDE =
LIBPATH =
LIBS =
FILE = ./test/*
#wildcard对cpp文件进行展开
SRCS := $(wildcard *.cpp)
#将SRCS中后缀.cpp替换成空,即可执行程序的名字与cpp名字相同
TARGET := $(patsubst %.cpp, %, $(SRCS))
OBJDIR = ./rootfs/
.cpp: