Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2014-06

Calling fpc libraries from other languages on freebsd/amd64 (bis)

12 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

fredvs

Hello.

I want to test some fpc libraries with freeBSD.

The compilation is ok but the library fail to run...

There was exactly the same problem in a earlier topic :

=> http://lists.freepascal.org/pipermail/fpc-devel/2013-November/032950.html

Is it solved in trunk fpc version ?
Have try with FPC 2.6.4 but without luck...

Thanks.

Fred

-----
Many thanks ;-)

Reply by email

fredvs
to fredvs

Ooops, i forget to note something...

My goal was to expose some pascal library to Java, of course those fpc libraries follow the "Java-native-library-way".

Those libraries loaded by a Java application work with Linux (tested on Mint 32/64) but fail to work with freeBSD...

Thanks.

Fred.

-----
Many thanks ;-)

Reply by email

fredvs
to Reinier Olislagers
> Is it solved in trunk fpc version ? Why don't you try?

I have install a brand new trunk version of fpc 2.7.1 64 bit on freeBSD 10 64 bit.

The library was successfully compiled.

But, sadly, i get hat error message while trying to run a java application
who use the library (that java application works in linux) :=>

~/fpGUIlib/demos/demo_Java% java -Djava.library.path=./ fpg_demo

Exception in thread "main" java.lang.UnsatisfiedLinkError: /usr/home/fred/fpGUIlib/demos/demo_Java/libfpgui.so: /usr/home/fred/fpGUIlib/demos/demo_Java/libfpgui.so: Undefined symbol "operatingsystem_parameter_envp"
at java.lang.ClassLoader$NativeLibrary.load(Native Method) at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1929) at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1847) at java.lang.Runtime.loadLibrary0(Runtime.java:870) at java.lang.System.loadLibrary(System.java:1119)
at fpg_demo.main(fpg_demo.java:148)

;-(

So, fpc 2.7.1 does not do the trick...

What can i do ?

Thanks

-----
Many thanks ;-)

Reply by email

Marco van de Voort
to fredvs: I have install a brand new trunk version of fpc 2.7.1 64 bit on freeBSD 10 64 bit. The…

In our previous episode, fredvs said:

Show quoted text 8 lines
/usr/home/fred/fpGUIlib/demos/demo_Java/libfpgui.so: /usr/home/fred/fpGUIlib/demos/demo_Java/libfpgui.so: Undefined symbol "operatingsystem_parameter_envp" ;-( So, fpc 2.7.1 does not do the trick... What can i do ?

First test it with a normal FPC program. That symbol is weak, maybe the java loader can't handle that.

Reply by email

fredvs
to Reinier Olislagers: Start providing source code so people can follow what you are trying to do instead of…
> Start providing source code so people can follow what you are trying to > do instead of having to guess would be a nice step ;)

First, fpGUI must be installed =>

Then. go there =>

- Click on "Download Zip". (middle/end of page) and unzip it.

- In /fpGUIlib/src/ change in extrafpc.cfg the directory of fpGUI according yours. (maybe read ReadMe.txt, it is explained).

- And finally compile the library In /fpGuilib/src/ =>

$ fpc @extrafpc.cfg fpgui.pas

Thats all for compilation.

___________________________________

Now test the library:

Copy the new compiled library /src/libfpgui.so into

~/fpGUIlib/demos/demo_Java

Then run the java demo with:
-In terminal do:

-> cd ~/fpGUIlib/demos/demo_Java (go in java demo path)

-> java -Djava.library.path=. fpg_demo

When i try to run it on freeBSD, i get error messages...

Many thanks to help.

Fred
-
PS: If you try the same things with Linux, it should work. (for me it works).

-----
Many thanks ;-)

Reply by email

fredvs
to fredvs

Ooops, in last topic, branch freebsd-fixes must be selected... Here re-explaination from sctatch =>

> Start providing source code so people can follow what you are trying to > do instead of having to guess would be a nice step ;)

First, fpGUI must be installed =>

Then. go there =>

Select branch: => freebsd-fixes

- Click on "Download Zip". (middle/end of page) and unzip it.

- In /fpGUIlib/src/ change in extrafpc.cfg the directory of fpGUI according yours. (maybe read ReadMe.txt, it is explained).

- And finally compile the library In /fpGuilib/src/ =>

$ fpc @extrafpc.cfg fpgui.pas

Thats all for compilation.

___________________________________

Now test the library:

Copy the new compiled library /src/libfpgui.so into

~/fpGUIlib/demos/demo_Java

Then run the java demo with:
-In terminal do:

-> cd ~/fpGUIlib/demos/demo_Java (go in java demo path)

-> java -Djava.library.path=. fpg_demo

When i try to run it on freeBSD, i get error messages...

Many thanks to help.

Fred
-
PS: If you try the same things with Linux, it should work. (for me it works).

-----
Many thanks ;-)

Reply by email

fredvs
to fredvs

Yes, it is still me...

You may try the compiled and binary java demo for Linux 64 bit :=>

Download and unzip the demo.

Then :=>

-In terminal do:

-> cd /demo_Java (go in java demo path)

Then run it with:

-> java -Djava.library.path=. fpg_demo

It is a demo for Linux 64 bit.
The same demo, with fpGUIlib.so compiled on freeBSD does not work...

-----
Many thanks ;-)

Reply by email

fredvs
to fredvs

Aaaargh, difficult t find help here...

In the original thread

> [fpc-devel] (hack) calling fpc libraries from other languages on > freebsd/amd64 > of Michal Wallace
Michael Wallace said that he has find the solution :=>
> Anyway, the problem appears to be in this file: > http://svn.freepascal.org/cgi-bin/viewvc.cgi/trunk/rtl/freebsd/x86_64/dllpr=

(But this file is no more accessible. ;-( )

Show quoted text 20 lines
> It has the comment: > # FreeBSD RunTime dynamic loader only > # calls the functions specified by -init > # as functions without parameters > # Thus, it is not possible to retrieve argc, argv and envp > # On x86_64 CPU, using weak for the operatingsystem_parameter_XXX > # allows to bind to main program parameters, > # but this does not seem to work for i386 loader. > Then at the bottom: > /* Do not fail linkage if argc, argv and envp are not found. */ > .weak operatingsystem_parameter_argc > .weak operatingsystem_parameter_argv > .weak operatingsystem_parameter_envp > My change was to comment these lines out and copy the lines from prt0.as > :
Show quoted text 14 lines
> .global operatingsystem_parameter_envp > .global operatingsystem_parameter_argc > .global operatingsystem_parameter_argv > .set operatingsystem_parameter_envp,operatingsystem_parameters+0 > .set operatingsystem_parameter_envp,operatingsystem_parameters+0 > .set operatingsystem_parameter_envp,operatingsystem_parameters+0 > Then after recompiling fpc, I was able to compile a *.so file usable from > python. > But... It seems like the original .weak version was done quite > deliberately, so I suspect that if I submit a patch, it would break > things for other people. OTOH, I'd like to get a fix for my issue > into trunk.

So, it seems that Michal Wallace do not sent a patch for that. It seems too that his solution was for Python, maybe it works for Java too.

But later Sergei Gorelkin answers :

Show quoted text 12 lines
Studying sources of FreeBSD dynamic loader reveals that, although it does not pass argc, argv and envp to the initialization function in .init section, it *does* pass them to procedures pointed to from .init_array section. Generally, .init_array is considered as a replacement for .init. Therefore, the correct solution would be to change initialization to use .init_array and remove all associated hacks. Regards, Sergei

So i do not know where is the good solution, please, wonderful fpc people, help us and me...

Fred

-----
Many thanks ;-)

Reply by email