i.amniels
i.amniels

Reputation: 1841

Add external source files from a library to the project in Eclipse-CDT

I have a project which I try to compile with Eclipse-CDT. The project depends on a library with header files and source files. How can I configure the project in Eclipse such that it will compile the needed source files from the library with the project?

With a makefile I use:

SRC+=lib_source.c

Upvotes: 2

Views: 5928

Answers (2)

Andrew Meyer
Andrew Meyer

Reputation: 27

Another approach is to use the operating system to add your libraries to the project. Eclipse then treats all source files (including library files) as part of the project, and therefore compiles any that need it even if they are in the libraries. This set-up allows keeping the library sources in a separate git repository from the project source code. You can record the git commit of a library to provide library version control so that improving the library in one project does not break all the others. The setup relies on the operating system's capability to link directories in a way that is entirely transparent to eclipse--in windows using the mklink command.

In windows the steps are

  1. put your library files in a clean workspace not mixed with .git (you can have .git in the parent directory as egit sets it up)
  2. use cmd window in administrator mode to add a link from your project directory to your library directory.
  3. from eclipse press F5 t make sure your project matches what is on disk, then set up git to ignore your library directory.
  4. set up your library file properties for read only access unless you are still tweaking that library.
  5. set up your project include path to include the project sub-directory in your project.

I can't remember why I abandoned eclipse linked directories; i think it was that the includes kept breaking. The mklink approach has worked flawlessly so far.

I have a pdf tutorial of how to set this up--but I'm new to the forum and don't see how to attach a file.

Upvotes: 0

Avihai Marchiano
Avihai Marchiano

Reputation: 3927

You can add linked source file. Choose project properties and in the left panel choose c++ general. Under it choose path and symbols. Now in the right panel tabs choose source location and add linked source folder. Include you need to define in "include" (under c++ build you will find settings)

Upvotes: 6

Related Questions