Hi Bernd Thanks for the information! I now wonder what i should do? I know i can do this from a script like method but i want the convenience of the script method and the convenience of forth but i also want the speed of compiled binarys or close to it. I also would like the benefit of code that can work on other platforms. I guess for now i will just try to figure out a best compromise method that will give me the most flexibility with the most speed. I will just have to think about this for sometime before i come up with a solution. Is the main reason this does not work yet because of some dependency Gforth has with some other library or is this an internal Gforth issue? Maybe i could try and solve this or is there some solution that you Bernd and others are already working on? I have done some testing to see the speed benefit of precompiled images and i find that there is up to 200 times speed benefit for some of my testing code. I know that seems like an amazing amount as 200 times is very noticeable. My original idea of having small parts of code run from the command line and piped to other parts of code would improve if it can all be precompiled images. But another way of structuring code i will need to devise to work around this issue then i guess! Thanks again for the answer! PKS
On Mon, Sep 2, 2013 at 2:24 PM, Bernd Paysan <[email protected]> wrote: > Am Montag, 2. September 2013, 14:10:46 schrieb Philip Smith: > > Hi fellow Gforthers > > I need to understand how to use a shared library in Gforth with a Gforth > > image! I Think this is possible because > > i can access a c shared library in gforth from the command line or from > > code that is accessed in gforth via the #! method as a script. > > I can not however access the c shared library from an image though. I > > think this is because i do not understand some part of gforthmi > > or perhaps gforth itself i am missing some part of the puzzle. The issue > > seems to be a linkage issue to the shared library but i present the > > steps i took to test this below. Note the "#####" indicates a file or > > screen capture. > > This is all done on a Raspberry pi running Debian Wheezy. I am using > > gforth version 0.7.2 but have also tried 0.7.0 with same results. > > I am just looking for some input if a c shared library can be assessed > in a > > gforth image or not and if so how is it done correctly! > > At the moment, this does not work, and we know that (i.e. a known bug); > this > is a valid feature request. > > > ##### someclib.c > > #include <stdio.h> > > > > int mytest(void) > > { > > printf("Hello world"); > > return 99 ; > > } > > ##### > > > > ##### someclib.h > > #include <stdio.h> > > > > int mytest(void); > > ##### > > > > Now i compile the c and make it a shared library as follows: > > > > ##### from the raspberry pi ssh session > > pi@raspberrypi ~/git/gforth_testing $ gcc -c -fPIC someclib.c -o > someclib.o > > pi@raspberrypi ~/git/gforth_testing $ ar rcs libsomeclib.a someclib.o > > pi@raspberrypi ~/git/gforth_testing $ gcc -shared > > -W1,-soname,libsomeclib.so.1 -o libsomeclib.so.1.0.1 someclib.o > > pi@raspberrypi ~/git/gforth_testing $ sudo cp libsomeclib.so.1.0.1 > /usr/lib/ > > pi@raspberrypi ~/git/gforth_testing $ sudo ln -sf > > /usr/lib/libsomeclib.so.1.0.1 /usr/lib/libsomeclib.so > > pi@raspberrypi ~/git/gforth_testing $ sudo ln -sf > > /usr/lib/libsomeclib.so.1.0.1 /usr/lib/libsomeclib.so.1 > > pi@raspberrypi ~/git/gforth_testing $ sudo ldconfig -n /usr/lib/ > > pi@raspberrypi ~/git/gforth_testing $ sudo cp someclib.h > > /usr/include/someclib.h > > ##### > > > > The library is now a shared library and the system sees it and i can link > > to it with other c code. > > Now i want to link to it with a wrapper function in gforth to allow usage > > of c library functions in gforth > > but ultimately i want the gforth as fast as it can be so i would like to > > make an image for gforth to use. > > I find this does not work! The steps are show below. > > > > ##### mywrapper.fs > > clear-libs > > c-library mybugtest > > s" someclib" add-lib > > > > \c #include "someclib.h" > > \c int thecfunction(void) { return (mytest()); } > > > > c-function forthword thecfunction -- n > > > > end-c-library > > ###### > > > > ###### mytest.fs > > include mywrapper.fs > > > > variable myvar > > > > 5 myvar ! > > > > : testword myvar @ . cr threading-method . cr version-string type cr > > > > forthword cr . cr ; > > > > :noname testword bye ; is bootmessage > > > > ###### > > > > Now if i use gforthmi as follows then run the code as shown below it > fails! > > > > ###### this is from the raspberry pi ssh session > > pi@raspberrypi ~/git/gforth_testing $ sudo gforthmi mytest mytest.fs > > data offset=-2AF20 > > code offset=-5CEF98 > > xt offset=-5CEFA8 > > 30 B69A7000 B697C000 > > 34 B69AC000 B6981000 > > 38 B69B1000 B6986000 > > 3C B69B6000 B698B000 > > 1CCC B69AB000 B6980000 > > 1CD0 B69B4C00 B6989C00 > > 1CD4 B69B0000 B6985000 > > 1CDC B69B4B98 B6989B98 > > 1CE0 B69B4B94 B6989B94 > > 1CEC 1099128 ACA128 > > 2D40 B6F1A5E0 B6EEF5E0 > > 2D60 B6F1A680 B6EEF680 > > 970C BED8B5D8 BED475D8 > > 9748 BED8B80C BED4780C > > 9F88 10885A8 AB95A8 > > B1AC 10999E0 ACA9E0 > > 10460 1090490 AC1490 > > 104C0 1088A00 AB9A00 > > 16D20 1090A20 AC1A20 > > 19048 1090B90 AC1B90 > > 22304 1082166 AB3166 > > 22358 1098D18 AC9D18 > > 227B0 1099330 ACA330 > > 28800 10992F8 ACA2F8 > > pi@raspberrypi ~/git/gforth_testing $ sudo gforth -i mytest > > 5 > > 0 > > 0.7.2 > > > > :0: Invalid memory address > > > > Backtrace: > > $B69EA770 lib-sym > > $B69EA8C0 link-wrapper-function > > $B69EE978 forthword > > $B69EE9A8 testword > > ######## > > > > But if i simply do the following from command line the code with the > shared > > library works! > > Why does this work when it is compiled into the standard gforth image but > > not precompiled as an image? > > I know from testing that i can use my own images made with gforthmi but i > > can not seem to have access to anything other then gforth code > > in those images. How then can i have access to shared c library and yet > > get the performance of an precompiled image in gforth at the same time? > > > > ######## this is from the raspberry pi ssh session > > pi@raspberrypi ~/git/gforth_testing $ sudo gforth mytest.fs > > 5 > > 0 > > 0.7.2 > > Hello world > > 99 > > > > pi@raspberrypi ~/git/gforth_testing $ > > > > ######## > > > > Any help would be appreciated! PKS > -- > Bernd Paysan > "If you want it done right, you have to do it yourself" > http://bernd-paysan.de/ > -- \|||/ -----0oo---( o o )---oo0------ (_) >From the hand of PKS
