ODB(C++ ORM)用Mingw的完整編譯過程

來源:互聯網
上載者:User

標籤:tag   make   str   xcode   ref   except   樣本   exce   版本   

用mingw官方的GCC4.7.2編譯libodb後,並用odb compiler對hello樣本產生odb的"包裹"代碼,編譯連結總是不能通過,下面是編譯example/hello報錯的資訊如下: 
libodb-sqlite-2.3.0/odb/sqlite -o driver.exe driver.o person-odb.o  -lodb-sqlite -lboost_date_time -lboost_system -lodb 
libtool: link: g++ -I/d/odb-sqlite/sqlite-amalgamation-3080200 -mthreads -o .libs/driver.exe driver.o person-odb.o  -L/d/odb-sqlite/sqlite-amalgamation-3080200 -L/d/odb-sqlite/libodb-2.3.0/odb -L/d/odb-sqlite/libodb-sqlite-2.3.0/odb/sqlite  /d/odb-sqlite/libodb-sqlite-2.3.0/odb/sqlite/.libs/libodb-sqlite.a -lsqlite3 -lboost_date_time -lboost_system /d/odb-sqlite/libodb-2.3.0/odb/.libs/libodb.dll.a -mthreads -L/usr/local/lib 
driver.o:driver.cxx:(.text$_ZN3odb6sqlite11query_paramC2EPKv[__ZN3odb6sqlite11qu 
ery_paramC2EPKv]+0x1b): undefined reference to `_imp___ZTVN3odb6sqlite11query_pa 
ramE‘ 
driver.o:driver.cxx:(.text$_ZN3odb6sqlite10query_baseC1EPKcS3_[__ZN3odb6sqlite10 
query_baseC1EPKcS3_]+0x5f): undefined reference to `_imp___ZN3odb6sqlite10query_ 
base6appendEPKcS3_‘ 
d:/lbe/mingw/bin/../lib/gcc/mingw32/4.7.2/../../../../mingw32/bin/ld.exe: driver 
.o: bad reloc address 0x5f in section `.text$_ZN3odb6sqlite10query_baseC1EPKcS3_ 
[__ZN3odb6sqlite10query_baseC1EPKcS3_]‘ 
collect2.exe: error: ld returned 1 exit status 
make[1]: *** [driver.exe] Error 1 
make[1]: Leaving directory `/d/lbe/oscode/odb-sqlite/odb-examples-2.3.0/hello‘ 
make: *** [all] Error 2 

嘗試多種方法不能解決,發現在odb compiler目錄中內建一個mingw編譯器,這個編譯版本是GCC4.7.3的,gcc -v的輸出資訊如下: 
Using built-in specs. 
COLLECT_GCC=D:\wxwidgets\wxcode\odb-2.3.0-i686-windows\mingw\bin\gcc 
.exe 
COLLECT_LTO_WRAPPER=d:/wxwidgets/wxcode/odb-2.3.0-i686-windows/mingw 
/bin/../libexec/gcc/i686-w64-mingw32/4.7.3/lto-wrapper.exe 
Target: i686-w64-mingw32 
Configured with: ../gcc/configure --host i686-w64-mingw32 --target i686-w64-ming 
w32 --prefix=/mingw --with-sysroot=/mingw --enable-languages=c,c++ --enable-shar 
ed --enable-threads=posix --disable-libssp --disable-libgomp --disable-graphite 
--disable-multilib --enable-libstdcxx-time --enable-fully-dynamic-string --disab 
le-dw2-exceptions --enable-sjlj-exceptions --disable-libstdcxx-pch --disable-lib 
stdcxx-debug --disable-rpath --disable-win32-registry --disable-nls --disable-we 
rror --with-pkgversion=‘ODB special‘ --with-bugurl=http://www.codesynthesis.com/ 
products/odb/ --enable-static-plugin --with-stage1-libs=libplugin-stub.a CFLAGS= 
-O2 CXXFLAGS=-O2 LDFLAGS=-s 
Thread model: posix 
gcc version 4.7.3 20130209 (prerelease) (ODB special) 

而Mingw GCC4.7.2的gcc -v的輸出資訊如下: 


Using built-in specs. 
COLLECT_GCC=d:\mingw\bin\gcc.exe 
COLLECT_LTO_WRAPPER=d:/mingw/bin/../libexec/gcc/mingw32/4.7.2/lto-wrapper.ex 

Target: mingw32 
Configured with: ../gcc-4.7.2/configure --enable-languages=c,c++,ada,fortran,obj 
c,obj-c++ --disable-sjlj-exceptions --with-dwarf2 --enable-shared --enable-libgo 
mp --disable-win32-registry --enable-libstdcxx-debug --disable-build-poststage1- 
with-cxx --enable-version-specific-runtime-libs --build=mingw32 --prefix=/mingw 
Thread model: win32 
gcc version 4.7.2 (GCC) 


現在則使用odb compiler內建的mingw完成所有的編譯連結過程,並記錄編譯的所有過程,

步驟是:

(1)編譯sqlite

gcc -c sqlite3.c

ar crvs libsqlite3.a sqlite3.o

(2)編譯libodb

./configure & make 即可

(3)編譯libodb-sqlite

./configure CXXFLAGS=-I/d/odb-sqlite/sqlite-amalgamation-3080200 LDFLAGS=-L/d/odb-sqlite/sqlite-amalgamation-3080200 --with-libodb=/d/odb-sqlite/libodb-2.3.0

 

(4)編譯libodb-example

./configure CXXFLAGS=-I/d/odb-sqlite/sqlite-amalgamation-3080200 LDFLAGS=-L/d/odb-sqlite/sqlite-amalgamation-3080200 --with-libodb=/d/odb-sqlite/libodb-2.3.0 ODB=/d/odb-2.3.0-i686-windows/bin/odb.exe --with-database=sqlite --with-libodb-sqlite=/d/odb-sqlite/libodb-sqlite-2.3.0

make
在example/hello下啟動測試的程式,並用SqliteAdmin這個軟體查看資料庫檔案中的資料,是正確的.

$ ./driver --database hello.db --create
Hello, John Doe!
Hello, Jane Doe!


count  : 3
min age: 31
max age: 33

ODB(C++ ORM)用Mingw的完整編譯過程

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.