gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 08:26:40 24 4
gpt4 key购买 nike

如何将源路径提供给 gcc

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

我怎样才能给 gcc 一个路径?我正在使用 makefile` 进行编译,并且总是收到消息

"no such file or directory 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)

最佳答案

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

在线查看gnu make manual在这里。

关于c - 如何将源文件路径提供给 gcc?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30186605/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com