2012-07-08 94 views
4

我編寫了使用<boost/thread/locks.hpp>的項目,我將include目錄添加到Additional Include directorieslib文件夾鏈接器。但是,當我嘗試建立的解決方案,錯誤:使用boost編譯時出錯

Error 1 error LNK1104: cannot open file 'libboost_thread-vc100-mt-sgd-1_50.lib'

我搜索在lib目錄下這個文件,但這個名字在lib目錄中沒有文件。我找到類似名稱的文件libboost_thread-vc100-mt-gd-1_50

我做錯了什麼?

+0

我想你已經安裝了庫或建立他們納入到你的項目? – mathematician1975 2012-07-08 16:06:49

+0

我建立了他們的引導http://www.boost.org/doc/libs/1_50_0/doc/html/bbv2/installation.html – Robert 2012-07-08 16:08:01

+0

您使用的是什麼操作系統和編譯器? – mathematician1975 2012-07-08 16:08:20

回答

7

您的問題似乎是非常相似的一個在this question。根據命名規則描述here鏈接器要使用庫,並且你有磁帶庫之間的唯一區別是,前者靜態鏈接到C++標準庫和編譯器運行支持庫。我能想到的兩種方法來解決這個問題:

  1. 獲取連接要
    一個圖書館。如果您使用了boostpro安裝程序:

    Make sure you check the box for Multithreaded debug, static runtime (I would recommend you mark them all)

    b。如果自己建庫:

    Open a console window
    Change directory to your boost root
    The following command builds the required library:
    b2 toolset=msvc-10.0 --with-thread address-model=64 variant=debug link=static runtime-link=static runtime-debugging=on stage
    (I would recommend using:
    b2 toolset=msvc-10.0 address-model=64 --build-type=complete stage)

  2. 讓鏈接器可以使用庫您想
    一個。使自動鏈接使用共享庫

    You can define BOOST_THREAD_DYN_LINK (to affect only the thread library) or BOOST_ALL_DYN_LIB (to affect all the boost libraries) before the inclusion of the header files (or preferably in your VC project preprocessor settings). This would make the linker try to use the library boost_thread-vc100-mt-gd-1_50.lib (note that the lib- preffix is missing).

    b。禁用自動鏈接

    You can define BOOST_ALL_NO_LIB and then add the exact name of your library in your linker options

+0

你的意思是這條命令: 1)bootstrap.bat 2)B2安裝--prefix = PREFIX運行時鏈接=靜態 ? – Eyalk 2012-12-15 17:59:54

+0

@Eyalk由羅伯特,你似乎被引用的評論的鏈接頁面介紹了Boost.Build二進制文件的安裝。在這一步中,你不應該添加'runtime-link = static'。一旦你安裝了Boost.Build,你需要構建Boost庫。在這個步驟中,您需要將其添加到您的命令中。我會嘗試編輯答案以使其更清楚。 – 2012-12-15 19:05:18