Next: Creating a project, Previous: EDE Mode, Up: EDE [Contents]
Once you have EDE enabled, you can create a project. This chapter provides an example C++ project that will create Automake files for compilation.
First, lets create a directory for our project. For this example, we’ll start with something in /tmp.
C-x C-f /tmp/myproject/README RET M-x make-directory RET RET
Now put some plain text in your README file to start.
Now, lets create the project:
M-x ede-new RET Automake RET myproject RET
Nothing visible happened, but if you use dired
to look at the
directory, you should see this:
/tmp/myproject: total used in directory 32 available 166643476 drwxr-xr-x 2 zappo users 4096 2012-02-23 22:10 . drwxrwxrwt 73 root root 20480 2012-02-23 22:10 .. -rw-r--r-- 1 zappo users 195 2012-02-23 22:10 Project.ede -rw-r--r-- 1 zappo users 10 2012-02-23 22:09 README
We’ll make a more complex project, so use dired to create some more directories using the + key, and typing in new directories:
+ include RET + src RET
Now I’ll short-cut in this tutorial. Create the following files:
include/myproj.hh
/** myproj.hh --- */ #ifndef myproj_hh #define myproj_hh 1 #define IMPORTANT_MACRO 1 int my_lib_function(); #endif // myproj_hh
src/main.cpp
/** main.cpp --- */ #include <iostream> #include "myproj.hh" int main() { } #ifdef IMPORTANT_MACRO int my_fcn() { } #endif
src/mylib.cpp
/** mylib.cpp --- * * Shared Library to build */ int my_lib_function() { }
EDE needs subdirectories to also have projects in them. You can now create those projects.
With main.cpp as your current buffer, type:
M-x ede-new RET Automake RET src RET
and in myproj.hh as your current buffer, type:
M-x ede-new RET Automake RET include RET
These steps effectively only create the Project.ede file in which you will start adding targets.
In order to build a program, you must have targets in your EDE
Projects. You can create targets either from a buffer, or from a
dired
directory buffer.
Note: If for some reason a directory list buffer, or file does not have the ‘Project’ menu item, or if EDE key bindings don’t work, just use M-x revert-buffer RET to force a refresh. Sometimes creating a new project doesn’t restart buffers correctly.
Lets start with the header file. In include/myproj.hh, you could use the menu, but we will now start using the EDE command prefix which is C-c ..
C-c . t includes RET miscellaneous RET y
This creates a misc target for holding your includes, and then adds myproj.hh to the target. Automake (the tool) has better ways to do this, but for this project, it is sufficient.
Next, visit the src directory using dired. There should be a ‘Project’ menu. You can create a new target with
. t myprogram RET program RET
Note that . t is a command for creating a target. This command is also in the menu. This will create a target that will build a program. If you want, visit Project.ede to see the structure built so far.
Next, place the cursor on main.cpp, and use . a to add that file to your target.
. a myprogram RET
Note that these prompts often have completion, so you can just press TAB to complete the name myprogram.
If you had many files to add to the same target, you could mark them all in your dired buffer, and add them all at the same time.
Next, do the same for the library by placing the cursor on mylib.cpp.
. t mylib RET sharedobject RET . a mylib RET
Next, we’ll try to compile the project, but we aren’t done yet, so it won’t work right away.
Visit /tmp/myproject/Project.ede. We’re starting here because we don’t have any program files in this directory yet. Now we can use the compile command:
C-c . C
Because this is the very first time, it will create a bunch of files for you that are required by Automake. It will then use automake to build the support infrastructure it needs. This step is skipped if you choose just a Makefile build system.
After the Automake init, it runs compile. You will immediately discover the error in main.cpp can’t find myproj.hh. We need to go fix this.
To fix the failed compile, we need to add /tmp/myproject/include to the include path.
Visit main.cpp.
M-x customize-project RET
Select the ‘[Settings]’ subgroup of options. Under ‘Variable :’ click ‘[INS]’. At this point, you need to be somewhat savvy with Automake. Add a variable named ‘CPPFLAGS’, and set the value to ‘../include’.
You should see something like this:
Variables : [INS] [DEL] Cons-cell: Name: AM_CPPFLAGS Value: -I../include [INS] Variables to set in this Makefile.
Click ‘[Apply]’. Feel free to visit Project.ede to see how it changed the config file.
Compile the whole project again with C-c . C from main.cpp. It should now compile.
You can run your program directly from EDE.
C-c . R RET RET
If your program takes command line arguments, you can type them in when it offers the command line you want to use to run your program.
Next: Creating a project, Previous: EDE Mode, Up: EDE [Contents]