如何将源文件路径提供给gcc?

时间:2015-05-12 09:17:50

标签: c gcc makefile

如何将源路径提供给gcc

我在源和测试目录中有.c个文件。

我如何给gcc路径?我m compiling with a makefile`并始终收到消息

  

"没有这样的文件或目录test.c"

我的目录结构:

make-directory|
              |
              |--source
              |
              |--Header
              |
              |--test
              |
              |--out
              |

问:

# makefile to generate UNIT-tests

# define any directories containing header files other than /usr/include
# TODO 

HEADERS =   :../CUnit/headers \
            CUnit/sources/Automated \
            CUnit/sources/Basic \
            CUnit/sources/Console \
            CUnit/sources/Curses \
            CUnit/sources/Framework \
            CUnit/sources/Test \
            CUnit/sources/Win \
            CUnit/sources/wxWidget \
            stub \
            ../source \
            test

SOURCES =   CUnit/headers \
            CUnit/sources/Automated \
            CUnit/sources/Basic \
            CUnit/sources/Console \
            CUnit/sources/Curses \
            CUnit/sources/Framework \
            CUnit/sources/Test \
            CUnit/sources/Win \
            CUnit/sources/wxWidget \
            stub \
            source \
            test


# define any libraries to link into executable:
#   if I want to link in libraries (libx.so or libx.a) I use the -llibname 
#   option, something like (this will link in libmylib.so and libm.so:
LIBS = 

#  TODO define the C source files
TST_SRCS = min.c max.c

SRCS = CUnit.c Automated.c Basic.c Console.c CUCurses.c CUError.c  Cunit_intl.c \
        MyMem.c TestDB.c TestRun.c Util.c wxWidget.c \
        $(TST_SRCS)


# define the C object files 
#
# This uses Suffix Replacement within a macro:
#   $(name:string1=string2)
#         For each word in 'name' replace 'string1' with 'string2'

#OBJ = $(SRCS:%.c=%.o)
OBJ = $(TST_SRCS:%.c=%.o)
#OBJ=$(join ($(SOURCES)), $(notdir $(SRCS:%.c=%.o))) 

# define the C compiler to use
CC = gcc
# define any compile-time flags
CFLAGS = -O0 -g -Wall -fmessage-length=0 -fprofile-arcs -ftest-coverage         
#TODO Linkerflags
LFLAGS = --coverage 

VPATH=source
# define the executable file,

TARGET = CUnit
all:    
    $(CC) -I $(HEADERS) $(CFLAGS) $(OBJ) -o $(TARGET) $(LFLAGS)

1 个答案:

答案 0 :(得分:2)

您可以使用makefile中的vpathVPATH指向包含源文件的目录。

请在此处查看在线gnu make manual