简体   繁体   English

Makefile:编译时没有链接问题

[英]Makefile: Compiling without Linking Issue

Currently I'm trying to compile.c-files in subfolder(s) without linking and created a simple draft in Makefile.目前,我正在尝试在不链接的情况下编译子文件夹中的.c 文件,并在 Makefile 中创建了一个简单的草稿。 What I want to do is take.o files into bin/ directory without linking as I described before.我想要做的是将.o 文件放入 bin/ 目录中,而不像我之前描述的那样进行链接。 However couldn't reach any output successfully.但是无法成功到达任何 output。

There is sample Makefile:有样品Makefile:

IDIR = test/inc
ODIR = test/src
CC = gcc
CFLAGS = -std=c99 -I$(IDIR)

OBJDIR    =   bin

.PHONY: clean

$(OBJDIR):
    mkdir   $(OBJDIR)

$(OBJDIR)/%.o:  $(ODIR)/*.c
    $(CC)   $(CFLAGS)   -c  $<  -o  $@

clean:
    @rm -rf $(OBJDIR)

It would be great if you define what did I missed.如果您定义我错过了什么,那就太好了。

the make file needs to actually ask for all the object files to be created. make 文件实际上需要要求创建所有 object 文件。 Suggest:建议:

IDIR := test/inc
SDIR := test/src/

CC := gcc
CFLAGS := -Wall -Wextra -Wconversion -pedantic -std=c99 -I$(IDIR)

OBJDIR    :=   bin/

SRCS := (wildcard:$(SDIR)*.c)
OBJS := ($(SRCS):.c=.o)

.PHONY: all clean

all: $(OBJDIR)  $(OBJS)


$(OBJDIR):
    mkdir   $(OBJDIR)

$(OBJDIR)%.o:  %.c
    $(CC)   $(CFLAGS)   -c  $<  -o  $@

clean:
    @rm -rf $(OBJDIR)

run the above makefile using:运行上述 makefile 使用:

make -f (your make file name) all

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM