Linker error

Linux specific forum
User_Russian
Addict
Addict
Posts: 1588
Joined: Wed Nov 12, 2008 5:01 pm
Location: Russia

Linker error

Post by User_Russian »

When you compile this code in PB 5.11 x64

Code: Select all

#NCCS = 32
#TCSANOW = 0
  
Structure termios Align #PB_Structure_AlignC
  c_iflag.l
  c_oflag.l
  c_cflag.l
  c_lflag.l
  c_line.a
  c_cc.a[#NCCS]
  c_ispeed.l
  c_ospeed.l
EndStructure
  
ProcedureDLL xx()
PortID = 0 ;SerialPortID(Port)

If tcgetattr_(PortID, @options) = 0   ; читает параметры порта.
  If cfsetispeed_(@options, Sp) = 0   ; установка скорости порта.
    If cfsetospeed_(@options, Sp) = 0 ; установка скорости порта.
      If tcsetattr_(PortID, #TCSANOW, @options) = 0
        Result=#True
      EndIf
    EndIf
  EndIf
EndIf

EndProcedure
linker an error occurs.

Image

The problem only occurs when creating so-library. Use Linux Mint 16 x64.

This command does not work.

Code: Select all

Import "-fPIC" : EndImport
How to fix the problem?
User avatar
idle
Always Here
Always Here
Posts: 6026
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Linker error

Post by idle »

The problem is with the the version of libc the function is resolving to. It hasn't been compiled with -FPic
so it can't be included into a shared object.

I had no problems compiling it on ubuntu 12.04 x64
Windows 11, Manjaro, Raspberry Pi OS
Image
User_Russian
Addict
Addict
Posts: 1588
Joined: Wed Nov 12, 2008 5:01 pm
Location: Russia

Re: Linker error

Post by User_Russian »

idle wrote:The problem is with the the version of libc the function is resolving to. It hasn't been compiled with -FPic
so it can't be included into a shared object.
This is a problem with the OS library, or PB-Library?
If with OS-library, why not have this error when compiling in PB 5.2x?
If with PB-library, then why not this error when compiling function OpenSerialPort(), in which there is a code from the first post of this topic?
idle wrote:I had no problems compiling it on ubuntu 12.04 x64
You used PB 5.11 or PB 5.2x?
In PB 5.2x compiles without errors, but there is a bug, because of which does not work do not one, SO-library are compiled in PB 5.2x.
User avatar
idle
Always Here
Always Here
Posts: 6026
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Linker error

Post by idle »

I'm using PB 5.21 LTS x64 on ubuntu 12.04

the error is telling you that the function is in a library that doesn't support relocatable code
so it can't be used in a shared object only in the executable.
Though I'm a bit confused why it's says the symbol is undefined.
The problem is with the OS library not PB but the gcc errors don't always report the library
that's causing the immediate problem either.
maybe you're missing a dev version of a library.
Windows 11, Manjaro, Raspberry Pi OS
Image
User_Russian
Addict
Addict
Posts: 1588
Joined: Wed Nov 12, 2008 5:01 pm
Location: Russia

Re: Linker error

Post by User_Russian »

idle wrote:maybe you're missing a dev version of a library.
Installed only libgtk2-dev.
Need more libraries to compile this code?

The strange thing is that OpenSerialPort() uses the function tcsetattr_() and it does not cause problems when compiling SO-library.
User_Russian
Addict
Addict
Posts: 1588
Joined: Wed Nov 12, 2008 5:01 pm
Location: Russia

Re: Linker error

Post by User_Russian »

Tried to load the functions from libdl.so.2. When compiling standard program - works, but when compiling SO-library can not open "libdl.so.2".

Code: Select all

#NCCS = 32
#TCSANOW = 0
  
Structure termios Align #PB_Structure_AlignC
  c_iflag.l
  c_oflag.l
  c_cflag.l
  c_lflag.l
  c_line.a
  c_cc.a[#NCCS]
  c_ispeed.l
  c_ospeed.l
EndStructure

Prototype tcgetattr(x, y)
Prototype cfsetispeed(x, y)
Prototype cfsetospeed(x, y)
Prototype tcsetattr(x, y, z)

  
ProcedureDLL xx()
  
  Result = 0
  
  Static tcgetattr.tcgetattr
  Static cfsetispeed.cfsetispeed
  Static cfsetospeed.cfsetospeed
  Static tcsetattr.tcsetattr
  
  Protected options.termios, Sp
  
  If IsLibrary(4)=0
    Result =1
    If OpenLibrary(4, "libdl.so.2")
      Result =2
      tcgetattr= GetFunction(4, "tcgetattr")
      cfsetispeed= GetFunction(4, "cfsetispeed")
      cfsetospeed=GetFunction(4, "cfsetospeed")
      tcsetattr= GetFunction(4, "tcsetattr")
    EndIf
  EndIf
  
  If IsLibrary(4) And tcgetattr And cfsetispeed And cfsetospeed And tcsetattr
    
    Result =3
    
    x=OpenSerialPort(0, "/dev/ttyS0", 9600, #PB_SerialPort_NoParity, 8, 1, #PB_SerialPort_NoHandshake, 1024, 1024)
    If x=0
      Result =4
      ProcedureReturn Result
    EndIf
    PortID = SerialPortID(0)
    
    Result =5
    
    options.termios
    Sp=4098
    
    If tcgetattr(PortID, @options) = 0   ; ÷èòàåò ïàðàìåòðû ïîðòà.
      Result =7
      If cfsetispeed(@options, Sp) = 0   ; óñòàíîâêà ñêîðîñòè ïîðòà.
        Result =8
        If cfsetospeed(@options, Sp) = 0 ; óñòàíîâêà ñêîðîñòè ïîðòà.
          Result =9
          If tcsetattr(PortID, #TCSANOW, @options) = 0
            Result=10
          EndIf
        EndIf
      EndIf
    EndIf
    
  EndIf
  
  ProcedureReturn Result
EndProcedure

; MessageRequester("", Str(xx()))
; xx()
User avatar
idle
Always Here
Always Here
Posts: 6026
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Linker error

Post by idle »

The functions are from libc which should be found under root/lib/x86_64-linux-gnu
The output is generating the linker request with "-lc"
and adding the Import your self probably won't help

Code: Select all

ImportC "-lc" : EndImport  


think you need someone with your linux version to help out
Windows 11, Manjaro, Raspberry Pi OS
Image
User_Russian
Addict
Addict
Posts: 1588
Joined: Wed Nov 12, 2008 5:01 pm
Location: Russia

Re: Linker error

Post by User_Russian »

idle wrote:I'm using PB 5.21 LTS x64 on ubuntu 12.04
Need to use PB 5.11.
In PB 5.21 bug where not working SO-library.

In Ubuntu 12.04, the same linker error.

Image
User avatar
idle
Always Here
Always Here
Posts: 6026
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Linker error

Post by idle »

There is no bug that I can see using PB5.21 x64 on ubuntu 12.04

This code compiles to a shared object. Tried ascii and unicode modes

Code: Select all

#NCCS = 32
#TCSANOW = 0
  
Structure termios Align #PB_Structure_AlignC
  c_iflag.l
  c_oflag.l
  c_cflag.l
  c_lflag.l
  c_line.a
  c_cc.a[#NCCS]
  c_ispeed.l
  c_ospeed.l
EndStructure

ProcedureCDLL xx()
  
    x=OpenSerialPort(0, "/dev/ttyS0", 9600, #PB_SerialPort_NoParity, 8, 1, #PB_SerialPort_NoHandshake, 1024, 1024)
    If x=0
      Result =4
      ProcedureReturn result  
    EndIf
    PortID = SerialPortID(0)
    
    Result =5
    
    options.termios
    Sp=4098
    
    If tcgetattr_(PortID, @options) = 0   ; ÷èòàåò ïàðàìåòðû ïîðòà.
      Result =7
      If cfsetispeed_(@options, Sp) = 0   ; óñòàíîâêà ñêîðîñòè ïîðòà.
        Result =8
        If cfsetospeed_(@options, Sp) = 0 ; óñòàíîâêà ñêîðîñòè ïîðòà.
          Result =9
          If tcsetattr_(PortID, #TCSANOW, @options) = 0
            Result=10
          EndIf
        EndIf
      EndIf
    EndIf
      
  ProcedureReturn Result
EndProcedure
This loaded the .so and called the function
with the compiler option to create the executable in the source directory

Code: Select all


ImportC "../junk.so" 
   xx() 
EndImport    

MessageRequester("", Str(xx()))

Though it didn't open the serial port
Windows 11, Manjaro, Raspberry Pi OS
Image
User_Russian
Addict
Addict
Posts: 1588
Joined: Wed Nov 12, 2008 5:01 pm
Location: Russia

Re: Linker error

Post by User_Russian »

Why, then, me do not work SO-libraries created in PB 5.21 x64?
SO-libraries created in PB 5.11 x64 (from the same source code), work without problems.
Tested in distributions, ubuntu 12.04, Mint 16 and OpenMandriva 2013. In the mode Live DVD (Boot from DVD without installation on your computer).
Post Reply