ich habe gerade eine Unicode Unit erstellt, deren Funktionen in einer in C geschriebenen .o Datei stecken, die ich nun für Pascal verfügbar machen will. Ich erhalte aber bei der ersten von mir getesteten Funktion UTextToUpper(d: l_utext): l_utext; diese Fehlermeldung:
Error: Undefined Symbol: UTEXT_$$_UTEXTTOUPPER$SHORTSTRING$$SHORTSTRING
Die C Funktion ist so definiert:
Code: Alles auswählen
l_utext UTextToUpper( l_utext d ){
l_utext l = d;
if ( !DCkPt("UTextToUpper.d",d) ) return 0;
while ( *d ){ *d = UToUpper(*d); d++; }
return l;
}
Ich habe eine C/C++ Bibliothek die aus .a und vielen .o Dateien besteht. Ich will diese verwenden und in Pascal nur die öffentlichen Funktionen als Pascal Header schreiben, die .a und .o Dateien in die Unit linken und den in C/C++ existierenden Code von Freepascal aus verwenden.
Wie mache ich das?
Für das obige Beispiel habe ich mir eine Pascal Unit geschrieben, welche folgenden Aufbau hat:
Code: Alles auswählen
////////////////////////////////////////////////////////////////////////////////
//
// Unicode Text Manipulation - Core file
//
// (c) Copyright 2004 Point Mad. All rights reserved.
//
////////////////////////////////////////////////////////////////////////////////
unit utext;
interface
uses Sysutils,cTypes;
{$LINK utext.o}
const
COMBUF_TEXT_SIZE = 255;
type
l_utext = String;
l_short = Byte;
l_ulong = Cardinal;
var
CommonBufferUText: array[0..COMBUF_TEXT_SIZE] of l_short;
function UTextLen( t: String ): l_ulong;
function UTextChr( t: l_utext; c: l_short ): l_utext;
function UTextRChr( t: l_utext; c: l_short ): l_utext;
function UTextCompare ( a: l_utext; b: l_utext ): Longint;
function UTextNCompare ( a: l_utext; b: l_utext; n: l_ulong ): Longint;
function UTextCaseCompare ( a: l_utext; b: l_utext ): Longint;
function UTextNCaseCompare ( a: l_utext; b: l_utext; n: l_ulong ): Longint;
function UTextSqNCaseCompare ( sq: l_utext; t: l_utext; n: l_ulong ): Longint;
function UTextCopy ( d: l_utext; s: l_utext ): l_utext;
function UTextNCopy ( d: l_utext; s: l_utext; n: l_ulong ): l_utext;
function UTextDup ( t: l_utext ): l_utext;
function UTextNDup ( t: l_utext; n: l_ulong ): l_utext;
function UTextCat ( d: l_utext; t: l_utext ): l_utext;
function UTextToUpper( d: l_utext ): l_utext;
function UTextToLower( d: l_utext ): l_utext;
function UToLower ( c: l_short ): l_short;
function UToUpper ( c: l_short ): l_short;
implementation
function UTextLen( t: String ): l_ulong;
var
l: l_ulong;
begin
l := Length(t);
UTextLen := l;
end;
function UTextChr( t: l_utext; c: l_short ): l_utext;
var
i: Integer;
begin
i := 1;
if Length(t) = 0 then UTextChr := IntToStr(0) else
while i < length(t) do
begin
if t[i] = Chr(c) then
begin
UTextChr := IntToStr(i);
i := Length(t);
end;
inc(i);
end;
end;
function UTextRChr( t: l_utext; c: l_short ): l_utext;
var i: Integer;
begin
i := Length(t);
UTextRChr := IntToStr(0);
while i>0 do
begin
if t[i] = Chr(c) then
begin
UTextRChr := IntToStr(i);
i := 0;
end;
dec(i);
end;
end;
function UTextCompare ( a: l_utext; b: l_utext ): Longint;
begin
if a<b then UTextCompare := -1 else
if a>b then UTextCompare := +1 else
UTextCompare := 0;
end;
// Compare 2 texts a and b on length n, return 0 if identical
function UTextNCompare ( a: l_utext; b: l_utext; n: l_ulong ): Longint; external;
// Compare 2 texts a and b, return 0 if identical
function UTextCaseCompare ( a: l_utext; b: l_utext ): Longint; external;
// Compare 2 texts a and b on length n, return 0 if identical
function UTextNCaseCompare ( a: l_utext; b: l_utext; n: l_ulong ): Longint; external;
// Compare a sequence (sq,n) and a text t, return 0 if identical,
function UTextSqNCaseCompare ( sq: l_utext; t: l_utext; n: l_ulong ): Longint; external;
// Copy text s to text d, return d
function UTextCopy ( d: l_utext; s: l_utext ): l_utext; external;
// Copy text s to text d of n chars, add \0 at end ,return d
function UTextNCopy ( d: l_utext; s: l_utext; n: l_ulong ): l_utext; external;
// Make a copy of string t in a new memory allocation
function UTextDup ( t: l_utext ): l_utext; external;
// Make a copy of n chars of text t in a new memory allocation (add \0 at end)
function UTextNDup ( t: l_utext; n: l_ulong ): l_utext; external;
// Add text t at the text d end, text d must have enouf memory allocated
function UTextCat ( d: l_utext; t: l_utext ): l_utext; external;
// Transform text to upper case
function UTextToUpper( d: l_utext ): l_utext; external;
// Transform text to lower case
function UTextToLower( d: l_utext ): l_utext; external;
function UToLower ( c: l_short ): l_short; external;
function UToUpper ( c: l_short ): l_short; external;
end.
Code: Alles auswählen
////////////////////////////////////////////////////////////////////////////////
//
// Unicode Text Manipulation - Core file
//
// (c) Copyright 2004 Point Mad. All rights reserved.
//
////////////////////////////////////////////////////////////////////////////////
#include "stdio.h"
#include "stdarg.h"
#include "types.h"
#include "utext.h"
#include "dynld.h"
#include "internal.h"
#include "debug.h"
/**
* NAME: CommonBufferUText
* DESCRIPTION: This is a common buffer text, be careful with it.
*/
l_short CommonBufferUText[COMBUF_TEXT_SIZE];
////////////////////////////////////////////////////////////////////////////////
// Return length of text t
l_ulong UTextLen( l_utext t )
{
l_utext l = t;
if ( !DCkPt("UTextLen.t",t) ) return 0;
while ( *l ) l++;
return l-t;
}
////////////////////////////////////////////////////////////////////////////////
// Return 1st occurence of the char c in text t, if not found return 0
l_utext UTextChr( l_utext t, l_short c )
{
if ( !DCkPt("UTextChr.t",t) ) return 0;
while ( *t )
{
if ( *t == c ) return t;
t++;
}
if ( c == 0 )
return t;
return 0;
}
////////////////////////////////////////////////////////////////////////////////
// Return Last occurence of the char c in text t, if not found return 0
l_utext UTextRChr( l_utext t, l_short c ) {
l_utext r = 0;
if ( !DCkPt("UTextRChr.t",t) ) return 0;
while ( *t ) {
if ( *t == c ) r = t;
t++;
}
if ( c == 0 ) r = t;
return r;
}
////////////////////////////////////////////////////////////////////////////////
// Compare 2 texts a and b, return 0 if identical
long UTextCompare ( l_utext a, l_utext b ) {
if ( !DCkPt("UTextCompare.a",a) || !DCkPt("UTextCompare.b",b) ) return 0;
while ( *a == *b ) {
if (!*a) return 0;
a++;
b++;
}
return *a-*b;
}
////////////////////////////////////////////////////////////////////////////////
// Compare 2 texts a and b on length n, return 0 if identical
long UTextNCompare ( l_utext a, l_utext b, l_ulong n ) {
if ( !DCkPt("UTextNCompare.a",a) || !DCkPt("UTextNCompare.b",b) ) return 0;
while ( n ) {
if ( *a != *b ) return *a-*b;
if ( !*a ) return 0;
a++;
b++;
n--;
}
return 0;
}
////////////////////////////////////////////////////////////////////////////////
// Compare 2 texts a and b, return 0 if identical
long UTextCaseCompare ( l_utext a, l_utext b ) {
if ( !DCkPt("UTextCaseCompare.a",a) || !DCkPt("UTextCaseCompare.b",b) ) return 0;
while ( UToLower(*a) == UToLower(*b) ) {
if (!*a) return 0;
a++;
b++;
}
return UToLower(*a)-UToLower(*b);
}
////////////////////////////////////////////////////////////////////////////////
// Compare 2 texts a and b on length n, return 0 if identical
long UTextNCaseCompare ( l_utext a, l_utext b, l_ulong n ) {
if ( !DCkPt("UTextNCaseCompare.a",a) || !DCkPt("UTextNCaseCompare.b",b) ) return 0;
while ( n ) {
if ( UToLower(*a) != UToLower(*b) ) return UToLower(*a)-UToLower(*b);
if ( !*a ) return 0;
a++;
b++;
n--;
}
return 0;
}
////////////////////////////////////////////////////////////////////////////////
// Compare a sequence (sq,n) and a text t, return 0 if identical,
long UTextSqNCaseCompare ( l_utext sq, l_utext t, l_ulong n ) {
if ( !DCkPt("UTextNCaseCompare.sq",sq) || !DCkPt("UTextNCaseCompare.t",t) ) return 0;
while ( n ) {
if ( tolower(*sq) != tolower(*t) ) return tolower(*sq)-tolower(*t);
if ( !*sq ) return 0;
sq++;
t++;
n--;
}
return *t;
}
////////////////////////////////////////////////////////////////////////////////
// Copy text s to text d, return d
l_utext UTextCopy ( l_utext d, l_utext s ) {
l_utext l = d;
if ( !DCkPt("UTextCopy.d",d) || !DCkPt("UTextCopy.s",s) ) return 0;
while ( *d = *s ) {
s++;
d++;
}
*d = 0;
return l;
}
////////////////////////////////////////////////////////////////////////////////
// Copy text s to text d of n chars, add \0 at end ,return d
l_utext UTextNCopy ( l_utext d, l_utext s, l_ulong n ) {
l_utext l = d;
if ( !DCkPt("UTextNCopy.d",d) || !DCkPt("UTextNCopy.s",s) ) return 0;
while ( ( *d = *s ) && n ) {
s++;
d++;
n--;
}
*d = 0;
return l;
}
////////////////////////////////////////////////////////////////////////////////
// Make a copy of string t in a new memory allocation
l_utext UTextDup ( l_utext t ) {
l_utext n;
if ( !DCkPt("UTextDup.t",t) ) return NULL;
n = (l_utext)malloc((UTextLen(t)*2)+2);
if ( !n ) return NULL;
return UTextCopy(n,t);
}
////////////////////////////////////////////////////////////////////////////////
// Make a copy of n chars of text t in a new memory allocation (add \0 at end)
l_utext UTextNDup ( l_utext t, l_ulong n ) {
l_utext l;
if ( !DCkPt("UTextNDup.t",t) ) return NULL;
l = (l_utext)malloc((n*2)+2);
if ( !l ) return NULL;
return UTextNCopy(l,t,n);
}
////////////////////////////////////////////////////////////////////////////////
// Add text t at the text d end, text d must have enouf memory allocated
l_utext UTextCat ( l_utext d, l_utext t ) {
l_utext l = d;
if ( !DCkPt("UTextCat.d",d) || !DCkPt("UTextCat.t",t) ) return d;
while ( *d ) d++;
UTextCopy(d,t);
return l;
}
////////////////////////////////////////////////////////////////////////////////
// Transform text to upper case
l_utext UTextToUpper( l_utext d ){
l_utext l = d;
if ( !DCkPt("UTextToUpper.d",d) ) return 0;
while ( *d ){ *d = UToUpper(*d); d++; }
return l;
}
////////////////////////////////////////////////////////////////////////////////
// Transform text to lower case
l_utext UTextToLower( l_utext d ){
l_utext l = d;
if ( !DCkPt("UTextToUpper.d",d) ) return 0;
while ( *d ){ *d = UToLower(*d); d++; }
return l;
}
////////////////////////////////////////////////////////////////////////////////
l_short UToLower ( l_short c ) {
if ( c & 0xFF00 )
return c;
else
return tolower(c & 0xFF);
}
////////////////////////////////////////////////////////////////////////////////
l_short UToUpper ( l_short c ) {
if ( c & 0xFF00 )
return c;
else
return toupper(c & 0xFF);
}
////////////////////////////////////////////////////////////////////////////////
void InitUText ( void ) {
SYSEXPORT(UTextLen);
SYSEXPORT(UTextChr);
SYSEXPORT(UTextCompare);
SYSEXPORT(UTextNCompare);
SYSEXPORT(UTextCaseCompare);
SYSEXPORT(UTextNCaseCompare);
SYSEXPORT(UTextCopy);
SYSEXPORT(UTextNCopy);
SYSEXPORT(UTextDup);
SYSEXPORT(UTextNDup);
SYSEXPORT(UTextCat);
SYSEXPORT(UTextRChr);
SYSEXPORT(UTextSqNCaseCompare);
SYSEXPORT(UTextToUpper);
SYSEXPORT(UTextToLower);
SYSEXPORT(UToUpper);
SYSEXPORT(UToLower);
}
////////////////////////////////////////////////////////////////////////////////
Es geht mir dabei weniger um Unicode, vielmehr geht es mir um die Vorgehensweise, um Code aus C/C++, der mir als .a, .lib, .o vorliegt, in Freepascal zu verwenden. Aktuell habe ich für meinen Test eine .o Datei als statische Bibliothek vorligen, deren Funktionen ich nutzen möchte.
Ist die Vorgehensweise bei .a und .lib Dateien die gleiche oder sind da wieder andere Dinge zu beachten und einzustellen. Habe das User Handbuch zu Freepascal durchgelesen. Dort ist aber leider nichts zum Format der Funktionsnamen gesagt auf die ich zugreifen will.
Wer kann mir weiter helfen?