Difference between revisions of "Configuring C Projects"

From AtlasWiki
Jump to: navigation, search
Line 1: Line 1:
The steps below detail how to import an existing C code base into an Eclipse project and some advanced project configuration this is necessary for large C projects like the Linux Kernel.
 
  
<br>
+
In order to map your C code, Atlas needs the same settings that the compiler needs to build your project.  The following guide explains common ways to import an existing C code base into an [http://www.eclipse.org/cdt/ Eclipse CDT] project, and to prepare it for mapping with Atlas.
<u>Importing C projects in Eclipse</u>
+
<br>
+
If the project requires a special compiler (other than gcc), you may need to install additional CDT features.  In particular, if your project requires a gcc-based cross compiler, you may need to install the CDT feature "C/C++ GCC Cross Compiler Support".
  
#Import, if the project has a Makefile:
+
==Importing C projects in Eclipse==
#*Right-click in the package explorer.
+
*If the project has a Makefile:
#*Select '''Import'''.
+
**From the '''File''' menu, select '''Import'''.
#*In the popup dialogue, expand '''C/C++''', select '''Existing Code as Makefile Project''', and click '''Next'''.
+
**In the popup dialogue, expand '''C/C++''', select '''Existing Code as Makefile Project''', and click '''Next'''.
#*Enter a project name and indicate the directory to import.
+
**Enter a project name and indicate the directory to import.  Set the '''Toolchain for Indexer Settings'''.  For cross compilation with gcc, select '''Cross GCC'''.
#*Click '''Finish'''.
+
**Click '''Finish'''.
#Import, if the project does NOT have a Makefile:
+
*If the project does NOT have a Makefile:
#*Right-click in the package explorer.
+
**From the '''File''' menu, select '''New''', then '''Other…''' .
#*Select '''New > Project…'''
+
**In the popup dialogue, expand '''C/C++''', select '''C Project''', and click '''Next'''.
#*In the popup dialogue, select '''General > Project''' and click '''Next'''.
+
**Expand the Project type '''Executable''', and click '''Empty Project'''.
#*Enter a project name and click '''Finish'''.
+
**Enter a project name and click '''Finish'''.
#*Right-click on the project and select '''Import'''.
+
**Right-click on the project and select '''Import'''.
#*Enter the parent directory, select files to import, and click '''Finish'''.
+
**In the popup dialogue, expand '''General''', select '''File System''', and click '''Next'''.
 +
**Enter the parent directory, select files to import, and click '''Finish'''.
 +
**Make adjustments to the include paths and preprocessor directives as needed.  Right-click on the project, folders, or files, and select '''Properties'''.
 +
**In the popup dialog, expand '''C/C++ Build''' and select '''Settings'''.  Add include paths and preprocessor directives as needed.  See also: [http://help.eclipse.org/neon/index.jsp?topic=%2Forg.eclipse.cdt.doc.user%2Freference%2Fcdt_u_prop_build_settings_tool.htm CDT Help].
 +
 +
==Configuring C projects for Atlas==
 +
'''At this point, your C project may be already configured correctly.'''  In order for Atlas to obtain compiler settings (such as include paths and preprocessor directives), the CDT must be able to build your C project and observe invocations of your compiler.  Review the steps below to ensure that Atlas can extract compiler information from the build process.
  
<br>
+
If your project uses a gcc-based cross compiler, configure the project to use it (instructions adapted from [http://stackoverflow.com/questions/27180771/how-to-configure-a-particular-gcc-cross-toolchain-in-eclipse-cdt stackoverflow.com]).
<u>Advanced Set up for C projects</u>
+
*Right-click on the project and select '''Preferences'''.
<br>
+
*Ensure the project is configured to use the Cross GCC Tool Chain.
 +
**Expand '''C/C++ Build''' and select '''Tool Chain Editor'''.
 +
**Set the '''Current toolchain''' to '''Cross GCC'''.
 +
**Click '''Apply'''.
 +
*In the popup dialog, select '''C/C++ Build'''.
 +
**Check '''Generate Makefiles automatically''', but do NOT Apply.
 +
*Under '''C/C++ Build''', select '''Settings'''.
 +
*Under the '''Tool Settings''' tab, select '''Cross Settings'''.  Set the cross compiler settings for '''Prefix''' and '''Path'''.  For example:
 +
**Prefix: arm-none-eabi-
 +
**Path: /usr/bin
 +
*Select '''C/C++ Build''' again, uncheck '''Generate Makefiles automatically'''.
 +
*Click '''Apply'''.
  
'''For a typical C project, no further setup is necessary.''' However, large projects like the Linux kernel have a complicated build system that Atlas must understand in order to map the code correctly. To do this Atlas will analyze the build commands used to build the project. The steps below detail the changes necessary to map only the files built by the make file.
+
The steps below detail the changes necessary to accurately map the files built by the Makefile.
 +
*Ensure that the CDT can observe invocations of your compiler during a build.  Makefiles for large projects (such as Linux) suppress the full text of the invocation for readability, but there is usually a way to emit the invocations in verbose mode.
 +
**Select '''C/C++ Build''' and uncheck '''"Use default build command"'''.  Adjust the command to make the output verbose. Common options include “make V=1” or “make VERBOSE=1”.
 +
*Configure Atlas to observe the build:
 +
**Right-click on the project and select '''Properties'''.
 +
**Select '''Atlas C Build'''.
 +
**Under '''Build Commands''', add the name of the compiler used by the project. Atlas will look for invocations of these compilers when parsing the output of the project's build.
 +
**Under '''Source files to map''', select '''Map only files in current build'''.
 +
**Click '''OK'''.
 +
 +
==Build==
 +
*To accurately map the project, it must be built so that the compiler invocations can be observed.
 +
**If your project uses a CDT-generated Makefile, or the Makefile has an “all” target
 +
*Right-click on the project in the '''Project Explorer''' and select '''Build Project'''
 +
**If your project has a hand-written Makefile
 +
**Right-click on the project in the '''Project Explorer''' and expand '''Build Targets''' and select '''Create…''' .
 +
**In '''Target name''', enter the name of the build target.  Click '''OK'''.
 +
**In the '''Project Explorer''' view, expand the project, expand the '''Build Targets''', and double-click on the target.
  
#Add the compiler build command:
+
==Map==
#* Right-click on the project in the package explorer and select '''Properties'''.
+
*After the project has been successfully built, it can be mapped with Atlas.
#* Under '''Atlas C/C++ Build''', add the name of the compiler used by the project to the '''Build Commands'''. Atlas will look for commands sent to these compilers when parsing the output of the project's makefile.
+
**Right-click on the project in the '''Project Explorer''', expand Atlas, and select '''Enable Mapping'''.
#* Click '''OK'''.
+
**Select '''Atlas''' from the main menu, and select '''Re-Map Workspace'''.
# Use information from build commands
+
#* Right-click on the project in the package explorer and select '''Properties'''.
+
==Troubleshooting==
#* Select '''Map only files in current build''' under '''Source files to map'''.
+
If Atlas is unable to properly map the project, try the following:
#* Select '''Use discovered configuration for files in the current build''' under '''File configuration'''.
+
*Clean and build the project and make sure the build output is being correctly parsed:
#* Click '''OK'''.
+
**Right-click on the project in the package explorer and select '''Properties'''.
 +
**Look under '''Atlas C Build > Build Configuration File'''.
 +
**If the '''Open''' button under '''Build Configuration File''' is grayed out, or if it says zero files were found, then Atlas was unable to detect the build configuration. Select '''C/C++ Build''' and uncheck '''“Use default build command”'''.
 +
**Adjust the command to make the output verbose. Necessary flags may vary; common options include “V=1” or “VERBOSE=1”.
 +
**Clean and build the project.  Check that '''Build Configuration File''' is nonzero.
 +
*If Atlas’ code map is still empty, it may be that the Makefile is improperly reporting changing directories.
 +
**Right-click on the project in the package explorer and select '''Properties'''.
 +
**Select '''C/C++ Build''' and uncheck “Use default build command”.
 +
**Add the flag “--print-directory”.
 +
**Clean and build the project.
  
<br>
 
<u>Troubleshooting</u>:  If Atlas is unable to properly map the project, try the following fixes:
 
<br>
 
  
#Clean and build the project and make sure the build output is being correctly parsed:
 
#*Right-click on the project in the package explorer and select '''Properties'''.
 
#*Look under '''Atlas C/C++ Build > Build Configuration File'''.
 
#*If the '''Open''' button under '''Build Configuration File''' is grayed out, or if it says zero files were found, then Atlas was unable to detect the build configuration. Select '''C/C++ Build''' and uncheck “Use default build command”.
 
#*Adjust the command to make the output verbose.  Necessary flags may vary; common options include “V=1” or “VERBOSE=1”.
 
#*Clean and build the project and check that '''Build Configuration File''' is nonzero.
 
#If Atlas’ code map is still empty, it may be that the Makefile is improperly reporting changing directories.
 
#*Right-click on the project in the package explorer and select '''Properties'''.
 
#*Select '''C/C++ Build''' and uncheck “Use default build command”.
 
#*Add the flag “--print-directory”.
 
#*Clean and build the project.
 
  
 
<br>
 
<br>
For versions of Atlas before Atlas 3.0, see the set up instructions at [[Configuring C Projects for Atlas 2.0]].
+
For versions of Atlas before Atlas 3.0, see the instructions at [[Configuring C Projects for Atlas 2.0]].
  
 
<br>
 
<br>
 
If you experience difficulty in setting up Atlas, please contact [mailto:[email protected] [email protected]] for assistance.
 
If you experience difficulty in setting up Atlas, please contact [mailto:[email protected] [email protected]] for assistance.

Revision as of 15:44, 5 June 2017

In order to map your C code, Atlas needs the same settings that the compiler needs to build your project. The following guide explains common ways to import an existing C code base into an Eclipse CDT project, and to prepare it for mapping with Atlas.

If the project requires a special compiler (other than gcc), you may need to install additional CDT features. In particular, if your project requires a gcc-based cross compiler, you may need to install the CDT feature "C/C++ GCC Cross Compiler Support".

Importing C projects in Eclipse

  • If the project has a Makefile:
    • From the File menu, select Import.
    • In the popup dialogue, expand C/C++, select Existing Code as Makefile Project, and click Next.
    • Enter a project name and indicate the directory to import. Set the Toolchain for Indexer Settings. For cross compilation with gcc, select Cross GCC.
    • Click Finish.
  • If the project does NOT have a Makefile:
    • From the File menu, select New, then Other… .
    • In the popup dialogue, expand C/C++, select C Project, and click Next.
    • Expand the Project type Executable, and click Empty Project.
    • Enter a project name and click Finish.
    • Right-click on the project and select Import.
    • In the popup dialogue, expand General, select File System, and click Next.
    • Enter the parent directory, select files to import, and click Finish.
    • Make adjustments to the include paths and preprocessor directives as needed. Right-click on the project, folders, or files, and select Properties.
    • In the popup dialog, expand C/C++ Build and select Settings. Add include paths and preprocessor directives as needed. See also: CDT Help.

Configuring C projects for Atlas

At this point, your C project may be already configured correctly. In order for Atlas to obtain compiler settings (such as include paths and preprocessor directives), the CDT must be able to build your C project and observe invocations of your compiler. Review the steps below to ensure that Atlas can extract compiler information from the build process.

If your project uses a gcc-based cross compiler, configure the project to use it (instructions adapted from stackoverflow.com).

  • Right-click on the project and select Preferences.
  • Ensure the project is configured to use the Cross GCC Tool Chain.
    • Expand C/C++ Build and select Tool Chain Editor.
    • Set the Current toolchain to Cross GCC.
    • Click Apply.
  • In the popup dialog, select C/C++ Build.
    • Check Generate Makefiles automatically, but do NOT Apply.
  • Under C/C++ Build, select Settings.
  • Under the Tool Settings tab, select Cross Settings. Set the cross compiler settings for Prefix and Path. For example:
    • Prefix: arm-none-eabi-
    • Path: /usr/bin
  • Select C/C++ Build again, uncheck Generate Makefiles automatically.
  • Click Apply.

The steps below detail the changes necessary to accurately map the files built by the Makefile.

  • Ensure that the CDT can observe invocations of your compiler during a build. Makefiles for large projects (such as Linux) suppress the full text of the invocation for readability, but there is usually a way to emit the invocations in verbose mode.
    • Select C/C++ Build and uncheck "Use default build command". Adjust the command to make the output verbose. Common options include “make V=1” or “make VERBOSE=1”.
  • Configure Atlas to observe the build:
    • Right-click on the project and select Properties.
    • Select Atlas C Build.
    • Under Build Commands, add the name of the compiler used by the project. Atlas will look for invocations of these compilers when parsing the output of the project's build.
    • Under Source files to map, select Map only files in current build.
    • Click OK.

Build

  • To accurately map the project, it must be built so that the compiler invocations can be observed.
    • If your project uses a CDT-generated Makefile, or the Makefile has an “all” target
  • Right-click on the project in the Project Explorer and select Build Project
    • If your project has a hand-written Makefile
    • Right-click on the project in the Project Explorer and expand Build Targets and select Create… .
    • In Target name, enter the name of the build target. Click OK.
    • In the Project Explorer view, expand the project, expand the Build Targets, and double-click on the target.

Map

  • After the project has been successfully built, it can be mapped with Atlas.
    • Right-click on the project in the Project Explorer, expand Atlas, and select Enable Mapping.
    • Select Atlas from the main menu, and select Re-Map Workspace.

Troubleshooting

If Atlas is unable to properly map the project, try the following:

  • Clean and build the project and make sure the build output is being correctly parsed:
    • Right-click on the project in the package explorer and select Properties.
    • Look under Atlas C Build > Build Configuration File.
    • If the Open button under Build Configuration File is grayed out, or if it says zero files were found, then Atlas was unable to detect the build configuration. Select C/C++ Build and uncheck “Use default build command”.
    • Adjust the command to make the output verbose. Necessary flags may vary; common options include “V=1” or “VERBOSE=1”.
    • Clean and build the project. Check that Build Configuration File is nonzero.
  • If Atlas’ code map is still empty, it may be that the Makefile is improperly reporting changing directories.
    • Right-click on the project in the package explorer and select Properties.
    • Select C/C++ Build and uncheck “Use default build command”.
    • Add the flag “--print-directory”.
    • Clean and build the project.



For versions of Atlas before Atlas 3.0, see the instructions at Configuring C Projects for Atlas 2.0.


If you experience difficulty in setting up Atlas, please contact [email protected] for assistance.