2012-01-01 4 views
8

मैं बीसीसी 55 के साथ sqlite3.c से sqlite3 डेटाबेस इंजन संकलित किया है निम्न आदेश का उपयोग कर उत्सर्जन:लिंक करना sqlite3.obj आगे uunsatisfied घोषणाओं त्रुटियों

bcc32.exe -jb -O2 -w- -K -c -6 -u- sqlite3.c 

उचित sqlite3.obj फ़ाइल उत्पन्न किया गया था। लेकिन एक बार मैं इस तरह मेरी डेल्फी आवेदन में लिंक करने का प्रयास करें:

unit unt_SQLite3; 

interface 

uses 
    Windows; 

implementation 

{$LINK 'sqlite3.obj'} 
end. 

मैं निम्नलिखित त्रुटियाँ मिलती है:

[DCC Error] E2065 Unsatisfied forward or external declaration: '__ftol' 
[DCC Error] E2065 Unsatisfied forward or external declaration: '__lldiv' 
[DCC Error] E2065 Unsatisfied forward or external declaration: '__llmod' 
[DCC Error] E2065 Unsatisfied forward or external declaration: '_localtime' 
[DCC Error] E2065 Unsatisfied forward or external declaration: '_strncmp' 
[DCC Error] E2065 Unsatisfied forward or external declaration: '_memset' 
[DCC Error] E2065 Unsatisfied forward or external declaration: '__llmul' 
[DCC Error] E2065 Unsatisfied forward or external declaration: '_malloc' 
[DCC Error] E2065 Unsatisfied forward or external declaration: '_free' 
[DCC Error] E2065 Unsatisfied forward or external declaration: '_realloc' 
[DCC Error] E2065 Unsatisfied forward or external declaration: '_memcpy' 
[DCC Error] E2065 Unsatisfied forward or external declaration: '__llumod' 
[DCC Error] E2065 Unsatisfied forward or external declaration: '__lludiv' 
[DCC Error] E2065 Unsatisfied forward or external declaration: '_memmove' 
[DCC Error] E2065 Unsatisfied forward or external declaration: '_memcmp' 
[DCC Error] E2065 Unsatisfied forward or external declaration: '__llshl' 
[DCC Error] E2065 Unsatisfied forward or external declaration: '__llshr' 
[DCC Error] E2065 Unsatisfied forward or external declaration: '_atol' 
[DCC Error] E2065 Unsatisfied forward or external declaration: '_strlen' 
[DCC Error] E2065 Unsatisfied forward or external declaration: '_qsort' 
[DCC Error] E2065 Unsatisfied forward or external declaration: '__llushr' 
[DCC Error] E2065 Unsatisfied forward or external declaration: '__turboFloat' 

क्यों बोर्लेन्ड सी ++ शुद्ध पास्कल में क्रम कार्यों को लागू करने की जरूरत है (या एएसएम)? क्या ओबीजे में सीधे जुड़े नहीं हो सकते हैं? उनमें से कुछ पहले ही System.pas में लागू किए गए हैं लेकिन फिर भी संकलक शिकायत करता है?

इस mysqlf कर के बजाय SynSQLite3 या DIXml का उपयोग कर के पीछे तर्कसंगत है निम्नलिखित:

  • SynSQLite3 3.7.8 का समर्थन करता है

  • SynSQLite3 छूट जाए (मैं नवीनतम 3.7.9 नहीं दिख रहा है) sqlite3_trace, sqlite_open_v2, आदि जैसे कुछ घोषणाओं

  • SynSQLite2 फलस्वरूप 20 000 कदम आपरेशनों में DIXml 2.4.0 से लगभग 18 गुना धीमी है

  • DISQLite3 भुगतान किया जाता है

  • DISQLite 2.4.0 तेज है 260ms में 20000 कदम संचालन करती है, लेकिन DXE2

  • DISQLite 3.0.0 और 3.1.0 समर्थन DXE2 कर समर्थन नहीं करता है, लेकिन लगभग 8 गुना धीमी कर रहे हैं 2.4.0

  • मैं बहुत उत्सुक लड़का हूं और हमेशा जितना संभव हो सके धातु के करीब कोड को कोड करने का प्रयास करता हूं।

  • SynSQLite3 और DISQLite3 डेवलपर्स के लिए कुडोस - वास्तव में अच्छा काम Doen अब तक

अंततः मैं SynSQLite3 चुनने समाप्त हो गया क्योंकि:

  1. यह है खुला स्रोत

  2. यह बहुत अच्छी तरह से प्रलेखित है

  3. मैं अपने आप को sqlite3.obj पुनः संकलित करें और विशेषताओं की आवश्यकता

  4. मैं अद्यतन 3.7.9 संस्करण से जुड़ा हुआ

  5. ठीक नवीनतम देखते 3.7 के साथ हो सकता है के लिए बस जरूरत संकलन स्विच छोड़ने के लिए कैसे सीखा .9 ओबीजे मैंने डीआईएसक्यूलाइट 3

  6. DISQLite3 लड़के के पास अपनी साइट पर एक ईमेल पता भी नहीं है (केवल एक मेलिंग सूची), जहां SynSQLite3 लोग उसी घंटे SO में जवाब देते हैं।किसी दूसरे पर एक lib चुनते समय यह समझ में आता है। प्रदर्शन और कीमत सबकुछ नहीं है।

SQLite3 Profile Results

पी.एस. मेरे sqlite3.obj डाउनलोड और परीक्षण here

+0

लिंकर। कंपाइलर उस परवाह नहीं करता है, लिंकर करता है। – OnTheFly

+0

@user no, यह संकलन समय है जब डीसीयू बनाया जा रहा है –

+0

@ डेविड हेफरन, असत्य। – OnTheFly

उत्तर

8

हमारे ओपन सोर्स लाइब्रेरी पर एक नज़र डालें। यह sqlite3.obj की स्थैतिक लिंकिंग लागू करता है, और SQLite3 आधिकारिक कोड (और सुविधाओं के नवीनतम संस्करण के साथ बनाए रखा जाता है - उदाहरण के लिए, SQLite3 वर्चुअल टेबल्स के विस्तारित उपयोग की अनुमति देने वाला यह एकमात्र ढांचा है)। आपको एक रैपर मिला है लेकिन उससे भी ज्यादा।

यहाँ कैसे हम .obj में स्रोत संकलन (एक FTS3, अन्य inclusing इसके बिना) है:

del sqlite3.obj 
\dev\bcc\bin\bcc32 -6 -O2 -c -d -DSQLITE_ENABLE_FTS3 -u- sqlite3.c 
copy sqlite3.obj sqlite3fts3.obj 
\dev\bcc\bin\bcc32 -6 -O2 -c -d -u- sqlite3.c 

फिर SynSQLite3.pas इकाई पर एक नज़र डालें। इसमें आवश्यक बाहरी फाइलों के कुछ शुद्ध पास्कल या एएसएम संस्करण शामिल हैं।

उदाहरण के लिए:

function _ftol: Int64; 
// Borland C++ float to integer (Int64) conversion 
asm 
    jmp [email protected] // FST(0) -> EDX:EAX, as expected by BCC32 compiler 
end; 

function _ftoul: Int64; 
// Borland C++ float to integer (Int64) conversion 
asm 
    jmp [email protected] // FST(0) -> EDX:EAX, as expected by BCC32 compiler 
end; 

function malloc(size: cardinal): Pointer; cdecl; { always cdecl } 
// the SQLite3 database engine will use the FastMM4/SynScaleMM fast heap manager 
begin 
    GetMem(Result, size); 
end; 

procedure free(P: Pointer); cdecl; { always cdecl } 
// the SQLite3 database engine will use the FastMM4 very fast heap manager 
begin 
    FreeMem(P); 
end; 

function realloc(P: Pointer; Size: Integer): Pointer; cdecl; { always cdecl } 
// the SQLite3 database engine will use the FastMM4/SynScaleMM very fast heap manager 
begin 
    result := P; 
    ReallocMem(result,Size); 
end; 

function memset(P: Pointer; B: Integer; count: Integer): pointer; cdecl; { always cdecl } 
// a fast full pascal version of the standard C library function 
begin 
    result := P; 
    FillChar(P^, count, B); 
end; 

procedure memmove(dest, source: pointer; count: Integer); cdecl; { always cdecl } 
// a fast full pascal version of the standard C library function 
begin 
    Move(source^, dest^, count); // move() is overlapping-friendly 
end; 

procedure memcpy(dest, source: Pointer; count: Integer); cdecl; { always cdecl } 
// a fast full pascal version of the standard C library function 
begin 
    Move(source^, dest^, count); 
end; 

function atol(P: pointer): integer; cdecl; { always cdecl } 
// a fast full pascal version of the standard C library function 
begin 
    result := GetInteger(P); 
end; 

var __turbofloat: word; { not used, but must be present for linking } 

// Borland C++ and Delphi share the same low level Int64 _ll*() functions: 

procedure _lldiv; 
asm 
    jmp [email protected]_lldiv 
end; 

procedure _lludiv; 
asm 
    jmp [email protected]_lludiv 
end; 

procedure _llmod; 
asm 
    jmp [email protected]_llmod 
end; 

procedure _llmul; 
asm 
    jmp [email protected]_llmul 
end; 

procedure _llumod; 
asm 
    jmp [email protected]_llumod 
end; 

procedure _llshl; 
asm 
    jmp [email protected]_llshl 
end; 

procedure _llshr; 
asm 
{$ifndef ENHANCEDRTL} // need this code for Borland/CodeGear default System.pas 
    shrd eax, edx, cl 
    sar  edx, cl 
    cmp  cl, 32 
    jl  @@Done 
    cmp  cl, 64 
    jge  @@RetSign 
    mov  eax, edx 
    sar  edx, 31 
    ret 
@@RetSign: 
    sar  edx, 31 
    mov  eax, edx 
@@Done: 
{$else} 
    // our customized System.pas didn't forget to put _llshr in its interface :) 
    jmp [email protected]_llshr 
{$endif} 
end; 

procedure _llushr; 
asm 
    jmp [email protected]_llushr 
end; 

function strlen(p: PAnsiChar): integer; cdecl; { always cdecl } 
// a fast full pascal version of the standard C library function 
begin // called only by some obscure FTS3 functions (normal code use dedicated functions) 
    result := SynCommons.StrLen(pointer(p)); 
end; 

function memcmp(p1, p2: pByte; Size: integer): integer; cdecl; { always cdecl } 
// a fast full pascal version of the standard C library function 
begin 
    if (p1<>p2) and (Size<>0) then 
    if p1<>nil then 
     if p2<>nil then begin 
     repeat 
      if p1^<>p2^ then begin 
      result := p1^-p2^; 
      exit; 
      end; 
      dec(Size); 
      inc(p1); 
      inc(p2); 
     until Size=0; 
     result := 0; 
     end else 
     result := 1 else 
    result := -1 else 
    result := 0; 
end; 

function strncmp(p1, p2: PByte; Size: integer): integer; cdecl; { always cdecl } 
// a fast full pascal version of the standard C library function 
var i: integer; 
begin 
    for i := 1 to Size do begin 
    result := p1^-p2^; 
    if (result<>0) or (p1^=0) then 
     exit; 
    inc(p1); 
    inc(p2); 
    end; 
    result := 0; 
end; 


function localtime(t: PCardinal): pointer; cdecl; { always cdecl } 
// a fast full pascal version of the standard C library function 
var uTm: TFileTime; 
    lTm: TFileTime; 
    S: TSystemTime; 
begin 
    Int64(uTm) := (Int64(t^) + 11644473600)*10000000; // unix time to dos file time 
    FileTimeToLocalFileTime(uTM,lTM); 
    FileTimeToSystemTime(lTM,S); 
    with atm do begin 
    tm_sec := S.wSecond; 
    tm_min := S.wMinute; 
    tm_hour := S.wHour; 
    tm_mday := S.wDay; 
    tm_mon := S.wMonth-1; 
    tm_year := S.wYear-1900; 
    tm_wday := S.wDayOfWeek; 
    end; 
    result := @atm; 
end; 

आप इस इकाई SQLite3 का सिर्फ एक स्थिर जोड़ने की तुलना में अधिक में मिल जाएगा। ध्यान दें कि भले ही इसका उपयोग हमारे मॉरमोट ओआरएम क्लाइंट-सर्वर ढांचे द्वारा किया जाता है, यह ओआरएम SQLite3 कक्षाओं का उपयोग करने के लिए आवश्यक है। this article for additional details देखें।

यदि आप हमारे स्रोत कोड भंडार (महान FOSILIL प्रोजेक्ट का उपयोग करके) में खो गए हैं, read this

+0

+1 मौजूदा कोड का उपयोग करने के लिए बहुत बेहतर है जहां यह फिट बैठता है। –

+0

आखिरकार मैंने sqlite3.c संस्करण 3.7.9 फ़ाइल को पुनः संकलित करने और SynSQLite3 में 3.7.8 sqlite3.obj फ़ाइल को प्रतिस्थापित करने के साथ समाप्त किया। इसने निष्पादन को डीआईएसक्यूलाइट 3 2.4.0 संस्करण के समान ही बनाया। प्रश्न में संलग्न प्रोफाइलिंग के साथ स्क्रीनशॉट। –

+0

वर्तमान संस्करण में आपूर्ति की गई sqlite3.obj फ़ाइलें पहले से ही 3.7.9 में हैं। मेरे उत्तर के अंत में [मैंने जो लिंक दिया था] देखें (http://synopse.info/fossil/wiki?name=Get+the+source)। प्रत्यक्ष डाउनलोड [यहां से] (http://synopse.info/files/sqlite3obj.7z)। यह स्नैपशॉट संस्करण है - आधिकारिक 1.15 अभी भी 3.7.8 का उपयोग कर रहा है। ओपन सोर्स पर आपकी रुचि के लिए बहुत बहुत धन्यवाद! यदि आप परियोजना में शामिल होना चाहते हैं, तो यूनिट को बढ़ाने के लिए कुछ कोड प्रतिबद्ध करते हैं, तो आप हमारे मंचों पर आपका स्वागत करते हैं। –

4

अद्यतन के लिए temporaly उपलब्ध है: आप अब तक SynSQLite3.pas साथ बेहतर रूप में अरनॉड ने सुझाव दिया हो जाएगा। हालांकि, मैं इस जवाब को यहां छोड़ रहा हूं क्योंकि यह कुछ चालों को दिखाता है जिनका उपयोग स्थिर लिंकिंग के दौरान अनुपस्थित निर्भरताओं को हल करने के लिए किया जा सकता है।


यहां क्या हो रहा है यह है कि .obj फ़ाइल विभिन्न सी रनटाइम फ़ंक्शंस पर निर्भर करती है जिन्हें आपके द्वारा प्रदान किया जाना आवश्यक है।

पहली बात यह है कि crtluses इकाई के खंड में $LINK निर्देश शामिल है। crtl इकाई में कई सी रनटाइम लाइब्रेरी फ़ंक्शंस के कार्यान्वयन होते हैं और इस उद्देश्य के लिए डिज़ाइन किया गया है।

हालांकि, जब आप ऐसा करते हैं, जबकि कुछ लापता निर्भरताओं का समाधान किया जाता है, तो बहुत अधिक दिखाई देते हैं।

Unsatisfied forward or external declaration: '_lldiv' 
Unsatisfied forward or external declaration: '_llmod' 
Unsatisfied forward or external declaration: 'localtime' 
Unsatisfied forward or external declaration: '_llmul' 
Unsatisfied forward or external declaration: 'InterlockedCompareExchange' 
Unsatisfied forward or external declaration: 'InitializeCriticalSection' 
Unsatisfied forward or external declaration: 'Sleep' 
Unsatisfied forward or external declaration: 'DeleteCriticalSection' 
Unsatisfied forward or external declaration: 'EnterCriticalSection' 
Unsatisfied forward or external declaration: 'LeaveCriticalSection' 
Unsatisfied forward or external declaration: '_llumod' 
Unsatisfied forward or external declaration: '_lludiv' 
Unsatisfied forward or external declaration: 'GetVersionExA' 
Unsatisfied forward or external declaration: 'MultiByteToWideChar' 
Unsatisfied forward or external declaration: 'WideCharToMultiByte' 
Unsatisfied forward or external declaration: 'AreFileApisANSI' 
Unsatisfied forward or external declaration: 'FormatMessageW' 
Unsatisfied forward or external declaration: 'LocalFree' 
Unsatisfied forward or external declaration: 'FormatMessageA' 
Unsatisfied forward or external declaration: 'SetFilePointer' 
Unsatisfied forward or external declaration: 'CloseHandle' 
Unsatisfied forward or external declaration: 'ReadFile' 
Unsatisfied forward or external declaration: 'WriteFile' 
Unsatisfied forward or external declaration: 'SetEndOfFile' 
Unsatisfied forward or external declaration: 'FlushFileBuffers' 
Unsatisfied forward or external declaration: 'GetFileSize' 
Unsatisfied forward or external declaration: 'LockFileEx' 
Unsatisfied forward or external declaration: 'LockFile' 
Unsatisfied forward or external declaration: 'UnlockFile' 
Unsatisfied forward or external declaration: 'UnlockFileEx' 
Unsatisfied forward or external declaration: 'UnmapViewOfFile' 
Unsatisfied forward or external declaration: 'CreateFileMappingA' 
Unsatisfied forward or external declaration: 'MapViewOfFile' 
Unsatisfied forward or external declaration: 'GetTempPathW' 
Unsatisfied forward or external declaration: 'GetTempPathA' 
Unsatisfied forward or external declaration: 'CreateFileW' 
Unsatisfied forward or external declaration: 'CreateFileA' 
Unsatisfied forward or external declaration: 'GetFileAttributesW' 
Unsatisfied forward or external declaration: 'DeleteFileW' 
Unsatisfied forward or external declaration: 'GetFileAttributesA' 
Unsatisfied forward or external declaration: 'DeleteFileA' 
Unsatisfied forward or external declaration: 'GetFileAttributesExW' 
Unsatisfied forward or external declaration: 'GetFullPathNameW' 
Unsatisfied forward or external declaration: 'GetFullPathNameA' 
Unsatisfied forward or external declaration: 'GetDiskFreeSpaceW' 
Unsatisfied forward or external declaration: 'GetDiskFreeSpaceA' 
Unsatisfied forward or external declaration: 'LoadLibraryW' 
Unsatisfied forward or external declaration: 'LoadLibraryA' 
Unsatisfied forward or external declaration: 'GetProcAddress' 
Unsatisfied forward or external declaration: 'FreeLibrary' 
Unsatisfied forward or external declaration: 'GetSystemTime' 
Unsatisfied forward or external declaration: 'GetCurrentProcessId' 
Unsatisfied forward or external declaration: 'GetTickCount' 
Unsatisfied forward or external declaration: 'QueryPerformanceCounter' 
Unsatisfied forward or external declaration: 'GetSystemTimeAsFileTime' 
Unsatisfied forward or external declaration: 'GetSystemInfo' 
Unsatisfied forward or external declaration: '_llshl' 
Unsatisfied forward or external declaration: '_llushr' 

इनमें से कई बस Windows API कार्य हैं और आसानी से अपने उपयोग करता है खंड के Windows जोड़कर हल किया जा सकता।

इस बिंदु आप निम्नलिखित के साथ छोड़ दिया जाता है पर:

Unsatisfied forward or external declaration: '_lldiv' 
Unsatisfied forward or external declaration: '_llmod' 
Unsatisfied forward or external declaration: 'localtime' 
Unsatisfied forward or external declaration: '_llmul' 
Unsatisfied forward or external declaration: '_llumod' 
Unsatisfied forward or external declaration: '_lludiv' 
Unsatisfied forward or external declaration: '_llshl' 
Unsatisfied forward or external declaration: '_llushr' 

इन आप की जरूरत को हल करने के लिए या तो:

  1. लिंक एक और .obj लापता निर्भरता युक्त फ़ाइल।
  2. उसी इकाई में डेल्फी कोड में लापता निर्भरता को लागू करें जिसमें $LINK है।

मुझे वास्तव में यह सुनिश्चित नहीं है कि ये कार्य क्या करते हैं ताकि आपके आगे कुछ और काम हो। मेरा अनुमान है कि ये कार्य 64 बिट पूर्णांक अंकगणित दिनचर्या हैं। आप शायद 64 बिट अंकगणितीय परिचालन करने के लिए सी के छोटे बिट्स लिखकर इसे इंजीनियर कर सकते हैं। फिर बीसीसी 32 के साथ संकलित करें और आउटपुट को asm के रूप में देखें। संभवतः bcc32 में asm उत्सर्जित करने की क्षमता है। या आप सिर्फ डेल्फी इकाई से लिंक कर सकते हैं और देख सकते हैं कि उपरोक्त में से कौन से फ़ंक्शन आपके सी कोड में उपयोग किए जाने वाले संचालन से मेल खाते हैं।

msvcrt.dll में से localtime खींच सकता है, हमेशा सी रनटाइम कार्यों को खोने के लिए उपयोगी फॉल-बैक विकल्प। वास्तव में, crtl इकाई का वर्तमान कार्यान्वयन यही है, इसलिए यदि आप crtl का उपयोग करने जा रहे हैं तो आपको localtime भी इसी तरह मिल सकता है।


अरनॉड से कुछ कोड उधार है, तो निम्न इकाई सफलतापूर्वक संकलित:

unit sqlite3; 

interface 

implementation 

uses 
    crtl, Windows; 

{$L c:\desktop\sqlite3.obj} 

procedure _lldiv; 
asm 
    jmp [email protected]_lldiv 
end; 

procedure _llmod; 
asm 
    jmp [email protected]_llmod 
end; 

procedure _llmul; 
asm 
    jmp [email protected]_llmul 
end; 

procedure _llumod; 
asm 
    jmp [email protected]_llumod 
end; 

procedure _lludiv; 
asm 
    jmp [email protected]_lludiv 
end; 

procedure _llshl; 
asm 
    jmp [email protected]_llshl 
end; 

procedure _llushr; 
asm 
    jmp [email protected]_llushr 
end; 

procedure localtime; cdecl; external 'msvcrt.dll'; 

end. 

ध्यान दें कि आप पैरामीटर सूची प्रदान करने के लिए, इन कार्यों में से किसी के लिए सम्मेलन आदि बुला के बाद से हम कर रहे हैं की जरूरत नहीं है उन्हें यहां लागू नहीं कर रहा है। प्रत्येक मामले में कोड केवल कार्यान्वयन का प्रतिनिधित्व करता है।

हालांकि, यह अभी भी sqlite3 फ़ंक्शंस घोषित करने के लिए कोड खो रहा है। और भी, मैंने परीक्षण करने का भी प्रयास नहीं किया है कि यह काम करता है या नहीं। सफल संकलन केवल पहला कदम है।

मैं दृढ़ता से अनुशंसा करता हूं कि आप उस कोड का उपयोग करें जो अर्नुद आपको निर्देशित करता है यदि आप स्थिर लिंकिंग का उपयोग करना चाहते हैं। इस कोड में स्पष्ट रूप से बहुत अधिक उपयोग और परीक्षण है और आप इससे भी लाभ उठा सकते हैं।


स्टेटिक जोड़ने सुविधाजनक तैनाती के लिए करता है, लेकिन एक DLL के खिलाफ गतिशील जोड़ने ज्यादा हासिल करने के लिए सरल है।

+0

वे फ़ंक्शन 64-बिट पूर्णांक (हस्ताक्षरित और "यू" nsigned) के लिए सहायक हैं।जीसीसी सिस्टम पर ऐसे कार्य libgcc में हैं। संभवतः एक msvc ऑब्जेक्ट फ़ाइल से स्थिर रूप से लिंक करने की आवश्यकता है। –

+0

मैंने दुर्घटना से आपकी प्रतिक्रिया को उखाड़ फेंक दिया हो सकता है। अगर यह मैं था तो कृपया मुझे सही करने के लिए बताएं। अगर यह मैं नहीं था तो कृपया इस टिप्पणी को हटा दें। –

+1

डेल्फी XE2 में System.Win.Crtl.pas नाम के तहत एक छोटी टिप्पणी सीआरटीएल इकाई उपलब्ध है और डिफ़ॉल्ट रूप से सी: \ प्रोग्राम फ़ाइलें \ Embarcadero \ RAD स्टूडियो \ 9.0 \ स्रोत \ rtl \ common पर स्रोत कोड के साथ उपलब्ध है स्थापना पथ का उपयोग किया जाता है। पिछले एक्सई संस्करण में यह केवल crtl.dcu के रूप में उपलब्ध था। –

संबंधित मुद्दे