Qbasicnews.com
Porting a lib? - Printable Version

+- Qbasicnews.com (http://qbasicnews.com/newforum)
+-- Forum: Qbasic "like" compilers/interpreters (http://qbasicnews.com/newforum/forum-5.html)
+--- Forum: FB Discussion & Programming Help (http://qbasicnews.com/newforum/forum-15.html)
+--- Thread: Porting a lib? (/thread-8761.html)



Porting a lib? - Torahteen - 01-17-2006

If I wanted to port the FANN Library to FB, what would be the steps that I would take?


Porting a lib? - L_O_J - 01-17-2006

well I never port libs before but, here is a way that I might think of :

1. the hard way, rewrite all the lib source to FB ( total port ) :p, and then recompile in FB (you dont want to do this tho Big Grin)

2. just take the library file in MingW / GCC format (".a") and then translate the header to FB format. thats it.

hope it helps


Porting a lib? - na_th_an - 01-17-2006

I think someone created a sort of automatic header translator, am I right? Then basicly you obtain the .a file (compiling the C source in mingw32, for example), translate the headers into .bi files and do some manual editing/double checks.


Porting a lib? - Antoni Gual - 01-17-2006

Yes, v1ctor created a SWIG script to translate .h to .bi, you can have the package here http://www.freebasic.net/temp/swig_fb.zip


Porting a lib? - Torahteen - 01-17-2006

Ok, so how do I use that program for one. Two, so all I need is the .a file? Wether that be in C or not?


Porting a lib? - Torahteen - 01-18-2006

I need to compile the library, but I have no clue how. Could somebody walk me through the steps in Dev-C++ or MSVC.NET?


Porting a lib? - d.j.peters - 01-18-2006

The lib is in C for C++ or dotnet you need only the language bindings.

Why you will build the lib new?

Joshy


Porting a lib? - Torahteen - 01-18-2006

For MSVC, the library has a project for you to compile, which should automatically make the new library file. However, it creates error upon error when it does this. I don't know what to do.


Porting a lib? - d.j.peters - 01-18-2006

Sorry about my bad english i don't know what you try.
You don't need to compile the whole lib.
If you will use the lib in FreeBASIC you must declare the functions.
This is the FreeBASIC code from "simple_test.c" in the example folder.
I have test it and it works.
(it must be in the same folder as "xor_float.net")

Joshy
Code:
type fann as any ptr
type fann_type as single

declare function fann_create_from_file lib "fann" alias "fann_create_from_file" (byval configuration_file as string) as fann
declare sub      fann_destroy          lib "fann" alias "fann_destroy"          (byval ann as fann)
declare function fann_run              lib "fann" alias "fann_run"              (byval ann as fann,byval f_input as fann_type ptr) as fann_type ptr
#inclib "fann"

dim as fann_type ptr calc_out
dim as fann_type f_input(2)
dim as fann ann
ann = fann_create_from_file("xor_float.net")

f_input(0) = -1
f_input(1) = 1
calc_out = fann_run(ann, @f_input(0))

print "xor test ", f_input(0), f_input(1) , calc_out[0]

fann_destroy ann
sleep
The c version.
Code:
#include <stdio.h>
#include "floatfann.h"

int main()
{
    fann_type *calc_out;
    fann_type input[2];

    struct fann *ann = fann_create_from_file("xor_float.net");

    input[0] = -1;
    input[1] = 1;
    calc_out = fann_run(ann, input);

    printf("xor test (%f,%f) -> %f\n", input[0], input[1], calc_out[0]);

    fann_destroy(ann);
    return 0;
}



Porting a lib? - d.j.peters - 01-29-2006

run's your first "neuronal" network now?

Joshy