static/dynamic libraries

BlitzMax Forums/BlitzMax Programming/static/dynamic libraries

Zenith(Posted 2004) [#1]
Is it possible to import static/dynamic libraries, (when all you get are headers with it)?

Ie:

Import "MYLIB.a" (or .lib) (or .dll!)
or
Import "-l MYLIB" (if its in the lib folder)

While I'm asking, Mark, any chance that you will someday work on an inteligent linker that only links modules that are used?


Drago(Posted 2004) [#2]
I was just about to ask a question about the lib folder if it was posible to add our own libs.

btw if anyone wants to kbow .libs made with MSVS are the same format as .a files for GCC.


skidracer(Posted 2004) [#3]
btw if anyone wants to kbow .libs made with MSVS are the same format as .a files for GCC.


If only that were true.

As for only linking modules that were used this is currently possible albeit manually using the Framework command, see the firepaint sample for an example.


TommyBear(Posted 2004) [#4]
Yes I would like to know too actually.


Zenith(Posted 2004) [#5]
Also, what is the basis of getting a module into place, I have source code of a library -- I figure basically I just need to get everything the main header file is doing into a module.bmx? :)

http://enet.cubik.org/
(Quick and dirty UDP Connection'ed with optional reliable/in order packets)


JaviCervera(Posted 2004) [#6]
btw if anyone wants to kbow .libs made with MSVS are the same format as .a files for GCC.
I am not 100% sure, but AFAIK, only C VC++ .lib files are compatible with GCC linker. VC++ does some dirty things to C++ .lib files, and they do not work with GCC. At least thats what was said in the times of Visual Studio 6. There have been many changes in VC++7 and 8, maybe now they are compatible, but let me doubt it.


skidracer(Posted 2004) [#7]
1. create a myname.mod/mymod.mod folder in your blitzmax/mod folder

2. copy your c source and headers into that folder retaining their folder structure

3. create a mymod.bmx file in the mymod.mod folder and add the following:
Module myname.mymod

Strict

Import "mycfile1.c"
Import "mycfile2.c"

4. Makemods and make sure GCC can build the C files OK, the path to myname.mod/mymod.mod is added to the include path so any #include <file.h>'s can be found, if you get this far, cool, thats the traditional makefile script side of things done.

5. Add an Extern block to your mymod.bmx, and place any functions you want to call from BlitzMax here, start with one, and if the functions are defined in C++ make sure they are declared in an Extern "C" {} block in the header file.

If you get stuck you may want to study the modules in pub to see how we do things.


Zenith(Posted 2004) [#8]
Ok thanks! I just about went this far!

Getting to work..


Zenith(Posted 2004) [#9]
I figured I better not post a new thread, so I'll ask more here. (Sorry!)
I can't figure out a good way to implement C structures that need to be used in order to return/push some functions.

Now I guess I could do it with a bank like we used to, but I think we're beyond that stage. :)

These are important C structures that must be created in order to create a host etc.

http://enet.cubik.org/Tutorial.html

Examples there. (Look at the Creating an ENet Server or Client)
For instance the ENetAddress structure, I ended up having to write a blitz type for it, but for ENetHost, it's not as easy, it's full of other object types and such within it.

Any chance of something like this:
Import "enet/enet.h"
Extern
type ENetAddress
type ENetHost
end extern

And so forth? Any ideas? That would be a ton of work in my oppinion, and I understand if it won't be included at this time (please consider it!). But could it be possible? I see that as the only way to really get alot of C libraries to work.. :)

Oh, and sorry if this has been discussed before -- which I hope it has. ;)


{cYan|de}(Posted 2004) [#10]
i agree:P


Drago(Posted 2004) [#11]
yeah, being able to use Structures from C would be good.


Perturbatio(Posted 2004) [#12]
It does look like a nice idea to me.


N(Posted 2004) [#13]
OK, after Zenith continually pestering me to reply and state my opinion on this subject, and after reading the entire thread, I do think this is actually a good idea. Being able to import C/C++ classes and structures is crucial to having a sort of plug-and-play development environment.

Seeing as how BlitzMax is still in the works, I'll give Blitz Research their time to work on it, but I would like to see this in at some point in time.


Zenith(Posted 2004) [#14]
It wasn't THAT constant. <_< >_>

And uhh, an enum of sorts (or a constant array, lol!) would be cool ;)


TommyBear(Posted 2004) [#15]
@skidracer

That only works if you actually have the files. Zenith's original question was more interesting. Can BMX import libraries to link against?


yeah, being able to use Structures from C would be good.



In some cases you'll need to write a support c file which implements functions that use these structures and extern them to BMX. I did this for the zip/unzip functionality tweaks to the ZLib library.


Zenith(Posted 2004) [#16]
I didn't think of that, nice!

Notice there is a lib folder, which is exactly like GCC/MINGW's. If you look into the opengl bmx code, you'll see that they use:
Import "-lopengl32" 
Also notice there inside the lib folder, it's named "libopengl32.a"
If I can remember correctly this is exactly how I used to do it in GCC. So when I was working on the enet code, it needs the 32-bit version of the winsock2 lib. I did infact add the lib, Blitzmax doesn't have it in its lib folder.(which was libws2_32.a) -- which I got from MinGW's lib folder. (But if you think about it, I probally wouldn't need to copy this to Blitzmax's lib folder, considering MinGW probally uses it's lib folder also.)

So yeah, it does include it. :)
But I guess it's just adding it to the command line, like other import's

Import "-l ws2_32"
Is how I put it

So yes it is possible to include libs, -- but it used them in the C code, and I didn't try anything from within blitz. :)


skn3(Posted 2004) [#17]
Would be sensible if structs could be imported, Id like to see this happen :)

Also an automated module check, so we dont have to hassle with which modules are used.


Zenith(Posted 2004) [#18]
Ya know, all I really need is to be able to take a header file, send it through gcc, and get it to spit out parsed structures and such that it found. Haha, then I could write a converter that converts them to types. I wonder if GCC has an arg for it.. Looking anyway. :)


TommyBear(Posted 2004) [#19]

So yeah, it does include it. :)
But I guess it's just adding it to the command line, like other import's



nice!


Drago(Posted 2004) [#20]
you also might want to look at the reimp command that comes with minGW, it lets you ,sometimes, make VS .libs to compatable .a files.