coffIT - create obj and lib static libraries from PB source!

Applications, Games, Tools, User libs and useful stuff coded in PureBasic
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

coffIT - create obj and lib static libraries from PB source!

Post by srod »

I may look like a mule, but I'm not a complete ass.
Dare
Addict
Addict
Posts: 1965
Joined: Mon May 29, 2006 1:01 am
Location: Outback

Post by Dare »

Not a bug report, just a query! Copied exacto from other forum and I'm just after what is safe. Eg, some things like Import, Interface, Psuedotypes. Esp Import would need care if available.
srod wrote:The help manual examines these problems quite thoroughly.
I have been through the manual a few times (fortunately it is easy to read and small) but I still need to request some clarification. Sorry!
srod wrote:Of course the first question is whether static libs created with PB can be used in other languages? The answer is yes, providing that your library does not use any commands which reside within any of PB's user libraries!
I assume this means all variables, types and operators and the following (I assume again) non-library commands:

Code: Select all

Break : Continue
Define
Dim : ReDim
End
Enumeration : EndEnumeration
For : Next
ForEach : Next
Global
Gosub : Return
Goto
If : Else : ElseIf : EndIf
Import : EndImport
Interface : EndInterface
Macro : EndMacro
NewList
Procedure : EndProcedure
Protected
Prototype
Pseudotype
Repeat : Until
Select : EndSelect
Shared
Static 
Structure : EndStructure
Swap
While : Wend
With : EndWith 
Would that be a complete list or have I missed something (or included something I shouldn't)?

Just making sure before I do something stupid and wonder what happened.

Have only played with the examples but this looks really exciting. Great job mate!
Dare2 cut down to size
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Sorry, horrendous bug found!!!

Back in a mo... :)
I may look like a mule, but I'm not a complete ass.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Particularly clumsy bug fixed. :) New version uploaded.

@Dare, all of the commands you've listed look fine to me. The proof of the pudding though is in the eating! Some things you just have to try and see what happens.

As for using the Import keyword in a .obj / .lib - that is fine; I've already tested this and it seems to work fine.

In fact rather than me arsing around, let me add an example of this right now!

Back in a mo... :)
I may look like a mule, but I'm not a complete ass.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

@Dare, I've added the following example to the coffIT download :

Code: Select all

;coffIT demo program.
;By Stephen Rodriguez.

;Import an external lib.

Import "User32.lib"
  MsgBox(Window.l, Body$, Title$, Flags.l) As "_MessageBoxA@16"
EndImport

ProcedureDLL CallImport(hWnd, text$)
  MsgBox(hWnd, text$, "Hello from coffIT!", 0)
EndProcedure 
Run this through coffIT to create a .obj file.

Now when using the resulting 'ImportExternalLib.obj' in an application you must simply ensure that user32.lib is added to the application at the linking stage. In the case of building a PB application, if you use the coffIT generated import wrapper, then the wrapper will ensure that user32.lib is indeed added at the link stage. (It does this by simply adding an empty Import / EndImport for the 'user32.lib' import library)

Simple! :)


**EDIT : coffIT ignores macros (except the one used to export variables). Use macros by all means in your source, but avoid using a macro to mask a Procedure definition or a global variable definition etc.
I may look like a mule, but I'm not a complete ass.
milan1612
Addict
Addict
Posts: 894
Joined: Thu Apr 05, 2007 12:15 am
Location: Nuremberg, Germany
Contact:

Post by milan1612 »

Great work srod :!:
When can we expect the second version (*.lib output)?

And btw. does the name refer to the COFF format or
your immense COFFee consum during the creation? :twisted:
Windows 7 & PureBasic 4.4
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

milan1612 wrote:Great work srod :!:
When can we expect the second version (*.lib output)?

And btw. does the name refer to the COFF format or
your immense COFFee consum during the creation? :twisted:
After I've had some sleep! :wink:

I've got some other work to do at the moment - a few days worth, this will give coffIT's existing bugs time to show themselves etc.

Once version 1 has been demonstrated as being relatively stable then I will complete version 2, which adds .lib support. The truth is that the majority of the code is already in place for this. It's a case of reorganising and adding a little more logic in places.
I may look like a mule, but I'm not a complete ass.
Dare
Addict
Addict
Posts: 1965
Joined: Mon May 29, 2006 1:01 am
Location: Outback

Post by Dare »

Hi Mate,

Thanks for the answers. Don't overdo the working. Or only if it means $$$.

:)
Dare2 cut down to size
Pureabc
User
User
Posts: 76
Joined: Mon Jan 16, 2006 1:11 am

Post by Pureabc »

Excellent!

Thanks Srod.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

You're welcome Pureabc. :)


@Milan : there is nothing stopping you using coffIT to create .libs right now (before version 2 is released).

All you need to do is split your source into individual source files, -say one for each function.

Run each function/file through coffIT and then use POLIB on all the resulting .obj files to create a .lib.

The only thing is that you will need to export all data (e.g. variables) which needs to be shared amongst the functions etc. and also export all 'internal' functions so that they are accessible throughout the library.
I may look like a mule, but I'm not a complete ass.
BriceManuel
Enthusiast
Enthusiast
Posts: 195
Joined: Thu Nov 29, 2007 8:23 am

Post by BriceManuel »

I have to say my concern is the same as Dare's. I had to buy another language to make DLLs since I can't use PB's DLLs in anything else but PB. I am not sure how a lib will circumvent this as any DLL or lib written using PB will naturally be making use of PBs commands, wouldn't it?
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Static libs are not intended to replace dll's Brice because, as you know, dll's have already passed through the linking stage and so using PB functions in a dll is not a problem.

.libs (if you intend using them in other languages) should stick to the basic command set + Win api. You would of course build up a library of routines this way until you had a rich base of functions etc.

Of course, with c static libs, things are made somewhat easier by the runtime library; which is always an option in PB. There's no reason why static libs created with PB cannot make use of the c runtime etc. I certainly intend to.

On an aside, I must admit that I've had no problems using PB created dll's with other languages. Is there any particular language you've had problems with when attempting to use PB created dll's?

On another aside, can you check your pm's please Brice? :)
I may look like a mule, but I'm not a complete ass.
BriceManuel
Enthusiast
Enthusiast
Posts: 195
Joined: Thu Nov 29, 2007 8:23 am

Post by BriceManuel »

Seriously and honestly, I am still confused, but its certainly not the first time :lol:
milan1612
Addict
Addict
Posts: 894
Joined: Thu Apr 05, 2007 12:15 am
Location: Nuremberg, Germany
Contact:

Post by milan1612 »

srod wrote:@Milan : there is nothing stopping you using coffIT to create .libs right now (before version 2 is released).

All you need to do is split your source into individual source files, -say one for each function.

Run each function/file through coffIT and then use POLIB on all the resulting .obj files to create a .lib.

The only thing is that you will need to export all data (e.g. variables) which needs to be shared amongst the functions etc. and also export all 'internal' functions so that they are accessible throughout the library.
Didn't know that, I'm gonna give it a try...
Thanks for the hint :)
Windows 7 & PureBasic 4.4
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

I'll knock up a quick example for you.
I may look like a mule, but I'm not a complete ass.
Post Reply