2011-05-18 101 views
1

預覽時鏈接錯誤:試圖靜態鏈接VS9當鏈接錯誤快遞C++ POCO LIB試圖靜態鏈接VS9表達

我試圖在Visual Studio 2008來編譯一個簡單的快捷應用基於Poco::Process。但我得到鏈接錯誤。

這裏被配置爲控制檯應用程序我簡單的代碼:

#include "Poco/Foundation.h" 
#include "Poco/Process.h" 
#include "Poco/Pipe.h" 
#include "Poco/PipeStream.h" 
using Poco::Process; 
using Poco::ProcessHandle; 
using Poco::Pipe; 
using Poco::PipeInputStream; 
using Poco::PipeOutputStream; 

int main(int argc, char** argv) 
{ 
    std::string cmd = "hostname"; 
    std::vector<std::string> args; 
    args.push_back("--help"); 

    ProcessHandle ph = Process::launch(cmd, args); 
    int rc = ph.wait(); 

    return 0; 
} 

我增加了預處理標誌:

Foundation_EXPORTS 
POCO_STATIC 
PCRE_STATIC 

而且我與鏈接:

PocoFoundationmt.lib 

與多-threaded調試DLL(/ MDd)定義,但我收到此鏈接錯誤:

1>poco_process.cpp 
1>Linking... 
1>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::~basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(void)" ([email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]) already defined in PocoFoundationmt.lib(Process.obj) 
1>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(char const *)" ([email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@Z) already defined in PocoFoundationmt.lib(Process.obj) 
1>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" ([email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@@Z) already defined in PocoFoundationmt.lib(Bugcheck.obj) 
1>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: class std::locale::facet * __thiscall std::locale::facet::_Decref(void)" ([email protected]@[email protected]@@[email protected]) already defined in PocoFoundationmt.lib(Bugcheck.obj) 
1>libcpmt.lib(ios.obj) : error LNK2005: "public: static void __cdecl std::ios_base::_Addstd(class std::ios_base *)" ([email protected][email protected]@@[email protected]@Z) already defined in msvcprtd.lib(MSVCP90D.dll) 
1>libcpmt.lib(ios.obj) : error LNK2005: "private: static void __cdecl std::ios_base::_Ios_base_dtor(class std::ios_base *)" ([email protected][email protected]@@[email protected]@Z) already defined in msvcprtd.lib(MSVCP90D.dll) 
1>libcpmt.lib(locale0.obj) : error LNK2005: "void __cdecl _AtModuleExit(void (__cdecl*)(void))" ([email protected]@[email protected]) already defined in msvcprtd.lib(locale0_implib.obj) 
1>libcpmt.lib(locale0.obj) : error LNK2005: "private: static class std::locale::_Locimp * __cdecl std::locale::_Getgloballocale(void)" (?_Getgloballocale[email protected]@[email protected]@[email protected]@XZ) already defined in msvcprtd.lib(MSVCP90D.dll) 
1>libcpmt.lib(locale0.obj) : error LNK2005: __Fac_tidy already defined in msvcprtd.lib(locale0_implib.obj) 
1>libcpmt.lib(locale0.obj) : error LNK2005: "private: static void __cdecl std::locale::facet::facet_Register(class std::locale::facet *)" ([email protected]@[email protected]@@[email protected]@Z) already defined in msvcprtd.lib(locale0_implib.obj) 
1>libcpmt.lib(locale0.obj) : error LNK2005: "public: char const * __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::c_str(void)const " ([email protected][email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@QBEPBDXZ) already defined in msvcprtd.lib(MSVCP90D.dll) 
1>libcpmt.lib(locale0.obj) : error LNK2005: "public: static void __cdecl std::_Locinfo::_Locinfo_dtor(class std::_Locinfo *)" ([email protected][email protected]@@[email protected]@Z) already defined in msvcprtd.lib(MSVCP90D.dll) 
1>libcpmt.lib(locale0.obj) : error LNK2005: "private: static class std::locale::_Locimp * __cdecl std::locale::_Init(void)" ([email protected]@[email protected]@[email protected]@XZ) already defined in msvcprtd.lib(MSVCP90D.dll) 
1>libcpmt.lib(locale0.obj) : error LNK2005: "public: static void __cdecl std::_Locinfo::_Locinfo_ctor(class std::_Locinfo *,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" ([email protected][email protected]@@[email protected][email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@Z) already defined in msvcprtd.lib(MSVCP90D.dll) 
1>libcpmt.lib(xlock.obj) : error LNK2005: "public: __thiscall std::_Lockit::_Lockit(int)" ([email protected]@@[email protected]@Z) already defined in msvcprtd.lib(MSVCP90D.dll) 
1>libcpmt.lib(xlock.obj) : error LNK2005: "public: __thiscall std::_Lockit::~_Lockit(void)" ([email protected]@@[email protected]) already defined in msvcprtd.lib(MSVCP90D.dll) 
1>LIBCMT.lib(invarg.obj) : error LNK2005: __invoke_watson already defined in MSVCRTD.lib(MSVCR90D.dll) 
1>LIBCMT.lib(invarg.obj) : error LNK2005: __invalid_parameter already defined in MSVCRTD.lib(MSVCR90D.dll) 
1>LIBCMT.lib(setlocal.obj) : error LNK2005: __configthreadlocale already defined in MSVCRTD.lib(MSVCR90D.dll) 
1>LIBCMT.lib(lconv.obj) : error LNK2005: _localeconv already defined in MSVCRTD.lib(MSVCR90D.dll) 
1>LIBCMT.lib(tidtable.obj) : error LNK2005: __encode_pointer already defined in MSVCRTD.lib(MSVCR90D.dll) 
1>LIBCMT.lib(tidtable.obj) : error LNK2005: __decode_pointer already defined in MSVCRTD.lib(MSVCR90D.dll) 
1>LIBCMT.lib(crt0dat.obj) : error LNK2005: __amsg_exit already defined in MSVCRTD.lib(MSVCR90D.dll) 
1>LIBCMT.lib(crt0dat.obj) : error LNK2005: __initterm_e already defined in MSVCRTD.lib(MSVCR90D.dll) 
1>LIBCMT.lib(crt0dat.obj) : error LNK2005: _exit already defined in MSVCRTD.lib(MSVCR90D.dll) 
1>LIBCMT.lib(crt0dat.obj) : error LNK2005: __exit already defined in MSVCRTD.lib(MSVCR90D.dll) 
1>LIBCMT.lib(crt0dat.obj) : error LNK2005: __cexit already defined in MSVCRTD.lib(MSVCR90D.dll) 
1>LIBCMT.lib(mlock.obj) : error LNK2005: __unlock already defined in MSVCRTD.lib(MSVCR90D.dll) 
1>LIBCMT.lib(mlock.obj) : error LNK2005: __lock already defined in MSVCRTD.lib(MSVCR90D.dll) 
1>LIBCMT.lib(winxfltr.obj) : error LNK2005: __XcptFilter already defined in MSVCRTD.lib(MSVCR90D.dll) 
1>LIBCMT.lib(crt0init.obj) : error LNK2005: ___xi_a already defined in MSVCRTD.lib(cinitexe.obj) 
1>LIBCMT.lib(crt0init.obj) : error LNK2005: ___xi_z already defined in MSVCRTD.lib(cinitexe.obj) 
1>LIBCMT.lib(crt0init.obj) : error LNK2005: ___xc_a already defined in MSVCRTD.lib(cinitexe.obj) 
1>LIBCMT.lib(crt0init.obj) : error LNK2005: ___xc_z already defined in MSVCRTD.lib(cinitexe.obj) 
1>LIBCMT.lib(hooks.obj) : error LNK2005: "void __cdecl terminate(void)" ([email protected]@YAXXZ) already defined in MSVCRTD.lib(MSVCR90D.dll) 
1>LIBCMT.lib(crt0.obj) : error LNK2005: _mainCRTStartup already defined in MSVCRTD.lib(crtexe.obj) 
1>LIBCMT.lib(errmode.obj) : error LNK2005: ___set_app_type already defined in MSVCRTD.lib(MSVCR90D.dll) 
1>LINK : warning LNK4098: defaultlib 'MSVCRTD' conflicts with use of other libs; use /NODEFAULTLIB:library 
1>LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library 
1>D:\cpp\libs\poco-1.4.1p1\poco-1.4.1p1\Foundation\Debug\poco_process.exe : fatal error LNK1169: one or more multiply defined symbols found 
1>Build log was saved at "file://d:\cpp\libs\poco-1.4.1p1\poco-1.4.1p1\poco_process\Debug\BuildLog.htm" 
1>poco_process - 38 error(s), 2 warning(s) 
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== 

什麼即時做錯了嗎?
感謝您的幫助

+1

你確定要'Foundation_EXPORTS'預處理器標誌嗎?編譯DLL時通常使用EXPORTS樣式標誌。 – Chadwick 2011-05-18 20:42:06

回答

1

您正在使用的庫「PocoFoundationmt.lib」是使用「release static」模式構建的。 從你運行的項目看起來你需要庫的調試版本,它應該是「PocoFoundationmtd.lib」。

正如您從錯誤日誌中看到的那樣,鏈接中存在衝突。那就是你說編譯器運行時庫是MDd,但是你要鏈接到一個發佈版本庫。確保在你的ProjectProperties-> Linker中你沒有鏈接到任何其他庫,並且鏈接到「PocoFoundationmtd.lib。確保選擇「Debug」,而不是「Release」(位於運行按鈕旁邊)。同樣定義POCO_STATIC

1

確保您針對相同的C運行時(靜態/動態,調試/發佈,多線程)構建Poco庫和項目。

1

我剛剛這樣做,正如查德威克提到的那樣,您不需要Foundation_EXPORTS預處理器標誌。

此外,如果你設置了額外的lib目錄到POCO lib中,你不需要指定的DLL即MT,調試等

你只需要POCO_STATIC作爲預處理標誌的類型。