auto-complete
does not work for Emacs C++ projects that have multiple modules. The header files each sub-module depends on exist both in the module itself and in other modules. In other words, one module may include header files of another module.
Below is my sample source code:
.
├── CMakeLists.txt
├── my_inc
│ ├── CMakeLists.txt
│ ├── myadd.cpp
│ └── myadd.h
├── README.md
└── src
├── CMakeLists.txt
├── Hello.java
├── helper.cpp
├── helper.h
└── main.cpp
The main.cpp
:
#include "myadd.h"
#include "helper.h"
int main() {
MyAdd add_obj;
Helper h;
h.toString(); // Auto-complete works since Helper is in the same directory.
add_obj. // Auto-complete for add_obj does not work
// because myadd.h is in another directory (my_inc).
}
The method list pops up when I type .
after h
, but does not for variable add_obj
, the class of which is defined in myadd.h
from other module my_inc
.
I have tried some solutions (CEDET-related):
(ede-cpp-root-project)
This solution does work here. I do not want to apply this one since
it would make my .emacs
large since I have many projects.
:include-path
here is unable to handle complicated header dependence of 20+ sub-modules, which makes this solution more like toy. I prefer separating configuration from .emacs
.
EDE project
I create project and target via ede-new
and c c . t, but this only for compilation instead of name, method auto-complete.
ede-generic-project
As described in the solution to this question and the manual on ede-generic-project
but I'm getting this error:
eieio-oref: Wrong type argument: (or eieio-object-p class-p), nil
once I execute:
M-x ede-customize-project
RET after (ede-enable-generic-projects)
.
Environment: I use Emacs 24.3 and installed auto-complete
and cedet2.0
.
Step 1 when working through issues that involve projects, header files and completion is to enable (global-semantic-decoration-mode 1)
which includes a mechanism for highlighting header files in red when the can't found. that helps in quickly working through configuration problems.
If you want to keep your .emacs
file clean and get some project support, the generic project type is a good bet, right up until that error started showing up. That is fixed in the CEDET bzr repository under the ede-ldf branch as of this writing (July 14, 2014) and will be merged up sometime soon.
If you have lots of sub-modules, you can also rely on a tool like GNU Global. The cedet manual has a short section about using GNU Global that includes the snippet you need to help it locate files. In that way, Global will track all your headers, and then that can be used to find them. If all your headers have a unique name, you will be all set. If the file "myadd.h" exists in several places, and you need to choose which "myadd.h" based on where the C file is, you will be out of luck, and will need a custom project type to do that.
After each configuration change, you will need to do a forced reparse of the buffer with the headers you want to be found so that the caches get refreshed. Use C-u M-x bovinate RET
to force it.