Building the Sample Code for Debugging

A simple Hello World application can demonstrate some of the debugger's basic features.

To prepare helloworld in C:

Create a new file named helloworld.c in a working directory. Add the following code to helloworld.c:

 #include <stdio.h>
 int main()
 {
    printf("Hello World!\n");
    return 0;
 }

Note

The Intel Debugger does not support position independent executable (pie).

On some systems the compiler option -fpie is set by default. Use -fno-pie to disable pie.

To compile helloworld.c:

Before compiling you must set the environment variables as described in the Intel® Compiler User Guide.

  1. Open a shell and change to the working directory.
  2. Compile the application:

    • On Linux* OS, compile the application using the following command:

      icc -debug -O0 helloworld.c -o helloworld

    • On OS X*, the debugger reads debug information from object files. As a result, the executables do not contain any debug information. To be able to debug, you must retain the object files.

      • First, create an object file with debug information using the following command:

        icc -debug -O0 –c helloworld.c -o helloworld.o

      • Then compile the application using the following command:

        icc -debug -O0 helloworld.o -o helloworld

Following successful compilation, the compiler creates an executable named helloworld in the working directory.

To prepare helloworld in Fortran:

Create a new file named helloworld.f90 in a working directory. Add the following code to helloworld.f90:

program main
print *,"Hello World!"
end program main 

To compile helloworld.c in Fortran:

  1. Open a shell and change to the working directory.

  2. Compile the application:

    • On Linux* OS, compile the application using the following command:

      ifort -debug -O0 helloworld.f90 -o helloworld

    • On OS X*, the debugger reads debug information from object files. As a result, the executables do not contain any debug information. To be able to debug, you must retain the object files.

      • First, create an object file with debug information using the following command:

        ifort -debug -O0 –c helloworld.f90 -o helloworld.o

      • Then compile the application using the following command:

        ifort -debug -O0 helloworld.o -o helloworld

Following successful compilation, the compiler creates an executable named helloworld in the working directory.


Submit feedback on this help topic