News:

As usual while waiting for the next release - don't forget to check the nightly builds in the forum.

Main Menu

how to properly set up a library?

Started by blueeyedlion, April 23, 2011, 12:59:27 AM

Previous topic - Next topic

blueeyedlion

I have 1 header and 1 library.  Where do I put the files, and what settings do I change?

This is c++ by the way.

ouch

well you put them wherever you want too...

but for the settings part it depends on what compiler your using.

stahta01

C Programmer working to learn more about C++.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. [url="http://wiki.codeblocks.org"]http://wiki.codeblocks.org[/url]

blueeyedlion

I already looked at that.  I found that these points:

-Add the required paths for compiler and linker.
-Pay attention to project settings and target settings.

needed a bit more explaining, so I came here.

ouch

and again... we need to know what compiler using to be able to help at all.

blueeyedlion

I'm using the gnu compiler,

and windows 7 if that makes a difference.

ouch

Ok, it's strait forward then.

Just go to project->build options

Then click on linker settings tab, then click add. Just type the name of the library without the extension.

Then click the search directories tab, click linker sub tab, then click add, then click the 3 dot button, (this button means browse...) and select the directory where your library is.

Then click the compiler sub tab, click add, click the 3 dot button, then select the directory where your header is.

And thats it, click OK.

be sure to call the the header from your code and enjoy your library. :)

You should also add the header to your project too (project->add files...) this allows code blocks to search through it for the good stuff. But it's not required. But seriously do it, default plugins need it, and are quite awesome. For instance it will scan that header and when you go type a function it will pop up and allow you to select the function you were going to type. To top it off it will tell you the number of arguments that function takes and the argument type that the function is expecting and even the return type if any.

blueeyedlion

Ok, I did that but now there's an error:

cannot find -lpdcurses

I'm trying to get pdcurses working by the way.

ouch

then on the search directories tab->linker sub tab part you didn't select the directory where that library is found.

blueeyedlion

After a bit of looking, I misnamed the library in the linker settings tab.  I did put in the path correctly.
Now I have a new error:

undefined reference to 'stdscr'

I'm using the simple "Hello World" sample code for pdcurses.

which way was closer to working?

ouch

your getting there.

undefined reference means it can't find your header file.

you either a: set your search directory wrong in the compile sub tab or b: you forgot to include the header in your hello world sample. (#include <stuff.h>)

blueeyedlion

I included the header in the source code:    #include <curses.h>
For the menus I did this:

project
  build options
     search directories
        compiler
           put in the directory of the header file (which is coincidentally the same directory as the library)

I did this the first time, an error resulted.  I redid it, same error.
Is there anything else I could try?
 

Jenna

Quote from: ouch on April 23, 2011, 07:14:38 AM
undefined reference means it can't find your header file.

That's wrong.
It means the header-file (with the declaration( is found (otherwise you get compiler errors.
But this is a linker error, that says, it does not find the stdscr in any of your linked libraries.

blueeyedlion

Do you have any idea of what I can do to fix it?

ouch

Yep jens right, it was late and I didn't catch that...

But it's not finding that function in the library.

check your spelling.

but it's probably more likely that the library you are using wasn't compiled with the gnu compiler (or compatible one). often people try to use static libraries written from microsoft's compilers with the gnu one and that doesn't work. Even less so if the library uses microsoft specific commands in the code. (and they almost always do)

You have to get a version of the library written with gnu in mind. best way to do that is to compile it yourself if possible.

where did you get this library?