Page 1 of 1

Return value from a linux library (libg2.so)

Posted: Thu Aug 09, 2007 4:41 pm
by vekem
Hello,

I tried (again) with PB 4.01 (Linux) using the library libg2 (G2, writing for example direct postscript files). But with the open-function (here "g2_open_PS") I get no return-value, it's always "0".

deviceG2.l = CallCFunction(hlibg2, #g2_open_PS, OutFile$, #g2_A4, #g2_PS_port)

deviceG2 should be a device-value, but is 0.Outfile$ is written! No other operations possible, because ther deviceID is needed.

Maybe it is the way calling the routines, but the most tries with external libraries, I've trouble... ;-)

Look here:

; ------------------------------------------------------------------
; Small test using this fin eg2- Library from (libg2, libg2-dev)
; http://g2.sourceforge.net/
; libg2.so
;
;XIncludeFile "/home/mv/mvData/EigeneDateien/develop/purebasic/linux/include/g2/g2_ps.inc"
;something aut of "g2_inc"...

#g2_open_PS = "g2_open_PS"
#g2_close = "g2_close"
#g2_line = "g2_line"
#g2_rectangle = "g2_rectangle"
#g2_string = "g2_string"

#g2_A4 = 4
#g2_PS_port = 1

Global hlibg2.l, OutFile$

OutFile$ = "gs_print.ps"

Procedure g2_Init()
Shared hlibg2
hlibg2 = OpenLibrary(#PB_Any, "libg2.so")
EndProcedure

Procedure g2_Quit()
Shared hlibg2
CloseLibrary(hlibg2)
hlibg2 = 0
EndProcedure

g2_Init()
deviceG2.l = CallCFunction(hlibg2, #g2_open_PS, OutFile$, #g2_A4, #g2_PS_port)

; =>>> deviceID doesn't get a value (on C it is declared as "int"-type)
; function is successfull!

CallCFunction(hlibg2, #g2_line, deviceG2, 10.0, 10.0, 90.0, 200.0)
CallCFunction(hlibg2, #g2_string, deviceG2, 20.0, 20.0, "This is a test g2-PureBasic!")
CallCFunction(hlibg2, #g2_close, deviceG2)

g2_Quit()
;MessageRequester("Fertig!","Programm beendet!")
MessageRequester("Ready!","Program terminated!")
End
;-------------------------------------------------------------------------

Posted: Fri Aug 10, 2007 1:50 pm
by walker
well... you don't check if hlibg2 is <> 0. is the openlibrary successful?

why defining hlibg2 as global and then as shared in the proc? this is not necessary... (global is enough...)

Posted: Wed Sep 19, 2007 3:49 pm
by vekem
Hello "walker",

sorry for answering so late. loading hlibg2 is successful, and it work's, because the first deviceG2 as a return value is "0" (next one is "1"...).

Damned... but no function for font-changing (or encoding for e.g. european characters), so this is no alternative way for Purebasic-printing under Linux.

Regards,
Markus

Posted: Wed Sep 19, 2007 3:52 pm
by vekem
both location are in "germany", talking english, hmmm... :wink:

Markus

Posted: Tue Oct 09, 2007 1:24 am
by walker
...this is the english forum.... :wink:

sorry for answering so late...i'd moved and had no internet access for a while....

I'd tried the lib and compiled it as described... the function is available but returns always zero.... maybe this is an issue with the shared lib of hlibg2..... :roll:

I was having that problem

Posted: Wed Nov 07, 2007 4:03 pm
by John Duchek
Where you just get a 0 when opening a .so file. You can check the chatter back and forth on it (thread is under a request in my name --john duchek). I had given up and came back a few months later to find someone had left the correct answer(unfortunately I cannot remember his name right now).

he suggested I load "./filename" rather than "filename". It worked like a charm but I have no idea why. I understand that in Linux that tells it to use the current directory, but some of my .so files load without that (I guess they are in the path from somewhere else somehow.)
Anyway I can now list the libary, but still haven't figured out how to call and use the functions correctly.

John

Posted: Wed Nov 07, 2007 4:49 pm
by bembulak
It's a path issue.
I guess PB first looks in the PATH, this is the reason, why "filename" fails and "./filename" works.
Had this problem several times now. It's a strange behavior, because on some distros it works without "./" and on some others you always need it.
E.g.: Suse <> Ubuntu (I think it was something like this, but I'm not sure anymore)

Posted: Wed Nov 07, 2007 5:02 pm
by Thalius
I have tested Libs on Ubuntu & OpenSuSe.

Having libs in:

Code: Select all

/usr/lib/
works.

Code: Select all

./libname.so
seeks the lib in the current directory.

Thalius