Verifying Installation

  1. Inside Eclipse, click the New icon.
  2. Expand the C folder and select C Project. Click Next.
  3. In the Project name textbox, type HelloCDT. On the left, select Makefile Project. On the right, select MinGW GCC and click Finish.
  4. In the window that pops up, check Remember my decision and click Yes.
  5. In the Project Explorer, select the "Hello CDT" project if it isn't already selected. Go to Project > Properties.
  6. On the left, select C/C++ Build and click the Behavior tab. Check the box labeled Build on resource save (Auto build) and click OK.
  7. Click the arrow next to the New icon and click File.
  8. In the File name textfield near the bottom of the window, type Makefile and click Finish.
  9. A new file named Makefile will be added to the project and opened for editing. Type in the following code and save it when you're done.
    EXE = HelloCDT

    all: $(EXE)

    $(EXE): main.o
    gcc -Wall --pedantic -o $@ -g $^

    %.o: %.c
    gcc -Wall --pedantic -g -c $<

    clean:
    rm -f *.o $(EXE)
  10. If the Make targets view is not already open, go to Window -> Show View -> Make Targets. Right click on the project name and click Add Make Target.
  11. Create two make targets, all and clean.
  12. Click the arrow next to the New icon and click Source File.
  13. Type in main.c and click Finish.
  14. A new file named main.c will be added to the project and opened for editing. Type in the following code and save it when you're done.
    #include <stdio.h>
    #include <string.h>

    int main(int argc, const char * const argv[]) {
    char *nl, buf[BUFSIZ];
    printf("Please enter your name: ");
    fflush(stdout);
    fgets(buf, sizeof(buf), stdin);
    nl = strchr(buf, '\n');
    if(nl)
    *nl = 0;
    printf("Welcome to CSE 12, %s!\n", buf);
    return 0;
    }
     

    After you copy the code to your editor, select all (Ctrl + A) and press Ctrl + Shift + F to automatically format your code.

  15. Build your project. There are several ways to build your project: Once your project has successfully compiled, click the Run button from the icons in the top menu bar.
  16. Select MinGW gdb Debugger and click OK.

    Some users do not get this popup; which is OK.

  17. The output from the program's execution should show up in the console. Type in your name when prompted and hit <enter>.

Congratulations, you have successfully installed the CDT 4.0 for Eclipse 3.3! Please proceed to the next guide, Using Eclipse for CSE 12 Homeworks