user3530525
user3530525

Reputation: 691

How do you get C++ libraries to work in Eclipse?

I'm not gonna waste too much time moaning about how difficult it is coming from Java, a language where you quite literally click a button and select a file to add external libraries to a project, to C++ where it seems impossible to do without the patience of an owl. I didn't think I'd ever have to post a question like this since it seemed quite elementary but it's been at least 3 weeks of trying and failing. I've also read the vague documentation provided by the eclipse website and it doesn't really cover anything at all.

For example, let's say gtkmm-3.0. I have installed that on my linux machine and everything is fine. Why isn't it possible to just do:

 #include <gtkmm-3.0/gtkmm.h>

since that does come up as a suggestion in Eclipse. At this stage, I'm already at a loss since I think a good IDE shouldn't give suggestions for things that aren't actually usable and if it does,it should at least automatically include them or something.

I have also tried and failed many times with other libraries and asked for help from a full-time C++ developer that I know and he couldn't work his head around the error either.

tl;dr - Download lib off internet, open eclipse, what do?

Sorry if this question seems silly. The depression is honestly just.. terrible when 'working' with C++.

Upvotes: 1

Views: 250

Answers (1)

Benjamin Trent
Benjamin Trent

Reputation: 7566

The best way I have found for including and linking against the appropriate libraries has been to create build variables for all configurations. This way I can have one place where I add/remove libraries and flags as needed.

  • Create your build variables
    • Right click your project and select properties then C/C++ Build -> Build Varialbes
    • Make sure that configuration is set to [All Configurations]
    • Select add and give it a name like GTK_CFLAGS and for the value, it is a string of the type `pkg-config gtkmm-3.0 --cflags`(those are back ticks)
    • Now do another variable but name it GTK_LIBS and use the flag --libs instead of --cflags.
    • Select Apply
  • Now Go to Settings(should be under C/C++ build as well)
    • Make sure that configuration is for all configurations and not just release or debug
    • Select GCC C++ Compiler(or whatever compiler you are using)
    • In the command line pattern (should look something like ${COMMAND} ${FLAGS} ${OUTPUT_FLAG}${OUTPUT_PREFIX}${OUTPUT} ${INPUTS} -std=c++11) add ${GTK_CFLAGS}(or whatever you called it) after the command macro
    • select apply
    • Now Select GCC C++ Linker and in the command line pattern after ${INPUTS} put ${GTK_LIBS} and select apply

This should let you compile with GTKmm, there may still be issues with the indexer and autocomplete. If you want to include specific header files so that your indexer and autocomplete can seen them. You can do that in C/C++ General-> Paths and Symbols and add the include directory and then select apply and rebuild your index.

Upvotes: 1

Related Questions