tags:

views:

122

answers:

1

This is what I see in the Console when I clicked Project->Clean menu:

g++ -O0 -g3 -Wall -c -fmessage-length=0 -osrc\hw.o ..\src\hw.cpp
g++ -ohw.exe src\hw.o

But I've no idea how is these command generated?

Can someone elaborate the lifecycle of the command?

This is the .project file:

<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
    <name>hw</name>
    <comment></comment>
    <projects>
    </projects>
    <buildSpec>
        <buildCommand>
            <name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
            <triggers>clean,full,incremental,</triggers>
            <arguments>
                <dictionary>
                    <key>?name?</key>
                    <value></value>
                </dictionary>
                <dictionary>
                    <key>org.eclipse.cdt.make.core.append_environment</key>
                    <value>true</value>
                </dictionary>
                <dictionary>
                    <key>org.eclipse.cdt.make.core.buildArguments</key>
                    <value></value>
                </dictionary>
                <dictionary>
                    <key>org.eclipse.cdt.make.core.buildCommand</key>
                    <value>make</value>
                </dictionary>
                <dictionary>
                    <key>org.eclipse.cdt.make.core.buildLocation</key>
                    <value>${workspace_loc:/hw/Debug}</value>
                </dictionary>
                <dictionary>
                    <key>org.eclipse.cdt.make.core.contents</key>
                    <value>org.eclipse.cdt.make.core.activeConfigSettings</value>
                </dictionary>
                <dictionary>
                    <key>org.eclipse.cdt.make.core.enableAutoBuild</key>
                    <value>false</value>
                </dictionary>
                <dictionary>
                    <key>org.eclipse.cdt.make.core.enableCleanBuild</key>
                    <value>true</value>
                </dictionary>
                <dictionary>
                    <key>org.eclipse.cdt.make.core.enableFullBuild</key>
                    <value>true</value>
                </dictionary>
                <dictionary>
                    <key>org.eclipse.cdt.make.core.stopOnError</key>
                    <value>true</value>
                </dictionary>
                <dictionary>
                    <key>org.eclipse.cdt.make.core.useDefaultBuildCmd</key>
                    <value>true</value>
                </dictionary>
            </arguments>
        </buildCommand>
        <buildCommand>
            <name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
            <arguments>
            </arguments>
        </buildCommand>
    </buildSpec>
    <natures>
        <nature>org.eclipse.cdt.core.cnature</nature>
        <nature>org.eclipse.cdt.core.ccnature</nature>
        <nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
        <nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
    </natures>
</projectDescription>
+1  A: 

Open Debug/makefile or Release/makefile in the text editor. It contains commands that you see in the Console window. Additionaly, clean section is executed when you make Clean and not regular build.

Generally, CDT generates makefile according to the project properties, for all source files in the projects. Then it executes makefile using command make, with optional parameters. You can do the same by executing make command from the command line in Debug or Release directories.

From the command line, it looks like this:

alex@alex-linux:~/workspace/Test/Debug$ make clean
rm -rf  ./main.o  ./main.d  Test

alex@alex-linux:~/workspace/Test/Debug$ make
Building file: ../main.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"main.d" -MT"main.d" -o"main.o" "../main.cpp"
Finished building: ../main.cpp

Building target: Test
Invoking: GCC C++ Linker
g++  -o"Test"  ./main.o   
Finished building target: Test
Alex Farber
Do you mean that the whole stuff is generated by a single `make` command?
symfony
It is possible to execute gcc compiler directly, invoking it from the command line, g++ -O0 -g3 ... The second level is makefile. This is kind of batch file, with more complicated syntax. makefile is interpreted by make command, which invokes gcc compiler, and any other commands, like rm for Clean. The third level is IDE, like Eclipse CDT. When you execute Build command, CDT dynamically generates makefile, and executes make command. Input information for makefile is: list of project source files, and compiler/linker flags from the project properties.
Alex Farber
Makefile generated by CDT contains one compilation line for every source file from the project, and one linking line, which generates final executable. You can play with compiler and linker flags in the project settings, and see how makefile and output build log change accordingly.
Alex Farber
Thanks for the information.But I don't find any makefile anywhere in the helloworld project.
symfony
What files do you have in the Debug directory?
Alex Farber
Open Project Properties, C++ Build. By default, it should have these settings: Builder type: External builder, Build command: make, Generate Makefiles automatically. makefile should be in the Build directory.
Alex Farber
Seems cdt generates the makefiles internally so I can't see it on disk,I've also pasted the `.project` in my post
symfony