Return value from a linux library (libg2.so)

Linux specific forum
vekem
User
User
Posts: 12
Joined: Tue Jun 17, 2003 7:37 am
Location: Germany

Return value from a linux library (libg2.so)

Post 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
;-------------------------------------------------------------------------
walker
Enthusiast
Enthusiast
Posts: 634
Joined: Wed May 05, 2004 4:04 pm
Location: Germany

Post 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...)
vekem
User
User
Posts: 12
Joined: Tue Jun 17, 2003 7:37 am
Location: Germany

Post 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
vekem
User
User
Posts: 12
Joined: Tue Jun 17, 2003 7:37 am
Location: Germany

Post by vekem »

both location are in "germany", talking english, hmmm... :wink:

Markus
walker
Enthusiast
Enthusiast
Posts: 634
Joined: Wed May 05, 2004 4:04 pm
Location: Germany

Post 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:
John Duchek
User
User
Posts: 83
Joined: Mon May 16, 2005 4:19 pm
Location: St. Louis, MO

I was having that problem

Post 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
John R. Duchek
St. Louis,MO
User avatar
bembulak
Enthusiast
Enthusiast
Posts: 575
Joined: Mon Mar 06, 2006 3:53 pm
Location: Austria

Post 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)
cheers,

bembulak
Thalius
Enthusiast
Enthusiast
Posts: 711
Joined: Thu Jul 17, 2003 4:15 pm
Contact:

Post 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
"In 3D there is never enough Time to do Things right,
but there's always enough Time to make them *look* right."
"psssst! i steal signatures... don't tell anyone! ;)"
Post Reply