我想要得到一個基本的「hello world」sqlite3程序進入cygwin。我最初從setup.exe安裝它,但是當我運行程序時,出現鏈接器錯誤,例如「對_sqlite3_open'的未定義引用」。 I編譯時使用-lsqlite3開關。cygwin SQLite3導致鏈接器錯誤
的位置是在這裏:
$ ls /usr/lib/ | grep sql
libsqlite3.a
libsqlite3.dll.a
libsqlite3.la
然後我試圖下載sqlite3的源和手動編譯它,但我得到了同樣的錯誤。它安裝到/ usr/local/lib目錄
$ ls /usr/local/lib/ | grep sql
libsqlite3.a
libsqlite3.dll.a
libsqlite3.la
我還是讓這些鏈接器錯誤,雖然,我似乎無法弄清楚如何解決它?
$ gcc -lsqlite3 test.cc
test.cc: In function ‘int main()’:
test.cc:41: warning: deprecated conversion from string constant to ‘char*’
/tmp/ccKA3ZFa.o:test.cc:(.text+0x2d): undefined reference to `_sqlite3_open'
/tmp/ccKA3ZFa.o:test.cc:(.text+0x41): undefined reference to `_sqlite3_errmsg'
/tmp/ccKA3ZFa.o:test.cc:(.text+0xb6): undefined reference to `_sqlite3_prepare_v2'
/tmp/ccKA3ZFa.o:test.cc:(.text+0xca): undefined reference to `_sqlite3_errmsg'
/tmp/ccKA3ZFa.o:test.cc:(.text+0x10e): undefined reference to `_sqlite3_step'
/tmp/ccKA3ZFa.o:test.cc:(.text+0x12a): undefined reference to `_sqlite3_column_bytes'
/tmp/ccKA3ZFa.o:test.cc:(.text+0x140): undefined reference to `_sqlite3_column_text'
/tmp/ccKA3ZFa.o:test.cc:(.eh_frame+0x11): undefined reference to `___gxx_personality_v0'
collect2: ld returned 1 exit status
感謝您的幫助,您可以提供。乾杯:)
Derp,它似乎是放置。也許這是一個cygwin的東西?我似乎沒有記得之前有一個安置問題:)謝謝!我試圖弄清楚爲什麼它沒有連接哈哈。 (是的,你是對的,這是一個C++程序,只是一個錯字) – Jordan 2011-04-20 02:33:05
@Jordan,我不認爲它只限於CygWin。完全相同的文本出現在我的Ubuntu 10.04盒子的手冊頁中。我想這可能是因爲它是CygWin下的gcc3,但是Ubuntu中的gcc3也是gcc4。我在_many_系統上曾經遇到過這個問題_many_次,所以我認爲這很常見。我們甚至曾經引入了一個kludge來修改庫列表以擺脫這個問題 - 它包括複製列表的次數與列表中的單個庫相同:所以'-la'或'-la -lb -la - Ib'或'-la -lb -lc -la -lb -lc -la -lb -lc'等等。 – paxdiablo 2011-04-20 02:38:55