FLAG = -DNDEBUG不禁用c中的assert()

时间:2015-10-13 16:08:31

标签: c gcc makefile assert

我在我的C文件和reading中使用了一堆assert()函数我已经完成了我应该能够通过传递命令行参数来禁用断言:

make

执行此操作不会禁用断言。但是,添加到代码#define NDEBUG会禁用断言。我想从命令行禁用它们,有没有任何理由说明此标志无法正常工作。

我在Windows机器上。

这是makefile:

OPTIONS = -B CFLAGS=-DNDEBUG -ansi -pedantic -Wall -Werror

a.out: myProgram.o StudentImplementation.o ListImplementation.o
    gcc $(OPTIONS) myProgram.o StudentImplementation.o ListImplementation.o

myProgram.o: myProgram.c StudentInterface.h StudentType.h ListInterface.h ListType.h
    gcc $(OPTIONS) -c myProgram.c

StudentImplementation.o: StudentImplementation.c StudentInterface.h StudentType.h
    gcc $(OPTIONS) -c StudentImplementation.c

ListImplementation.o: ListImplementation.c ListInterface.h ListType.h StudentInterface.h StudentType.h
    gcc $(OPTIONS) -c ListImplementation.c

clean:
    rm *.o a.out

3 个答案:

答案 0 :(得分:4)

如果您有正常的makefile或没有makefile,那么您需要的命令是

make -B CFLAGS=-DNDEBUG

标准制作配方中没有FLAG变量;每个组件都有自己的变量,因此CFLAGS用于C,CXXFLAGS用于C ++,LDFLAGS用于链接器,依此类推。

使用您在问题中提供的Makefile,您无法更改make命令行上的标记。你可以用

OPTIONS = -DNDEBUG -ansi -pedantic -Wall -Werror

但这意味着每次要更改调试设置时都要编辑Makefile。

答案 1 :(得分:1)

你只需要

OPTIONS = -DNDEBUG -ansi -pedantic...

然而,更简单的Makefile看起来像这样

CFLAGS = -DNDEBUG -ansi -pedantic -Wall -Werror -I.

a.out: myProgram.o StudentImplementation.o ListImplementation.o

clean:
    rm *.o a.out

答案 2 :(得分:0)

根据我的Unix makefile经验,默认标志应该是CFLAGS,除非你的makefile中明确使用了FLAG。但是,不建议在命令行上定义CFLAGS,因为它是overriding a make variable

编译器调用中是否有-DNDEBUG调用?如果没有,那么问题就在于Makefile本身,你必须提供相关的数据

相关问题