You are developing a C application that compiles to a native application named process exe
GCC (GNU Compiler Collection)A Brief History and Introduction to GCCThe original GNU C Compiler (GCC) is developed by Richard Stallman, the founder of the GNU Project. Richard Stallman founded the GNU project in 1984 to create a complete Unix-like operating system as free software, to promote freedom and cooperation among computer users and programmers. Show GCC, formerly for "GNU C Compiler", has grown over times to support
many languages such as C ( GCC is a key component of so-called "GNU Toolchain", for developing applications and writing operating systems. The GNU Toolchain includes:
GCC is portable and run in many operating platforms. GCC (and GNU Toolchain) is currently available on all Unixes. They are also ported to Windows (by Cygwin, MinGW and MinGW-W64). GCC is also a cross-compiler, for producing executables on different platform. GCC VersionsThe various GCC versions are:
C++ Standard SupportThere are various C++ standards:
The default mode is C++98 for GCC versions
prior to 6.1, and C++14 for GCC 6.1 and above. You can use command-line flag
Installing GCC on UnixesGNU Toolchain, including GCC, is included in all Unixes. It is the standard compiler for most Unix-like operating systems. Installing GCC on Mac OS XOpen a Terminal, and enter " $ gcc --version ...... Target: x86_64-apple-darwin14.5.0 Thread model: posix Installing GCC on WindowsFor Windows, you could either install Cygwin GCC, MinGW GCC or MinGW-W64 GCC. Read "How to install Cygwin and MinGW".
Various GCCs under CygwinThere are many GCCs under Cygain/MinGW. To differentiate these variations, you need to understand the followings:
MinGW-W64 Target 32/64-bit Native WindowsThe MinGW-W64 (a fork of MinGW, available at http://mingw-w64.org/doku.php) supports target of both 32-bit and 64-bit native Windows. You can install "MinGW-W64" under "Cygwin" by selecting these packages (under "devel" category):
Notes:
Run the executables and check the versions: $ x86_64-w64-mingw32-gcc --version Other GCCs in CygwinOther GCC packages in Cygwin are:
Post InstallationVersionsYou could display the version of GCC via $ gcc --version gcc (GCC) 6.4.0 $ g++ --version g++ (GCC) 6.4.0 More details can be obtained via $ gcc -v Using built-in specs. HelpYou can get the help manual via the $ gcc --help Man PagesYou can read the GCC manual pages (or man pages) via the $ man gcc $ man g++ Reading man pages under CMD or Bash shell can be difficult. You could generate a text file via: $ man gcc | col -b > gcc.txt The Alternatively, you could look for an online man pages, e.g., http://linux.die.net/man/1/gcc. The GCC man pages are kept under " $ whereis gcc gcc: /usr/bin/gcc.exe /usr/lib/gcc /usr/share/man/man1/gcc.1.gz Getting StartedThe GNU C and C++ compiler are called Compile/Link a Simple C Program - hello.cBelow is the Hello-world C program
To compile the > gcc hello.c The default output executable is called " To run the program: > a $ chmod a+x a.out $ ./a.out Notes for Unixes and Bash Shell:
To specify the output filename, use > gcc -o hello.exe hello.c > hello $ gcc -o hello hello.c $ chmod a+x hello $ ./hello NOTE for Unixes:
Compile/Link a Simple C++ Program - hello.cpp
You need to use g++ to compile C++ program, as follows. We use the > g++ -o hello.exe hello.cpp > hello $ g++ -o hello hello.cpp $ chmod a+x hello $ ./hello More GCC Compiler OptionsA few commonly-used GCC compiler options are: $ g++ -Wall -g -o Hello.exe Hello.cpp
Compile and Link SeparatelyThe above command compile the source file into object file and > g++ -c -Wall -g Hello.cpp > g++ -g -o Hello.exe Hello.o The options are:
Compile and Link Multiple Source FilesSuppose that your program has two source files: > g++ -o myprog.exe file1.cpp file2.cpp However, we usually compile each of the source files separately into object file, and link them together in the later stage. In this case, changes in one file does not require re-compilation of the other files. > g++ -c file1.cpp > g++ -c file2.cpp > g++ -o myprog.exe file1.o file2.o Compile into a Shared LibraryTo compile and link C/C++ program into a shared library ( GCC Compilation ProcessGCC compiles a C/C++ program into executable in 4 steps as shown in the above diagram. For example, a "
Verbose Mode (-v)You can see the detailed compilation process by enabling > gcc -v -o hello.exe hello.c Defining Macro (-D)You can use the Headers (.h), Static Libraries (.lib, .a) and Shared Library (.dll, .so)Static Library vs. Shared LibraryA library is a collection of pre-compiled object files that can be linked into your programs via the linker. Examples are the system functions such as There are two types of external libraries: static library and shared library.
Because of the advantage of dynamic linking, GCC, by default, links to the shared library if it is available. You can list the contents of a library via " Searching for Header Files and Libraries (-I, -L and -l)When compiling the program, the compiler needs the header files to compile the source codes; the linker needs the libraries to resolve external references from other object files or libraries. The compiler and linker will not find the headers/libraries unless you set the appropriate options, which is not obvious for first-time user. For each of the headers used in your source (via The linker searches the so-called library-paths for libraries needed to link the program into an executable. The library-path is specified via Default Include-paths, Library-paths and LibrariesTry list the default include-paths in your system used by the "GNU C Preprocessor" via " > cpp -v ...... #include "..." search starts here: #include <...> search starts here: /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include Try running the compilation in verbose mode ( > gcc -v -o hello.exe hello.c ...... -L/usr/lib/gcc/x86_64-pc-cygwin/6.4.0 -L/usr/x86_64-pc-cygwin/lib -L/usr/lib -L/lib -lgcc_s -lgcc -lcygwin -ladvapi32 -lshell32 -luser32 -lkernel32
GCC Environment VariablesGCC uses the following environment variables:
Utilities for Examining the Compiled FilesFor all the GNU utilities, you can use " "file" Utility - Determine File TypeThe utility " $ gcc -c hello.c $ gcc -o hello.exe hello.o $ file hello.c "nm" Utility - List Symbol Table of Object FilesThe utility " $ nm hello.o 0000000000000000 b .bss "nm" is commonly-used to check if a particular function is defined in an object file. A "ldd" Utility - List Dynamic-Link LibrariesThe utility " > ldd hello.exe ntdll.dll => /cygdrive/c/WINDOWS/SYSTEM32/ntdll.dll (0x7ff9ba3c0000) GNU MakeThe " You can issue " First Makefile By ExampleLet's begin with a simple example to build the Hello-world program (
Create the following file named "makefile" (without any file extension), which contains rules to build the executable, and save in the same directory as the source file. Use "tab" to indent the command (NOT spaces). all: hello.exe hello.exe: hello.o gcc -o hello.exe hello.o hello.o: hello.c gcc -c hello.c clean: rm hello.o hello.exe Run the " > make gcc -c hello.c gcc -o hello.exe hello.o Running target: pre-req-1 pre-req-2 ... command The target and pre-requisites are separated by a colon ( When In the above example, the rule " More importantly, if the pre-requisite is not newer than than target, the command will not be run. In other words, the command will be run only if the target is out-dated compared with its pre-requisite. For example, if we re-run the make command: > make make: Nothing to be done for `all'. You can also specify the target to be made in the > make clean rm hello.o hello.exe > make gcc -c hello.c gcc -o hello.exe hello.o Try modifying the " NOTES:
More on MakefileComment & ContinuationA comment begins with a Syntax of RulesA general syntax for the rules is: target1 [target2 ...]: [pre-req-1 pre-req-2 ...] [command1 command2 ......] The rules are usually organized in such as way the more general rules come first. The overall rule is often name " Phony Targets (or Artificial Targets)A target that does not represent a file is called a phony target. For example, the " VariablesA variable begins with a Automatic VariablesAutomatic variables are set by make after a rule is matched. There include:
For example, we can rewrite the earlier makefile as: all: hello.exe # $@ matches the target; $< matches the first dependent hello.exe: hello.o gcc -o $@ $< hello.o: hello.c gcc -c $< clean: rm hello.o hello.exe Virtual Path - VPATH & vpathYou can use VPATH = src include You can also use vpath %.c src vpath %.h include Pattern RulesA pattern rule, which uses pattern
matching character %.o: %.c $(COMPILE.c) $(OUTPUT_OPTION) $< %: %.o $(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -o $@ Implicit Pattern RulesMake comes with a huge set of implicit pattern rules. You can list all the rule via A Sample MakefileThis sample makefile is extracted from Eclipse's "C/C++ Development Guide -Makefile". LINK_TARGET = test_me.exe OBJS = \ Test1.o \ Test2.o \ Main.o REBUILDABLES = $(OBJS) $(LINK_TARGET) clean : rm -f $(REBUILDABLES) echo Clean done all : $(LINK_TARGET) echo All done $(LINK_TARGET) : $(OBJS) g++ -g -o $@ $^ %.o : %.cpp g++ -g -o $@ -c $< Main.o : Main.h Test1.h Test2.h Test1.o : Test1.h Test2.h Test2.o : Test2.h # %.dep : %.cpp # g++ -M $(FLAGS) $< > $@ # include $(OBJS:.o=.dep) Brief SummaryI have presented the basic make features here so that you can read and understand simple makefiles for building C/C++ applications. Make is actually quite complex, and can be considered as a programming language by itself!! REFERENCES & RESOURCES
Latest version tested: CygWin GCC 6.4.0, MinGW-W64 GCC 6.4.0 How should you complete the code segment AZ 204?How should you complete the code segment? To answer, drag the appropriate code segments to the correct location. Each code segment may be used once, more than once, or not at all. You may need to drag the split bar between panes or scroll to view content.
Is AZ 204 multiple choice?The exam also has a Multi-Response and Multiple Choice Question structure. The Microsoft AZ-204 questions range in number from 40-to 60. However, this can may vary depending on the nature of the exam.
When you are implementing a software as a service SaaS solution?When you are implementing a software as a service (SaaS) solution, you are responsible for configuring high availability. Instructions: Review the underlined text. If it makes the statement correct, select "No change is needed". If the statement is incorrect, select the answer choice that makes the statement correct.
Which Azure function app features should you use?Azure Functions are best suited for smaller apps have events that can work independently of other websites. Some of the common azure functions are sending emails, starting backup, order processing, task scheduling such as database cleanup, sending notifications, messages, and IoT data processing.
|