Author Topic: how to properly set up a library?  (Read 9888 times)

Offline blueeyedlion

  • Multiple posting newcomer
  • *
  • Posts: 13
how to properly set up a library?
« on: April 23, 2011, 12:59:27 am »
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.

Offline ouch

  • Almost regular
  • **
  • Posts: 223
Re: how to properly set up a library?
« Reply #1 on: April 23, 2011, 01:07:24 am »
well you put them wherever you want too...

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

Offline stahta01

  • Lives here!
  • ****
  • Posts: 6636
    • My Best Post
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline blueeyedlion

  • Multiple posting newcomer
  • *
  • Posts: 13
Re: how to properly set up a library?
« Reply #3 on: April 23, 2011, 02:24:15 am »
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.

Offline ouch

  • Almost regular
  • **
  • Posts: 223
Re: how to properly set up a library?
« Reply #4 on: April 23, 2011, 02:44:32 am »
and again... we need to know what compiler using to be able to help at all.

Offline blueeyedlion

  • Multiple posting newcomer
  • *
  • Posts: 13
Re: how to properly set up a library?
« Reply #5 on: April 23, 2011, 03:22:23 am »
I'm using the gnu compiler,

and windows 7 if that makes a difference.

Offline ouch

  • Almost regular
  • **
  • Posts: 223
Re: how to properly set up a library?
« Reply #6 on: April 23, 2011, 05:14:58 am »
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.

Offline blueeyedlion

  • Multiple posting newcomer
  • *
  • Posts: 13
Re: how to properly set up a library?
« Reply #7 on: April 23, 2011, 05:28:44 am »
Ok, I did that but now there's an error:

cannot find -lpdcurses

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

Offline ouch

  • Almost regular
  • **
  • Posts: 223
Re: how to properly set up a library?
« Reply #8 on: April 23, 2011, 06:02:58 am »
then on the search directories tab->linker sub tab part you didn't select the directory where that library is found.

Offline blueeyedlion

  • Multiple posting newcomer
  • *
  • Posts: 13
Re: how to properly set up a library?
« Reply #9 on: April 23, 2011, 06:24:58 am »
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?

Offline ouch

  • Almost regular
  • **
  • Posts: 223
Re: how to properly set up a library?
« Reply #10 on: April 23, 2011, 07:14:38 am »
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>)

Offline blueeyedlion

  • Multiple posting newcomer
  • *
  • Posts: 13
Re: how to properly set up a library?
« Reply #11 on: April 23, 2011, 08:33:27 am »
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?
  

Offline jens

  • Administrator
  • Lives here!
  • *****
  • Posts: 7265
    • Jens' unofficial debian-repository for the Code::Blocks - IDE
Re: how to properly set up a library?
« Reply #12 on: April 23, 2011, 10:29:40 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.

Offline blueeyedlion

  • Multiple posting newcomer
  • *
  • Posts: 13
Re: how to properly set up a library?
« Reply #13 on: April 23, 2011, 10:40:29 am »
Do you have any idea of what I can do to fix it?

Offline ouch

  • Almost regular
  • **
  • Posts: 223
Re: how to properly set up a library?
« Reply #14 on: April 23, 2011, 09:27:07 pm »
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?

Offline blueeyedlion

  • Multiple posting newcomer
  • *
  • Posts: 13
Re: how to properly set up a library?
« Reply #15 on: April 24, 2011, 12:27:15 am »
This is where I got it:

pdcurses.sourceforge.net

Offline blueeyedlion

  • Multiple posting newcomer
  • *
  • Posts: 13
Re: how to properly set up a library?
« Reply #16 on: April 25, 2011, 08:26:12 pm »
Is there anything at all that I could try?

Someone must have had this problem before.

Offline ouch

  • Almost regular
  • **
  • Posts: 223
Re: how to properly set up a library?
« Reply #17 on: April 25, 2011, 09:55:07 pm »
I checked the precompiled library files, and it doesn't look like there are any for gcc or mingw. (all the dll's come .lib files, gcc/mingw dll's usually come with .a files)

If so you will have to build one yourself.

this file seems to be the source:

http://sourceforge.net/projects/pdcurses/files/pdcurses/3.4/pdcurs34.zip/download

But i would just download the trunk from the svn repository for the latest source code.

but the directions to build it are in the win32 folder called README.

if you have troubles with that go to their forums and post a message. Once done, replace the library you have now with the new one you just made.

Note: With this library I would probably statically link it instead of dynamically anyway.

Offline blueeyedlion

  • Multiple posting newcomer
  • *
  • Posts: 13
Re: how to properly set up a library?
« Reply #18 on: April 25, 2011, 10:45:10 pm »
After looking into this a bit, it seems horribly complicated.  Is there some easier way to get pdcurses working?  Maybe switching compilers or something?  If there isn't an easier way, perhaps there is a step by step guide out there that someone could point me to?

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 12001
    • Travis build status
Re: how to properly set up a library?
« Reply #19 on: April 25, 2011, 11:17:11 pm »
I think gcc/mingw can use .lib directly (probably try -lmylib.lib), if it can there is a way to convert .lib to .a.
Search the net for the details, because I don't remember how it has to be done (I've done it long time ago for the opengl libs).
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline ouch

  • Almost regular
  • **
  • Posts: 223
Re: how to properly set up a library?
« Reply #20 on: April 25, 2011, 11:18:47 pm »
You could just forget making a library, and just add the source and header files associated with the functions you want directly into your project.

just right click on your project and add files, or add files recursively if you want to add a bunch. then compile your project.

Offline blueeyedlion

  • Multiple posting newcomer
  • *
  • Posts: 13
Re: how to properly set up a library?
« Reply #21 on: April 26, 2011, 12:33:17 am »
"(probably try -lmylib.lib)"

Try this how?

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 12001
    • Travis build status
Re: how to properly set up a library?
« Reply #22 on: April 26, 2011, 12:49:14 am »
Read this: http://wiki.codeblocks.org/index.php?title=FAQ#Q:_How_do_I_troubleshoot_an_compiler_problem.3F (and enable the full log)

-lmylib.lib is added in two places:
1. linker settings -> link libraries (don't use -l)
2. linker settings -> other linker options (this is not recommended)
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline blueeyedlion

  • Multiple posting newcomer
  • *
  • Posts: 13
Re: how to properly set up a library?
« Reply #23 on: April 26, 2011, 01:05:27 am »
oh.  method 1 was described in one of the earlier posts.  I did it and it still wouldn't work.

Offline blueeyedlion

  • Multiple posting newcomer
  • *
  • Posts: 13
Re: how to properly set up a library?
« Reply #24 on: April 26, 2011, 05:39:44 am »
Is there any different compiler that would make using pdcurses easier?

Also I would like to remind you that I am using windows 7.

Offline stahta01

  • Lives here!
  • ****
  • Posts: 6636
    • My Best Post
Re: how to properly set up a library?
« Reply #25 on: April 26, 2011, 06:12:22 am »
MinGW GCC can link directly to C DLLs. I am guessing this is a C DLL based on the header file I downloaded.

Try using the "pdcurses.dll" as the library name.

Tim S.
« Last Edit: April 26, 2011, 06:38:04 am by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline stahta01

  • Lives here!
  • ****
  • Posts: 6636
    • My Best Post
Re: how to properly set up a library?
« Reply #26 on: April 26, 2011, 06:13:25 am »
Is there any different compiler that would make using pdcurses easier?

Also I would like to remind you that I am using windows 7.

The same one the pdcurses project used to compile the library for windows would be easier.

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