圖文說明Visual Studio 2013編譯libpqxx步驟以及常見編譯錯誤

來源:互聯網
上載者:User

標籤:

編譯步驟(x86版本)


1.下載並安裝postgresql,點擊進入。下載介面如下:




目前最新版本是9.5.1,我下載了 Win x86-32 的最新版本。安裝後目錄如下:





2.下載並解壓縮libpqxx,點擊進入。下載介面如下:




目前最新版本是4.0.1,我下載了libpqxx-4.0.1.tar.gz 壓縮包。解壓後目錄如下:





3.編譯環境準備。(安裝或解壓路徑請以實際的為準,本文路徑僅供參考)

  • 進入libpqxx的解壓路徑 D:\Program Files (x86)\libpqxx-4.0.1\win32 ,將該路徑下的common-sample檔案另存新檔common檔案

  • 開啟並刪除上述common檔案原有全部內容,然後將以下代碼複製到common檔案中並儲存。
       *注意:複製後請將第53行 PGSQLSRC 的值修改為你實際安裝postgresql的根目錄,同時根目錄兩端的雙引號不能省略!
# Common options for Visual C++ makefiles to build libpqxx and its regression# test.# THE ORIGINAL OF THIS FILE IS CALLED common-sample; DON'T EDIT THE ORIGINAL or# you may lose your changes when you upgrade your libpqxx sources.# Instead, copy "common-sample" to "common" and edit just the file "common".# Caution: on Windows, some environments, such as the "make" that comes with# Visual C++, expect you to use backslashes as path separators (for example,# "C:\src\libpqxx") whereas others like MinGW want you to use more conventional# slashes (as in "C:/src/libpqxx").# Standard library namespace.# There are only two reasons why you might want to change this:## 1. Your compiler doesn't define the standard library in the "std" namespace# but in the global namespace, in which case PGSTD should be the empty string.# However, a compiler with that problem is not likely to be good enough to# compile libpqxx.## 2. You are using a third-party standard library implementation such as# STLport, which lives in another namespace to avoid clashes with the# implementation that came with the compiler.## In the latter case, PGSTD must be set to the namespace used by your preferred# implementation.  In all other cases, just leave this set to "std".STD="std"# If you are using a 3rd-party STL like STLport, remember to check your path# and be sure the STLport is included before the MSVC includes. VCVARS32.BAT# doesn't know anything about the directories as defined in the IDE. I use## set INCLUDE=\Utility\Code\STLport-4.5\stlport;%INCLUDE%## ...and set STD to "_STL".# Depending on your STL library min/max need to be defined.  Using STLport# there is no need for libpqxx to redefine these for me.# The next line gives us the directory under which all PostgreSQL include# directories, DLLs and LIB files can be found.## If you built PostgreSQL from source, this is probably the only line you# will need to change.## If you installed PostgreSQL using the One Click Installer from EnterpriseDB,# comment out the following line and uncomment the line after it.## Edit the appropriate line to match your specific installation.#PGSQLSRC="C:\Sources\postgresql-9.1.1\src"PGSQLSRC="D:\Program Files (x86)\PostgreSQL\9.5"# This is the directory where the Postgres header files, e.g. postgres_ext.h,# are found.PGSQLINC=$(PGSQLSRC)\include# This is the directory where the libpq header files, e.g. libpq-fe.h,# are found.  If you used the One Click Installer, comment out the next line# and uncomment the one following it:#LIBPQINC=$(PGSQLSRC)\interfaces\libpqLIBPQINC=$(PGSQLSRC)\include# This is the directory where the release build of the libpq DLL# and its corresponding LIB file are found, as well as the names of# those two files.## If you installed PostgreSQL using the One Click Installer from EnterpriseDB,# comment out the next three lines and uncomment the following three:#LIBPQPATH=$(PGSQLSRC)\interfaces\libpq\Release#LIBPQDLL=libpq.dll#LIBPQLIB=libpqdll.libLIBPQPATH=$(PGSQLSRC)\libLIBPQDLL=libpq.dllLIBPQLIB=libpq.lib# This is the directory where the debug build of the libpq DLL# and its corresponding LIB file are found, as well as the names of# those two files.## NOTE: If you don't have access to a debug build of libpq, just# provide the same information as above here. The debug builds of# libpqxx will reference the release version of libpq, which will# only limit your ability to debug libpq sources but otherwise should# work just fine.## If you installed PostgreSQL using the One Click Installer from EnterpriseDB,# comment out the next three lines and uncomment the following three.#LIBPQDPATH=$(PGSQLSRC)\interfaces\libpq\Debug#LIBPQDDLL=libpqd.dll#LIBPQDLIB=libpqddll.libLIBPQDPATH=$(PGSQLSRC)\libLIBPQDDLL=libpq.dllLIBPQDLIB=libpq.lib
  • 進入libpqxx的解壓路徑 D:\Program Files (x86)\libpqxx-4.0.1\config\sample-headers\compiler\VisualStudio2010\pqxx ,將該路徑下的全部標頭檔拷貝到目錄 D:\Program Files (x86)\libpqxx-4.0.1\include\pqxx中
  • 進入libpqxx的解壓路徑 D:\Program Files (x86)\libpqxx-4.0.1\config\sample-headers\libpq\9.0\pqxx ,將該路徑下的全部標頭檔拷貝到目錄 D:\Program Files (x86)\libpqxx-4.0.1\include\pqxx中
  • 進入libpqxx的解壓路徑 D:\Program Files (x86)\libpqxx-4.0.1\src ,開啟 largeobject.cxx 源檔案,在第34行加入標頭檔#include <algorithm>
              

4.開始編譯。(安裝或解壓路徑請以實際的為準,本文路徑僅供參考)
  • 在開始菜單選擇Visual Studio 2013的開發人員命令提示工具,並以管理員方式運行,然後直接運行命令:vcvars32.bat
              
  • 將命令提示工具定位到 libpqxx 的解壓路徑: D:\Program Files (x86)\libpqxx-4.0.1
       
  • 最後在命令提示工具中直接運行命令:nmake /f win32/vc-libpqxx.mak ALL,即可開始編譯。
          
  • 編譯成功後,所產生的靜態庫以及動態庫,包括DEBUG版本和RELEASE版本,全部都在如下目錄中:
             


常見編譯錯誤
  • 提示缺少標頭檔。
              請查看common檔案中的 PGSQLSRC 的值是否已經修改為你實際安裝postgresql的根目錄,並確保已經按照上述步驟拷貝全部所需標頭檔。
  • 提示類似錯誤:error U1077: ‘copy‘ : return code ‘0x1‘。
             請查看common檔案中的 PGSQLSRC 的值是否已經修改為你實際安裝postgresql的根目錄,並確保根目錄兩端的雙引號存在。
  • 提示類似錯誤: min() 或者 max() 不是std 的標準函數。
             請確保 largeobject.cxx 源檔案第34行已經加入標頭檔 #include <algorithm>。
  • 提示一堆無法解析的外部函數。
              如果編譯的是 x86 版本的 libpqxx ,請確保安裝的 postgresql 也是 x86 版本的;同樣 x64 版本的也是一個道理。

關於 libpgxx 更多的編譯選項及編譯說明,請參照 libpqxx 解壓路徑 Win32 目錄下的common,INSTALL.TXT 以及 vc-libpgxx.mak 等檔案。

圖文說明Visual Studio 2013編譯libpqxx步驟以及常見編譯錯誤

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.