Problem with UserLibrary

Linux specific forum
Andras
User
User
Posts: 34
Joined: Wed Oct 27, 2004 6:58 am
Location: Germany

Problem with UserLibrary

Post by Andras »

Hi,

I created a Library and now tried to compile an example-source. I get the following messages:

******************************************
PureBasic Linux x86 v3.92
******************************************

Loading external modules...
Starting compilation...
108 lines processed.
Creating the executable.
DynArray.a: could not read symbols: Archive has no index; run ranlib to add one
collect2: ld returned 1 exit status
Error: Linker


What am I doing wrong?
Undank ist der Welten Lohn
dmoc
Enthusiast
Enthusiast
Posts: 739
Joined: Sat Apr 26, 2003 12:40 am

Post by dmoc »

Probably nothing - I don't think userlibs are supported. There's *always* something missing from the linux version.
olejr
Enthusiast
Enthusiast
Posts: 152
Joined: Sun Jul 11, 2004 7:48 pm
Location: Lillehammer, No(r)way
Contact:

Post by olejr »

@dmoc: Userlibs is one thing that's been there for a loong time!!

@Andreas: Created it with asm or c??
dmoc
Enthusiast
Enthusiast
Posts: 739
Joined: Sat Apr 26, 2003 12:40 am

Post by dmoc »

Re userlibs: not according to this post
olejr
Enthusiast
Enthusiast
Posts: 152
Joined: Sun Jul 11, 2004 7:48 pm
Location: Lillehammer, No(r)way
Contact:

Post by olejr »

That's the /userlibraries folder I requested. Like we have on Windows..
You can still make userlibs and put them in /purelibraries..
Andras
User
User
Posts: 34
Joined: Wed Oct 27, 2004 6:58 am
Location: Germany

Post by Andras »

Hi!

@dmoc: I put the Library directly into the PureLibraries-Directory

@olejr: The Library was created with Assembler

I'm going to write a detailed overview of how I created the Library this evening and will post it here. Maybe I just made a little mistake during the creation of it.
Undank ist der Welten Lohn
olejr
Enthusiast
Enthusiast
Posts: 152
Joined: Sun Jul 11, 2004 7:48 pm
Location: Lillehammer, No(r)way
Contact:

Post by olejr »

Oh.. I didn't get asm to work either, so I did it in C..
I got some error about missing 'main' or something.. Don't remember....

It should also work in asm, but i'm no guru..:?
But heres a quick rundown on how it should be:

Code: Select all

fasm source.asm source.o <- repeat for every sourcefile
ar rvs yourlib.a *.o
librarymaker  yourlib.desc /TO $(PUREBASIC_HOME)/purelibraries/
Andras
User
User
Posts: 34
Joined: Wed Oct 27, 2004 6:58 am
Location: Germany

Post by Andras »

Here are some information of how I made the Library:

I am using Suse 9.1, 2.6.4-52-default

1. Write SourceCode in PureBasic-Language (OS-Independent)
2. Use TailBite to create the .asm-Files (Under Windows)
3. Compiled the .asm Files to .o-Files with FAsm (under Linux)
4. Created an Archive containing the .o-Files with ar (ar rs DynArray.a *.o)
5. Corrected the .Desc-File (Content below)
6. Used PBLibraryMaker to create the Library and put it into PureLibraries-Directory
7. Tried to compile an ExampleSource using the Library -> LinkerError

My .asm-Files look like this (this is only one of them):

Code: Select all

format MS COFF

Public PB_DynArray_Erase

Extrn PB_PeekL
Extrn _PB_FreeMemory@4
Extrn PB_PokeL


section '.text' code readable executable

PB_DynArray_Erase:
_DynArray_Erase:
PUSH   ebx
PUSH   ecx
PUSH   ebp
PUSH   esi
PUSH   edi
MOV esi,esp
SUB    esp,8
MOV    eax,esp
MOV    edx,eax
ADD    edx,8
_ClearLoop16:
MOV    dword [eax],0
ADD    eax,4
CMP    eax,edx
JNE   _ClearLoop16
MOV    eax, dword [esi+24]
MOV    dword [esp+0],eax
;
; DynID=PeekL(*DynArrayID)
MOV    eax,dword [esp]
CALL   PB_PeekL
MOV    dword [esp+4],eax
;
; If DynID<>0
MOV    ebx,dword [esp+4]
CMP    ebx,0
JE    _EndIf56
; FreeMemory(DynID-4)
MOV    ebx,dword [esp+4]
ADD    ebx,-4
PUSH   ebx
CALL  _PB_FreeMemory@4
; PokeL(*DynArrayID,0)
PUSH   dword 0
MOV    eax,dword [esp+4]
CALL   PB_PokeL
; EndIf
_EndIf56:
;
; EndProcedure
XOR    eax,eax
_EndProcedure17:
ADD    esp,8
POP    edi
POP    esi
POP    ebp
POP    ecx
POP    ebx
RET    4
_EndProcedure16:
My .Desc-File looks like this:

Code: Select all

ASM
;
0
;
LIB
;
4
String
StringExtension
MemoryExtension
Memory
;
DynArray.chm
;
DynArray_ReDim, Long, Long (*DynArrayID, ElementCount) - Creates or redimensionates a DynArray
Byte | StdCall
;
DynArray_Set, Long, Long, Long (*DynArrayID, ElementNumber, Value) - Sets a Value to an Element in the DynArray
Byte | StdCall
;
DynArray_Get, Long, Long (*DynArrayID, ElementNumber) - Gets a Value from an Element in the DynArray
Long | StdCall
;
DynArray_Clone, Long, Long (*DynArrayIDSrc, *DynArrayIDDest) - Clones a DynArray
Byte | StdCall
;
DynArray_Count, Long (*DynArrayID) - Returns the Count of Elements
Long | StdCall
;
DynArray_Clear, Long (*DynArrayID) - Sets all Values to 0
None | StdCall
;
DynArray_FillByPBArray, Long, Long, Long, Long (*DynArrayID, aPBarray, StartDest, ElementCount) - Fills a DynArray by a PureBasic-Array
None | StdCall
;
DynArray_GetMemoryPosition, Long (*DynArrayID) - Returns the MemoryAddress of the LongArray
Long | StdCall
;
DynArray_Erase, Long (*DynArrayID) - Destroys a DynArray
None | StdCall
;
DynArray_RemoveElement, Long, Long (*DynArrayID, ElementNumber) - Removes an Element
None | StdCall
;
DynArray_InsertElement, Long, Long, Long (*DynArrayID, ElementNumber, Value) - Insert an Element and set the Value
Byte | StdCall
;
DynArray_SetString, Long, String, Long (*DynArrayID, aString.s, StartDest) - Set a Part of the DynArray to the Bytes of a String
Byte | StdCall
;
DynArray_GetString, Long, Long, Long (*DynArrayID, StartElement, MaxLength) - Get a Part of the DynArray as a String
String | StdCall
;
These are the Messages I get when I compile an ExampleSource that uses the Library:

Code: Select all

******************************************
PureBasic Linux x86 v3.92
******************************************

Loading external modules...
Starting compilation...
108 lines processed.
Creating the executable.
DynArray.a: could not read symbols: Archive has no index; run ranlib to add one
collect2: ld returned 1 exit status
Error: Linker
When I use the original SourceCode of the Library (IncludeFile) to compile the ExampleSource, everything works fine... :monday:
Undank ist der Welten Lohn
olejr
Enthusiast
Enthusiast
Posts: 152
Joined: Sun Jul 11, 2004 7:48 pm
Location: Lillehammer, No(r)way
Contact:

Post by olejr »

Well here's the offending parts:

Code: Select all

format MS COFF  ;<- MS as in MicroSoft
;Should be
format ELF  ;<- Not sure about this.. Maybe just COFF (pb output is ELF)

section '.text' code readable executable
;Should be
section '.text' executable
Ie Windows only stuff...

Not sure if it work if you change this bits either..
Andras
User
User
Posts: 34
Joined: Wed Oct 27, 2004 6:58 am
Location: Germany

Post by Andras »

I tried both, COFF and ELF, but nothing worked. Using COFF results in the same Messages as above. When I use ELF I get the following:

Code: Select all

******************************************
PureBasic Linux x86 v3.92
******************************************

Loading external modules...
Starting compilation...
108 lines processed.
Creating the executable.
DynArray.a(DynArray_Clone.o)(.text+0x69): In function `PB_DynArray_Clone':
: undefined reference to `_PB_ReAllocateMemory@8'
DynArray.a(DynArray_Clone.o)(.text+0xa6): In function `PB_DynArray_Clone':
: undefined reference to `_PB_AllocateMemory@4'
DynArray.a(DynArray_Clone.o)(.text+0xe4): In function `PB_DynArray_Clone':
: undefined reference to `_PB_CopyMemory@12'
DynArray.a(DynArray_Erase.o)(.text+0x42): In function `PB_DynArray_Erase':
: undefined reference to `_PB_FreeMemory@4'
DynArray.a(DynArray_FillByPBArray.o)(.text+0xba): In function `PB_DynArray_FillByPBArray':
: undefined reference to `_PB_CopyMemory@12'
DynArray.a(DynArray_InsertElement.o)(.text+0x8c): In function `PB_DynArray_InsertElement':
: undefined reference to `_PB_ReAllocateMemory@8'
DynArray.a(DynArray_InsertElement.o)(.text+0xf5): In function `PB_DynArray_InsertElement':
: undefined reference to `_PB_CopyMemory@12'
DynArray.a(DynArray_ReDim.o)(.text+0x6d): In function `PB_DynArray_ReDim':
: undefined reference to `_PB_FreeMemory@4'
DynArray.a(DynArray_ReDim.o)(.text+0xab): In function `PB_DynArray_ReDim':
: undefined reference to `_PB_ReAllocateMemory@8'
DynArray.a(DynArray_ReDim.o)(.text+0xf8): In function `PB_DynArray_ReDim':
: undefined reference to `_PB_AllocateMemory@4'
DynArray.a(DynArray_RemoveElement.o)(.text+0xa6): In function `PB_DynArray_RemoveElement':
: undefined reference to `_PB_CopyMemory@12'
DynArray.a(DynArray_RemoveElement.o)(.text+0xd1): In function `PB_DynArray_RemoveElement':
: undefined reference to `_PB_ReAllocateMemory@8'
collect2: ld returned 1 exit status
Error: Linker
With ELF I removed all flags except "exectuable" and "writeable", with COFF "code" and "data"...

hmmmm :(
Undank ist der Welten Lohn
olejr
Enthusiast
Enthusiast
Posts: 152
Joined: Sun Jul 11, 2004 7:48 pm
Location: Lillehammer, No(r)way
Contact:

Post by olejr »

Well.. Here's what I would do:

Copy the source.pb to Linux, do pbcompiler source.pb -c -e test,
and look at the purebasic.asm in the same folder as the source.pb
to see what differ....
(the: -e test is just there so the exe don't autorun..)
Andras
User
User
Posts: 34
Joined: Wed Oct 27, 2004 6:58 am
Location: Germany

Post by Andras »

I'll try that - but I expect that the PBCompiler produces different .asm-"Formats" for executable-files and object-files...

tusen takk! thanks a lot for your help so far!
Undank ist der Welten Lohn
olejr
Enthusiast
Enthusiast
Posts: 152
Joined: Sun Jul 11, 2004 7:48 pm
Location: Lillehammer, No(r)way
Contact:

Post by olejr »

Don't think that the pbcompiler output is alot different..

And as I said in the beginning.. I couldn't make it work with asm either..
Fred
Administrator
Administrator
Posts: 18350
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

Compiling on Windows for Linux won't work, as internals fonctions names aren't the same, as reported by the linker. You will have to compile it on Linux as olejr told, and tweak the code (may be TailBite could be easily adapted, the output code is very similar - olejr give it a try IIRC).
Fred - AlphaSND
Post Reply