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

用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
e
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完成全部的編譯連接過程,並記錄編譯的全部過程, c++

步驟是: sql

(1)編譯sqlite 數據庫

gcc -c sqlite3.c windows

ar crvs libsqlite3.a sqlite3.o xcode

(2)編譯libodb app

./configure & make 便可 post

(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
ui


(4)編譯libodb-example url

./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

相關文章
相關標籤/搜索