Libraries, how do I use them?

New to FreeBASIC? Post your questions here.
MythGuyDK
Posts: 22
Joined: Sep 21, 2006 20:01

Libraries, how do I use them?

Postby MythGuyDK » Dec 15, 2006 16:17

I'm asking what I do to use libraries. Most specificly .a libraries. Any help is much appreciated.
Imortis
Moderator
Posts: 1744
Joined: Jun 02, 2005 15:10
Location: USA
Contact:

Postby Imortis » Dec 15, 2006 16:26

You can either use the .bi file that includes the .a file or you can include it manually, like so:

Code: Select all

#Inclib "somelib"


If you want to use a .bi file you do it like this:

Code: Select all

#include "some.bi"
integer
Posts: 393
Joined: Feb 01, 2007 16:54
Location: usa

library

Postby integer » Feb 13, 2007 0:41

question for IMORTIS

I have searched for information on libraries. What I seem to find is "make that subprogram a library and use it".
OK. That is just what I want to do.

How do I turn a .bas into a .bi ?

Could you point to some tutorials that might give some verbose explanations about how to generate a library?

After I create the module with several routines ( minisubs.bas ) do I merely rename it "minisubs.bi" and then call use the #INCLUDE directive or is there something else that needs to be done.

At this moment my program(s) uses the include directive for the subprograms that I need. What I would like to do ( and I believe a library is the way ) is compile my subprograms and merely link them each time I need to compile the main program.

As it is ALL of the routines in the minisubs.bas is recompiled every time I make a change to the main program. Most of the subprograms are fixed and rarely will need to be changed. The Main program is only a few hundred lines, but the subprograms are approaching several thousand lines.

I'm not asking something simple, such as integrating a polynomial (since any one who has gone to elementary school can do that), for me this is a very complicated complex intricate problem: module --> library

Some things are very easy and some easy things aren't.

Thanks for any help.
diffeecult
Posts: 84
Joined: Feb 03, 2007 2:37

Postby diffeecult » Feb 13, 2007 1:15

This is what the manual says about creating a library.

fbc -lib module1.bas module2.bas module3.bas -x libmylib.a
Will create the libmylib.a static library out of the passed module source files

diffeecult
stylin
Posts: 1253
Joined: Nov 06, 2005 5:19

Postby stylin » Feb 13, 2007 1:25

More information can be found here:
http://www.freebasic.net/wiki/wikka.php ... cLibraries
Imortis
Moderator
Posts: 1744
Joined: Jun 02, 2005 15:10
Location: USA
Contact:

Postby Imortis » Feb 13, 2007 14:47

How do I turn a .bas into a .bi ?


You don't really. A .bi simply contains all the declarations for your .bas. I'll make a small example:
ex.bas

Code: Select all

Sub test(a as integer)
   Print a
end sub


If that is your .bas, this would be the .bi:
ex.bi

Code: Select all

Declare Sub test(a as integer)


After I create the module with several routines ( minisubs.bas ) do I merely rename it "minisubs.bi" and then call use the #INCLUDE directive or is there something else that needs to be done.


In Order to make a true library (.a file) you will need to compile the code with the -lib option. You do this from the command line. Using the ex.bas file above, you would type this at the comand line:

Code: Select all

fbc -lib ex.bas


If you use FBEdit, it had the library complie option by default in it's make options.
To the end of your ex.bi file you would add this:

Code: Select all

#inclib "libex.a"


Also, the .a file made from you .bas needs to be put, either in the same folder as the code that will be using it, or in the lib folder in the compiler folder.

Then, in the code you are using the library in, you would put this at the top of the program:

Code: Select all

#include "ex.bi"


If you need more help, let us know.

Return to “Beginners”

Who is online

Users browsing this forum: No registered users and 7 guests