Build a Trivial Program: Difference between revisions
Jump to navigation
Jump to search
New page: This is an example showing how to create and build a trivial program. First your account, environment and sandbox need to be established. After that you can create and build programs in ... |
No edit summary |
||
| (2 intermediate revisions by the same user not shown) | |||
| Line 7: | Line 7: | ||
Edit a new file '''testprog.cpp''' and add this program: | Edit a new file '''testprog.cpp''' and add this program: | ||
<pre> | |||
#include <stdio.h> | #include <stdio.h> | ||
| Line 14: | Line 15: | ||
return 0; | return 0; | ||
} | } | ||
</pre> | |||
Edit another file named '''Makefile''' and add: | Edit another file named '''Makefile''' and add: | ||
<pre> | |||
# The project name is used to create directory names. For consistency | # The project name is used to create directory names. For consistency | ||
# make this the same name as the top level directory for the project. | # make this the same name as the top level directory for the project. | ||
| Line 39: | Line 42: | ||
# | # | ||
include $(G)/common/build/make/directory.make | include $(G)/common/build/make/directory.make | ||
</pre> | |||
Use '''make''' to build the program. It will create the obj directory with an optimized version (testprog-gcc4), a debugging version (testprog-gcc4_g) and a profiling version (testprog-gcc4_p). Note that on Windows the programs will have | Use '''make''' to build the program. It will create the obj directory with an optimized version (testprog-gcc4), a debugging version (testprog-gcc4_g) and a profiling version (testprog-gcc4_p). Note that on Windows the programs will have "cl9" for the compiler id and an ".exe" suffix. | ||
> make | > make | ||
Latest revision as of 14:50, 30 April 2010
This is an example showing how to create and build a trivial program. First your account, environment and sandbox need to be established. After that you can create and build programs in any directory. First create a directory for your test program.
> mkdir testprog > cd testprog
Edit a new file testprog.cpp and add this program:
#include <stdio.h>
int main(int argc, char **argv)
{
printf("hello world\n");
return 0;
}
Edit another file named Makefile and add:
# The project name is used to create directory names. For consistency # make this the same name as the top level directory for the project. # PROJECT = testprog # This is the name of the generated executable file. # There can be more than one program listed per directory. # PROGRAM = testprog # For each program with C++ sources set a variable using the program name. # By convention the source file containing the "main" entry point has the # same name as the program. # CXXtestprog = testprog.cpp # This brings in the G Build make files and is required. # include $(G)/common/build/make/directory.make
Use make to build the program. It will create the obj directory with an optimized version (testprog-gcc4), a debugging version (testprog-gcc4_g) and a profiling version (testprog-gcc4_p). Note that on Windows the programs will have "cl9" for the compiler id and an ".exe" suffix.
> make : > ls obj/test* obj/testprog-gcc4* obj/testprog-gcc4_g* obj/testprog-gcc4_p*
You can then run the program with:
> obj/testprog-gcc4 hello world
If you want to delete the build output run:
> make clean