1

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++.

user3530525
  • 691
  • 3
  • 8
  • 20
  • So, you are asking how to link against a library? Or how to include the header? – Benjamin Trent Mar 11 '15 at 01:44
  • Both. I've tried tons of IDE paths, linker flags, everything. The closest I got to it working was when gtkmm threw some form of error that had a mangled constructor name from another lib in it. I just can't seem to get any library to work at all. – user3530525 Mar 11 '15 at 01:50
  • What platform are you on? – Benjamin Trent Mar 11 '15 at 15:01
  • @BenjaminTrent Linux. All the libs are in /usr/include. I just switched IDE to Qt creator which seems to make more sense but now I'm getting dependency errors with versions of another library, atkmm - which I cannot find links for anywhere. I'm starting to think that the way you set up libraries for each library is completely different and will always give you errors. – user3530525 Mar 11 '15 at 15:05
  • usually your libraries are in /usr/lib/ and your header files are in /usr/include/. Did you put them in the same place? You have to compile with the correct include directories, and then link the corresponding libraries after compilation so that your binary file knows where the header file implementations are located. – Benjamin Trent Mar 11 '15 at 15:11
  • @BenjaminTrent Hmm.. I don't have a gtkmm folder in /usr/lib/. Only the header files in the /usr/include/. – user3530525 Mar 11 '15 at 15:13
  • Its not a folder, but your library files, and since each system is set up differently, the only way to reliably link against them(if you installed the package traditionally) is to use `pkg-config gtkmm-3.0 --cflags` for compilation(creating object files) and `pkg-config gtkmm-3.0 --libs` for the libraries you need to link against when creating the binary. – Benjamin Trent Mar 11 '15 at 15:16
  • @BenjaminTrent I know this will sound silly, but would you be able to tell me how to actually use those in eclipse. I tried just adding it to the Cross G++ compiler and linker commands in eclipse but that made all other includes unresolved. I'd much appreciate it. – user3530525 Mar 11 '15 at 15:23

1 Answers1

1

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.

Benjamin Trent
  • 7,378
  • 3
  • 31
  • 41
  • Let me know if you still have issues, Eclipse is hairy and frustrating...I have been debating on moving towards CLion but my company's make files are not CMake and I don't want to bother changing them... – Benjamin Trent Mar 11 '15 at 15:44
  • I'll try this out later and tell you how it goes, thanks for the help. – user3530525 Mar 11 '15 at 15:49
  • I tried this out, kinda. I was able to update a library that gtkmm depends on and finally got an example working: http://i.imgur.com/X47luPS.png Now I just gotta try this out in Eclipse. Thanks Benjamin. – user3530525 Mar 11 '15 at 22:39
  • 1
    You, Benjamin, are a legend. Thank you so much. All working now. http://i.imgur.com/wvgly5C.png Thanks again. – user3530525 Mar 11 '15 at 23:00