Главная страница | назад





Article #23055: How do you force Builder to compile a project in straight C?

Question: Using C++Builder, how do I compile a project in straight C?

Answer: Builder compiles C or C++ based on the file extension. If your source file is named "file.c" it will be compiled with only C language features.

The only complication you must be aware of is when the source file containing your main() function is a C file. The C++Buidler 4 IDE requires the root source file (the source file with the same leading name as the project file) to be a C++ file and contain a symbol "main". An updated Console Wizard has solved this problem in C++ Builder 5 while the following steps work around this limitation in C++ Builder 4:

  1.  File  |  Close All
  2.  File  |  New  |  Console Wizard  |  & include the VCL
  3.  Replace the default code in the editor (Unit1.cpp) to the following:

    #define main
    #include <vcl.h>
    USEUNIT("main.c");

  4.  File  |  New  |  Text
  5.  File  |  Save "File1.txt" as "main.c"  |  & then close it
  6.  Project  |  Add to Project  |  & choose "main.c"
  7.  Now, add the following to main.c

    #include <stdio.h>
    #include <conio.h>
    int main()
    {
      printf("Hello, world!");
      getch();
      return 0;
    }

  8.  File  |  Save all
  9.  Hit F9 to compile and run.

Last Modified: 22-NOV-00