Setting up an emacs EDE-project with libraries

2019-04-29 19:37发布

I already searched the emacs documentation, the cedet website and here on SO in vain. If my question is already been answered, fell free to (point out to an existing answer and) close it.

I'm trying to familiarize myself with EDE-projects in emacs. So far I can set up a simple project with one or more files.

Now I'd like to separate a part of my code and pack it into a library. Basically I'm trying to achieve the same thing I get with the following hand-written naive Makefile:

matrix:
  g++ -c -o lib/libmatrix.o lib/matrix.cpp -std=c++0x
  ar crf lib/libmatrix.a lib/libmatrix.o

num:
    g++ num.cpp -Llib -Ilib -std=c++0x -o num -g

Here I have a library consisting of "lib/matrix.h" and "lib/matrix.cpp" (it's a toy implementation of a matrix type) and a file "num.cpp" that uses matrix.

I don't know how to tell emacs to compile matrix properly. So far I got the following EDE-project, but of course it doesn't compile.

;; Object Numbers
;; EDE project file.
(ede-proj-project "Numbers"
  :name "Numbers"
  :file "Project.ede"
  :targets (list 
   (ede-proj-target-makefile-program "num"
    :name "num"
    :path ""
    :source '("num.cpp")
    :compiler 'ede-g++-compiler
    :linker 'ede-g++-linker
    :configuration-variables 'nil
    :ldflags '("-std=c++0x" "-Llib" "-Ilib")
    :ldlibs '("matrix")
    )
   (ede-proj-target-makefile-archive "matrix"
    :name "matrix"
    :path "/lib"
    :source '("matrix.cpp")
    :compiler 'ede-g++-compiler
    :linker 'ede-archive-linker
    :configuration-variables 'nil
    )
   )
  :configuration-variables 'nil
  )

标签: c++ emacs cedet
1条回答
对你真心纯属浪费
2楼-- · 2019-04-29 20:01

So,

i think I solved it. I'm answering the question myself, in case someone stumbles on the same difficulties.

Basically I needed to define a subproject in the directory "lib/" which compiles and archives the library.

I now have the following files

include/
    matrix.h
lib/
    Project.ede
    matrix.cpp
Project.ede
num.cpp

the config-file lib/Project.ede is the subproject responsible for the library and it looks like this:

;; Object matrix
;; EDE project file.
(ede-proj-project "matrix"
  :name "matrix"
  :file "Project.ede"
  :targets (list 
   (ede-proj-target-makefile-archive "matrix"
    :name "matrix"
    :path ""
    :source '("matrix.cpp")
    :configuration-variables '(("debug" ("CPPFLAGS" . "-I../include -std=c++0x -g"))    ("release" ("CPPFLAGS" . "-I../include -std=c++0x")))
    )
   )
  )

The main file ./Project.ede looks like this:

;; Object num
;; EDE project file.
(ede-proj-project "num"
  :name "num"
  :file "Project.ede"
  :targets (list 
   (ede-proj-target-makefile-program "num"
    :name "num"
    :path ""
    :source '("num.cpp")
    :configuration-variables '(("debug" ("CPPFLAGS" . "-std=c++0x -Iinclude")) ("release" ("CPPFLAGS" . "-std=c++0x -Iinclude")))
    :ldflags '("-Llib")
    :ldlibs '("matrix")
    )
   )
  )
查看更多
登录 后发表回答