Note: the instructions here are for Eclipse C/C++, version 4.16 on Linux Ubuntu 20.04. There may be differences for other versions and OSs.
The script build.sh can be used to generate Eclipse project files for apg
and all of the examples. This section gives explicit instructions on how to do this. Execute
$./build.sh -d all
Open the Eclipse IDE and switch the workspace to the apg-7.0 repository directory. Navigate to
Project->Build Automatically
Uncheck or toggle off this option. Optionally, but a good practice, is to also use spaces instead of tabs in all code and documents. Navigate to
Window->Preferences->General->Editors->Text Editors
and check the box "Insert spaces for tabs". Navigate to
Window->Preferences->C/C++ ->Code Style->Formatter
Under "Active profile:" click edit. At the "Indentation" tab select "Spaces only" for the Tab policy. At the "Line Wrapping" tab type in your favorite Maximum line width. 120 often works well. At the top for "Profile name:" type in "MyProfile" or your preferred profile name. Click "OK". Click "Apply and Close".
We are now ready to import the projects generated by build.sh
. Navigate to
File->import->General->Existing Projects into Workspace
At "Select root directory" type or Browse to (full path) ./Debug
. Under "Projects" all of the generated projects should appear already selected. Click "Finish". At this point you should be able to build, run, edit and debug apg
and all of the examples of its use.
It is a good practice to keep the source directories clean and keep all of the project and build files separate. In the repository directory. e.g.
$mkdir build
Open the Eclipse IDE. The workspace location is not important, but it is probably good practice to switch the work space to the repository directory. Follow the instructions above for configuring Eclipse for the new workspace. To create a new project navigate to
File->new->C/C++ Project->C Managed Build
In "Project name" type "apg70". Uncheck the box "Use default location" and type or Browse to (full path name) ./build/apg70
The "Project type:" should be "Executable->Empty Project" and "Toolchains:" should be "Linux GCC" . Click "Finish". The project is now created.
Next it needs to be configured with the necessary macros and source libraries. Right click on the project name and navigate to
Properties->C/C++ General->Paths and Symbols
At the "#Symbols" tab click "Add" and type APG_AST
. Check the box "Add to all configurations" and click "OK". At the "Source Location" tab click "Link Folder...". In the "Folder name:" box type apg
. Check the box "Link to folder in the file system" and navigate to (full path) ./apg
. Click OK
. Repeat for
api
library
utilities
The project is now ready to build. Right click the project and select BuildConfigurations->Set Active->Debug
. Right click the project name again and select Build Project
. It should build with no errors or warnings. At this point you can run, edit and debug the apg
project in the normal Eclipse manner.
Projects for all of the example applications can be created with a similar process.
However, most of the examples read and write files from and to
./examples/input
./examples/output
Therefore, these programs need to know how to find these directories regardless of the current working directory at the time of execution. This is handled automatically by cmake
. cmake
generates a header file with the absolute location of the source code defined. For the manual builds of the examples that do input and output it is necessary to manually add a header file to serve that purpose. For example, in the ex-trace
example it is necessary to add the header file
./examples/ex-trace/source.h
with the content
#ifndef SOURCE_H_
#define SOURCE_H_
#define SOURCE_DIR "/my/path/apg-7.0/examples/ex-trace"
#endif /* SOURCE_H_ */
where /my/path/
is the absolute path to the repository directory.