User forums > Using Code::Blocks

adding library files and getting function declaration

(1/2) > >>

lehe:
Hi,
Here are two of my questions while using codeblocks:

1. Is there a convenient way to add multiple library files for the same library, instead of adding one file at one time? I known in terminal, we can use something like "gcc `pkg-config --cflags --libs libraryname` -o my-prgm my-prgm.c".

2. While using some libraries,  I often want to see declarations of their functions.  For some of them, I right-click and try jumping to their declarations but nothing is found, even if the include directories have been correctly specified and the header files have been successfully found by the compiler. Also placing the mouse on functions sometimes don't give declaration. What should I do?

Thanks a lot!

Jenna:

--- Code: ---`pkg-config --libs libraryname`
--- End code ---
can be used if pkg-config and an appropriate config-file exists.

Just place it including the backticks in your projects build options, tab "Linker settings -> Other linker options".


--- Code: ---`pkg-config --cflags libraryname`
--- End code ---
can be used for includes and compile-flags in "Compiler settings -> Other options".

The backticks work on windows also (only in C::B).

You can, of course, call any other external program or script also and the call within the backticks will be replaced by the output.

lehe:
Thanks, Jens! I tried what you said and it works!

I still feel very hard to get declarations of functions of the libraries I am using.   I cannot get the declarations by right-clicking and choosing to jump to their declarations in the header files or by placing the mouse on their name to get a hint. However in Visual C++, I can get declarations of the functions in either way. I think I must miss something in CB. Please help if you have any idea. I am using svn5432 by the way. Thanks a lot!

some other updates:
While "gcc `pkg-config --cflags --libs opencv` `pkg-config --cflags --libs gtk+-2.0` -o my-prgm my-prgm.c" works fine, building my program with same settings in CB can give erros like these:

1.   /usr/lib/libgtk.a and /usr/lib/libgdk.a are not found. gtk+-2.0 is installed on my system, but the missing library files are provided by a lower gtk version gtk-1.2 and the problem can be fixed by installing gtk-1.2.  Is this because codeblocks is based on gtk-1.2 or something?

2.

--- Code: ---/usr/lib/libX11.a(CrGlCur.o)||In function `open_library':|
||warning: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking|
/usr/lib/libdl.a(dlopen.o)||In function `dlopen':|
(.text+0x1b)||undefined reference to `__dlopen'|
/usr/lib/libdl.a(dlsym.o)||In function `dlsym':|
(.text+0x1b)||undefined reference to `__dlsym'|
||=== Build finished: 2 errors, 1 warnings ===|

--- End code ---
I fix it by adding libdl.a to linking.  Is it because codeblocks is based on libdl or some other reason?

MortenMacFly:

--- Quote from: lehe on February 03, 2009, 01:08:47 am ---I fix it by adding libdl.a to linking.  Is it because codeblocks is based on libdl or some other reason?

--- End quote ---
Note: This is a linker error that is just reported by C::B (which is an IDE, not a compiler/linker). So it's not a C::B issue.

In general: If you use function foo of library bar you need to link against the library bar. That's how libraries work: They provide functions you don't need to implement yourself but you are responsible for linking the libraries into you application correctly. Grab a programmers book to read more about this topic. It's really helpful if a developer knows at least how a compiler/linker works and how I use 3rd party libraries correctly.

However - this goes beyond the scope of C::B and thus violates our forum rules. Topic locked therefore.

MortenMacFly:
Topic re-opened on request with more details (now it's C::B specific):


--- Quote ---1. My questions is: in CB, even if I set correctly the directories of header files and library files and what the library files that my code should be linked to and build my program successfully, I still can't get the declaration for its functions or jump to its header files in CB, neither can I for some functions of standard C/C++ library, like exit(), printf(). But I can get declarations from string or math libraries, like for strcp() and log(). Without being able to see the declaration of functions I need, I feel very difficult to use CB. I guess I might be doing something wrong, but it is really not a how-to-use-library issue, but a how-to-use-CB issue.  I have been bothered by this problem for quite some time, along with 8.02, 5382 and 5432. If someone know a clue, it will help me a lot.

2. for CB and gcc, under the same setting "`pkg-config --cflags --libs opencv` `pkg-config --cflags --libs gtk+-2.0`" , my program could be built successfully with gcc but not CB unless I have to do some extra stuff: install gtk1.2 and link my program to libdl.a.

--- End quote ---

Navigation

[0] Message Index

[#] Next page

Go to full version