C++ 语法控制&;调试

C++ 语法控制&;调试,c++,debugging,makefile,syntax-checking,C++,Debugging,Makefile,Syntax Checking,如何在makefile上进行语法控制和调试? 我使用了g++编译器。我们可以假设下面的代码是我们的示例生成文件。谢谢您的建议 all: sample1 sample1: deneme.o hello.o g++ deneme.o hello.o -o sample1 deneme.o: deneme.cpp g++ -c deneme.cpp hello.o : hello.cpp g++ -c hello.cpp 通常,您有makefil

如何在makefile上进行语法控制和调试? 我使用了g++编译器。我们可以假设下面的代码是我们的示例生成文件。谢谢您的建议

all: sample1
sample1: deneme.o hello.o
         g++ deneme.o hello.o -o sample1
deneme.o: deneme.cpp
         g++ -c deneme.cpp
hello.o : hello.cpp
         g++ -c hello.cpp

通常,您有makefile变量,例如:

DEBUG=-Wall -g
并在生成命令中使用它们:

sample1: deneme.o hello.o
    g++ deneme.o hello.o -o sample1
sample1-debug: deneme-debug hello-debug
    g++ $(DEBUG) deneme.o hello.o -o sample1
deneme.o: deneme.cpp
    g++ -c deneme.cpp
deneme-debug: deneme.cpp
    g++ $(DEBUG) -c deneme.cpp
hello.o: hello.cpp
    g++ -c hello.cpp
hello-debug: hello.cpp
    g++ $(DEBUG) -c hello.cpp

然后使用
makesample1 degug
调试可执行文件。

通常,您有makefile变量,例如:

DEBUG=-Wall -g
并在生成命令中使用它们:

sample1: deneme.o hello.o
    g++ deneme.o hello.o -o sample1
sample1-debug: deneme-debug hello-debug
    g++ $(DEBUG) deneme.o hello.o -o sample1
deneme.o: deneme.cpp
    g++ -c deneme.cpp
deneme-debug: deneme.cpp
    g++ $(DEBUG) -c deneme.cpp
hello.o: hello.cpp
    g++ -c hello.cpp
hello-debug: hello.cpp
    g++ $(DEBUG) -c hello.cpp

然后使用
makesample1 degug
为您调试可执行文件。

至于个人体验,我将保留makefile的原始结构,并在每个g++配方行中插入CDEBUG变量。(当然,makefile可以通过进行改进,但这里的情况并非如此)。这样,生成可调试程序所需要做的就是在Makefile中更改CDEBUG declaration,或者在make调用“make”CDEBUG=-g”中更改CDEBUG declaration


Paul提供的解决方案会起作用,但请注意,它将创建大量*-调试文件,这些文件将不再重要。当然,我很乐意理解其他方面。

至于个人经验,我会保留makefile的原始结构,并在每个g++配方行中插入CDEBUG变量。(当然,makefile可以通过进行改进,但这里的情况并非如此)。这样,生成可调试程序所需要做的就是在Makefile中更改CDEBUG declaration,或者在make调用“make”CDEBUG=-g”中更改CDEBUG declaration


Paul提供的解决方案会起作用,但请注意,它将创建大量*-调试文件,这些文件将不再重要。当然,我很乐意理解其他情况。

也许你把静态分析和“语法控制”混淆了?语法是由编译器检查的,您的Makefile应该足够了。对于调试,它不是在makefile中完成的,您需要使用
-g
开关添加另一个目标,比如说
deneme debug
(并使用
make deneme debug
调用它),以便在必要时将其传递给
gdb
,以便进行调试。也许您将静态分析与“语法控制”混淆了?语法是由编译器检查的,您的Makefile应该足够了。对于调试,它不是在makefile中完成的,您需要使用
-g
开关添加另一个目标,比如
deneme debug
(并使用
make deneme debug
调用它),以便在必要时将其传递给
gdb
,以便进行调试。