Author Topic: Linking Nested Dependent Libraries/Sources [SOLVED]  (Read 3716 times)

Offline Guy

  • Single posting newcomer
  • *
  • Posts: 5
Linking Nested Dependent Libraries/Sources [SOLVED]
« on: January 30, 2015, 02:18:01 pm »
Hello everyone.  First and foremost, let me say that I'm fairly new to Code::Blocks and to C/C++ programming in general.  This is probably a noob question.

I'm on Linux trying to use cb 12.11 to compile a C++ program that's available open source, just to get my feet wet with a large project (I've done small standalone projects in the past).  This program uses multiple external static linked libraries.  Now, every time I try to compile the program the compiler complains it can't find a header file for an external library.  So, I track down the header file on my system, put the path in the 'Search Directories' section of my Build Options window and try compilation again.  But then that dependency has another dependency that defines another header file and I have to enter that one into the 'Search Directories' section again.  This process continues over and over again ad nauseum.  I suppose I could end up spending a week compiling, tracing and entering file paths into the build options, but I'm hoping there's a better way.  Like I said, I'm new to this so hopefully there's something I'm missing.

Code
Example (not real but the jist of what I'm experiencing):
(Compile)
source.cpp has [i]#include <gtk/gtk.h>[/i]
Compile error: can't find gtk.h -> locate gtk.h -> put /usr/include/gtk-2.0/ into 'Search Directories'
(Compile)
gtk.h has [i]#include <gio/gio.h>[/i]
Compile error: can't find gio.h -> locate gio.h -> put /usr/include/glib-2.0/ into 'Search Directories'
(Compile)
gio.h has [i]#include <glibconfig.h>[/i]
Compile error: can't find glibconfig.h -> locate glibconfig.h -> put /usr/include/glib-2.0/include/ into 'Search Directories'
etc....

Note, these are all dependent but "standard" libraries.  Also, I've already made sure /usr/include/ is in the Search Directories.  I've seen posts on this forum that say recursive linking is bad and I can understand why but there's just got to be a better way to tell cb (and the compiler/linker for that matter) where all these nested dependent libraries are.  Can anyone tell me how to properly set up my project so it finds these libraries on its own?  Thanks for reading my long post.
« Last Edit: January 30, 2015, 04:00:29 pm by Guy »


Offline stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
Re: Linking Nested Dependent Libraries/Sources
« Reply #2 on: January 30, 2015, 02:57:17 pm »
Another thing to check is Global Compiler Settings for the Compiler being used by the CB Project.
(This has fixed errors similar to yours in the past for me.)

Settings -> Compiler
Select your Compiler
"Global Compiler Settings"
Tab "Build Options" Scroll to right if not visible.
Checkmark "Explicitly add Currently compiling file directory"

Tim S.

« Last Edit: January 30, 2015, 03:08:09 pm by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline Guy

  • Single posting newcomer
  • *
  • Posts: 5
Re: Linking Nested Dependent Libraries/Sources
« Reply #3 on: January 30, 2015, 03:27:11 pm »
Thank you for such a quick reply stahta01!  I checked out those resources, as well as a few others in the FAQ and the Wiki, searched the forums and the web, and finally posted my question here.  I read the rules too and found:
Quote
There's the "Using CodeBlocks" board to help newbies set up their compilers and change their configuration.
I believe I'm dealing with a cb configuration issue, nothing more, which is why I posted my question to this forum.

I took your suggestion and re-read those entries and have come to the conclusion that I need to actually just sit down and enter every dang path to every dang header file on my system in the "Global Compiler Settings" -> Search Directories tab.  What a chore, but oh well, I still really like this IDE.  I tried checking that tick box you mentioned but it doesn't help for dependency libraries, at least in my case.

Thanks again for your suggestions!

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
Re: Linking Nested Dependent Libraries/Sources
« Reply #4 on: January 30, 2015, 03:31:32 pm »
Did you try the normal Linux way?

Using the Linux script command that returns the information; CB Supports that remember to use back ticks.

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline Guy

  • Single posting newcomer
  • *
  • Posts: 5
Re: Linking Nested Dependent Libraries/Sources
« Reply #5 on: January 30, 2015, 03:41:37 pm »
I was thinking along those lines when I created an SDL project through the cb wizard and saw `sdl-config --cflags` under "Compiler settings" and `sdl-config --libs` under "Linker settings".  I think this might be the way to go... it seems promising.  Thanks for that tip!

Offline Guy

  • Single posting newcomer
  • *
  • Posts: 5
Re: Linking Nested Dependent Libraries/Sources
« Reply #6 on: January 30, 2015, 04:00:08 pm »
@stahta01: you rock.  I used the cb GTK+ template to get the compiler and linker configuration tools and simply copied and pasted those into the project.  Just for reference, the strings were:

Compiler settings -> Other options -> `pkg-config gtk+-2.0 --cflags`
Linker settings -> Other linker options -> `pkg-config gtk+-2.0 --libs`

Again, thank you stahta01!