0

                                   projectroot/
                                         |
          +------------------------------+----------------------------+
          |                              |                            |
       include/                        libs/                     helloworld/
          |                              |                            |
     shader_utils.h                shader_utils.c                 triangle.c

项目根目录下有三个目录。helloworld 目录包含 triangle.c,它依赖于 shader_utils.h(在 projectroot/include 下),其定义在 projectroot/libs 下。这是我的 make 文件。这有什么问题。

#!bin/sh
CC=gcc
LDLIBS=-lglut -lGLEW -lGL
ROOT=/media/programming/experiments/projectroot

VPATH=../libs:../include
INC=-I$(ROOT)/include

all: triangle
triangle: triangle.o shader_utils.o
         cc -c $(CFLAGS) $< -o $@ $(INC)
shader_utils.o: shader_utils.h
         cc -c $(CFLAGS) $< -o $@ $(INC)    
clean:
        rm -f *.o triangle
.PHONY: all clean

尝试制作时。它告诉这个

cc -c  ../include/shader_utils.h -o shader_utils.o -I/media/programming/experiments/projectroot/include 
cc -c  triangle.o -o triangle -I/media/programming/experiments/projectroot/include
cc: warning: triangle.o: linker input file unused because linking not done
4

1 回答 1

0

这个规则没有意义:

triangle: triangle.o shader_utils.o
         cc -c $(CFLAGS) $< -o $@ $(INC)

您是在告诉 Make 构造一个可执行文件,但要求它使用-c. 只需删除所有规则并让默认设置为您工作。重写 Makefile:

CC=gcc
LDLIBS=-lglut -lGLEW -lGL
ROOT=/media/programming/experiments/projectroot
VPATH=../libs:../include
CFLAGS=-I$(ROOT)/include

all: triangle
triangle: triangle.o shader_utils.o
shader_utils.o: shader_utils.h 
clean:
        rm -f *.o triangle
.PHONY: all clean
于 2012-11-28T02:31:42.757 回答