Is it possible to add include paths and libraries to all C/C++ projects? In others words: How can I make them global or copy one C/C++ project build setting to another one?<
For libraries I do the following in the source project:
Project -> properties -> c/c++Build -> c++ linker -> libraries
After this I select libraries (shift + mouse) & copy (ctrl + c)
In the blank project:
Project -> properties -> c/c++Build -> c++ linker -> libraries
ctrl + v (paste)
Works fine with eclipse juno
I am looking into it long ago. A few posts mentioned one method: Project > Properties > C/C++ General > Paths and Symbols Then click Export Settings.. But it only works for including header files.
To specify libraries and library paths, as far as I know, I do not find an easy solution. For example, I am now using ffmpeg libraries. If you use "Makefile", the including and library files can be expressed below:
FFMPEG_LIBS= libavdevice
libavformat
libavfilter
libavcodec
libswresample
libswscale
libavutil
CFLAGS := $(shell pkg-config --cflags $(FFMPEG_LIBS)) $(CFLAGS) LDLIBS := $(shell pkg-config --libs $(FFMPEG_LIBS)) $(LDLIBS)
There are many files here. If I include them one by one in an Eclipse C++ project, it is daunting. I do not know why there is no option in Eclipse that we could include library files by using past a long line using ; as a separator, such as:
-lavdevice -lavfilter -lswresample -lswscale -lavformat -lavcodec -ldl -lasound -lSDL -lz -lrt -lavutil -lm
Is there any such way, or I have to type the library files one by one, or have to use Makefile?
I faced the same problem and solved it like this : I saw that in the auto-generated makefile there are lines:
-include ../makefile.init
...
-include ../makefile.defs
...
-include ../makefile.targets
after reading How can I parameterize an Eclipse generated make file I realized that you can define variables outside of you project. That mean it can be shared variable to several projects. So I added makefile.defs file outside of the project and declare in it some variables:
MY_INCLUDE = <path to include>...
MY_LIBS_PATH = <path to libs>...
MY_LIBS = -lmylib ... (the libs)
than in all my projects "properties->c/c++ build->build variables" I defined new variable:
my_include = $(MY_INCLUDE)
my_libs_path = $(MYLIBS_PATH)
my_libs = $(MY_LIBS)
And than you can you those variables in the projects. Go to properties->c/c++ build->Settings and choose compiler includes and add $(my_include). Go to linker and choose Libraries and add to search path $(my_libs_path). For some reason the Libraries (-l) can't take my defined env variable so I bypass it by choosing linker and than go to Miscellaneous and add to linker flags $(my_libs). Finally you have to change the order in the command line (when the linker execute) cause the list of libs need to come after the .o files. So to do that you go to linker and tab and there you can see the final command line that is going to be executed. In "expert settings command line pattern" you move the ${FLAGS} to the back of the command line (that moves the $(my_libs) string to be in the back of the command line). THAT ALL. its a lot but you need to do it only once... hope that it helps someone...
Yes, you can, in 2 steps, more user-friendly as the one mentioned by parvus. Both are done in "Project Properties" -> "C/C++ General" -> "Paths and Symbols":
[Exp]
tag to each line.Referencing the libraries works the same way.
Also have a look at:
I often use the CPATH environment variable to include different directories across all my projects. It's found under: c/c++->build->environment. Be sure to separate each path with a ':' character (not a ';' semicolon).
You can also use PATH to include static libs. However, for me it's only worked reliably in linux. In OSX it ruins make.
The alternative would be to add these libraries and headers to your environments default search paths; place likes /usr/local/lib. Read up on where your linker searches by default.
I just copy one project from using eclipse built in Project explorer. Afterwards, just rename source files.