* * *

Author Topic: Use libxml2 in Linux 64 bits  (Read 3373 times)

almp1

  • New member
  • *
  • Posts: 13
Use libxml2 in Linux 64 bits
« on: July 25, 2016, 04:12:38 am »
Hello friends!

I use in my projects to libxml2-pascal library https://sourceforge.net/projects/libxml2-pas/. Use a long time.
Already gone through various environments using this library. Used environments are as follows:
1) Lazarus 1.4.x FPC 2.6.x on Windows 7.8 and 10 32 and 64 bits
2) Lazarus 1.6.x FPC 3.0.x on Windows 7.8 and 10 32 and 64 bits
3) Lazarus 1.4.x FPC 2.6.x Linux, Centos 6.7 distribution and Ubuntu 12.x and 14.x 32bits
4) Lazarus 1.6.x FPC 3.0.x Linux, Centos 6.7 distribution and Ubuntu 12.x and 14.x 32bits

The libxml2 library, both the DLL as the .so are version 2.9.4

But I can not use the library on Linux 64bits. I really need to use this library in Linux 64bit environment, I've tried everything I know, but it is always displayed the exception message

Linux 64 environment can make the library loading with
LoadLibrary ( 'libxml2.so');

But when I use GetProcess such as the following line:
 xmlStringComment: = PAnsiChar (GetProcAddress (libHandle 'xmlStringComment'));

I get the message below

System design raised exception class 'External: SIGSEGV'.
The address 7FFFF7DE4DF0

I do not know what to do, will that someone could help me with any tips?

I thank you

molly

  • Hero Member
  • *****
  • Posts: 1963
Re: Use libxml2 in Linux 64 bits
« Reply #1 on: July 25, 2016, 07:23:50 am »
Linux 64 environment can make the library loading with
LoadLibrary ( 'libxml2.so');

But when I use GetProcess such as the following line:
 xmlStringComment: = PAnsiChar (GetProcAddress (libHandle 'xmlStringComment'));

I get the message below

System design raised exception class 'External: SIGSEGV'.
The address 7FFFF7DE4DF0
Since loadlibrary is a function returning a result, what does it return for you ?

Note the part:
Quote
If the library cannot be loaded, NilHandle is returned.

mig-31

  • Full Member
  • ***
  • Posts: 223
Re: Use libxml2 in Linux 64 bits
« Reply #2 on: July 25, 2016, 10:04:33 am »
If your application 64-bit check the path /usr/lib/ for library exists, for 32-bit - /usr/lib32

If your see something like /usr/lib/libxml2.so.2.1 create a symbol link libxml2.so -> libxml2.so.2.1
Lazarus 1.6 - Linux 32/64 bit, win32

almp1

  • New member
  • *
  • Posts: 13
Re: Use libxml2 in Linux 64 bits
« Reply #3 on: July 25, 2016, 04:01:51 pm »
Hi Molly

The return has been a valid integer. In my code there is a line below

Code: Pascal  [Select]
  1.  
  2.    libHandle: = LoadLibrary ('libxml2.so');
  3.    if libHandle <> 0 then
  4.    begin
  5.      __emptyExp: = xmlExpNodePtrPtr (GetProcAddress (libHandle 'emptyExp'));
  6.  

Still, thanks for the reply


almp1

  • New member
  • *
  • Posts: 13
Re: Use libxml2 in Linux 64 bits
« Reply #4 on: July 25, 2016, 04:04:14 pm »
Hi mig-31

Yes I checked the symbolic links, they are correct. If I cause an error in the link symbolic return of LoadLibrary is NilHandle

Thanks for your response

molly

  • Hero Member
  • *****
  • Posts: 1963
Re: Use libxml2 in Linux 64 bits
« Reply #5 on: July 25, 2016, 06:41:21 pm »
The return has been a valid integer. In my code there is a line below
Hmz strange.

Are you perhaps compiling a 64-bit program and loading a 32-bit version of the library ?

almp1

  • New member
  • *
  • Posts: 13
Re: Use libxml2 in Linux 64 bits
« Reply #6 on: July 25, 2016, 07:00:47 pm »
Hi molly

Prepared every environment in 64bits, on a separate machine.
I made sure to ensure that no library 32bits stay active.
So was the test environment:

  • CentOS7 64bits
  • Lazarus 1.6 and FPC 3.0 64bits installed using RPM packages

Although the libraries are available in the yum repository CentOS7, updated packages to their latest versions.
The xmlsec, xml2 and xslt libraries were downloaded here

ftp://xmlsoft.org/libxml2/

thanks for the reply

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 556
Re: Use libxml2 in Linux 64 bits
« Reply #7 on: July 26, 2016, 01:31:12 pm »
Is the type of the variable in which you store the result of loadlibrary "TLibHandle"? It's an integer type, so if you assign it to a 32 bit variable it will compile, but you will be truncating the handle. Try compiling with range checking enabled to catch such errors.

almp1

  • New member
  • *
  • Posts: 13
Re: Use libxml2 in Linux 64 bits
« Reply #8 on: July 27, 2016, 05:44:11 am »
Hi  Jonas Maebe

I used your idea to change the type declaration of variable libhandle. I was thus declaring libhandle: THandle. I made a change to libhandle: TLibHandle. With this I managed to pass the __emptyExp: = xmlExpNodePtrPtr (GetProcAddress (libHandle 'emptyExp'));

Code: Pascal  [Select]
  1. var
  2.   //libHandle: THandle;
  3.   libHandle: TLibHandle;
  4. begin
  5. libHandle: = LoadLibrary ('libxml2.so');
  6.    if libHandle <> 0 then
  7.    begin
  8.      __emptyExp: = xmlExpNodePtrPtr (GetProcAddress (libHandle 'emptyExp'));
  9.  

Now I have other pair identify challenges, but already helped me a lot

Thank you

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus