c – SCons,Boost :: ASIO,Windows预编译标头和链接器错误

我正在研究使用SCons进行构建过程,因为我们为多个平台开发了C语言.我在构建配置中有99%的方式,但我在
Windows上遇到了一个非常奇怪的错误,它与预编译的头文件有关.更奇怪的是,它只发生在一个项目上.

在这个项目的SConscript文件中,我有以下内容在Windows上编译PCH:

if env['PLATFORM'] == 'win32':
    env['PCH'] = env.PCH('MyPCH-LSCommon.pch', 'Common/src/MyPCH.h')[0]
    env['PCHSTOP'] = '"MyPCH.h"'

我还有一个编译器标志设置为强制包含项目中所有文件的MyPCH.h:

if env['PLATFORM'] == 'win32':
    cxxflags = [ '/FI"MyPCH.h"' ]

一切顺利,编译绝对精细.直到最后的DLL链接阶段,我才得到链接器错误的页面和页面,如下所示:

error LNK2001: unresolved external symbol "private: static class
boost::asio::detail::tss_ptr<class boost::asio::detail::call_stack<class 
boost::asio::detail::win_iocp_io_service>::context> boost::asio::detail::call_stack<class 
boost::asio::detail::win_iocp_io_service>::top_" 
(?top_@?$call_stack@Vwin_iocp_io_service@detail@asio@boost@@@detail@asio@boost@@0V?$tss_ptr@
Vcontext@?$call_stack@Vwin_iocp_io_service@detail@asio@boost@@@detail@asio@boost@@@234@A)

和:

     error LNK2001: unresolved external symbol "private: static class 
boost::asio::detail::winsock_init<2,0> boost::asio::detail::winsock_init<2,0>::instance_" 
(?instance_@?$winsock_init@$01$0A@@detail@asio@boost@@0V1234@A)

这是令人费解的,因为我得到链接警告的类都没有使用boost :: asio,尽管它包含在预编译头文件中并且在某些#includes链中.

更令人费解的是,如果我禁用预编译头文件的编译,但仍然强制它的包含,一切编译和链接就好了.它只需要永远的怪胎.

有没有人知道可能导致这些链接器错误的原因是什么?

提前致谢.

—编辑—

这是SCons为了构建PCH(Minus Include Paths)而吐出的命令行:

    cl /nologo /W4 /Od /RTC1 /MDd /TP /EHsc /FD /RTC1 /RTCc /Gy /openmp /TP 
/Fd"\vc80.pdb" /nologo /Wp64 /wd4231 /wd4616 /errorReport:prompt /Zm256 /MDd /Od
/FI"CedrusPCH.h" /DOS_WINDOWS=OS_WINDOWS /D_WIN32 /DWIN32 /D_WIN32_WINNT=0X500 /D_WINDOWS 
/D_UNICODE /DBOOST_ALL_DYN_LINK /DBOOST_REGEX_DYN_LINK /DBOOST_LIB_DIAGNOSTIC 
/D_VC80_UPGRADE=0x710 /DUNICODE /DWXUSINGDLL /DwxUSE_SERVICE_DISCOVERY=1 /D_DEBUG /D_DEBUG 
/DSL_ENABLE_NETWORKING=1 /DWXMAKINGDLL_LSCOMMON /DSLSDK_USEDLL 
/c C:\Projects\licenser\Common\src\CedrusPCH.h /Foscons-out\dbg\obj\CedrusPCH-LSCommon.obj
/Yc"CedrusPCH.h" /Fpscons-out\dbg\obj\CedrusPCH-LSCommon.pch /ZI CedrusPCH.h

这是正在编译的文件的命令行(再次减去包含路径):

cl /Foscons-out\dbg\obj\Licenser\src\secure\windows_crypto
\PlatformCryptoKeyProvider_wincrypt.obj /c C:\Projects\licenser\Licenser\src\secure
\windows_crypto\PlatformCryptoKeyProvider_wincrypt.cpp /nologo /W4 /Od /RTC1 /MDd /TP 
/EHsc /FD /RTC1 /RTCc /Gy /openmp /TP /Fd"\vc80.pdb" /nologo /Wp64 /wd4231 /wd4616 
/errorReport:prompt /Zm256 /MDd /Od /FI"CedrusPCH.h" /nologo /W4 /Od /RTC1 /MDd 
/DOS_WINDOWS=OS_WINDOWS /D_WIN32 /DWIN32 /D_WIN32_WINNT=0X500 /D_WINDOWS /D_UNICODE 
/DBOOST_ALL_DYN_LINK /DBOOST_REGEX_DYN_LINK /DBOOST_LIB_DIAGNOSTIC /D_VC80_UPGRADE=0x710 
/DUNICODE /DWXUSINGDLL /DwxUSE_SERVICE_DISCOVERY=1 /D_DEBUG /D_DEBUG 
/DSL_ENABLE_NETWORKING=1 /DWXMAKINGDLL_LSCOMMON /DSLSDK_USEDLL /D_USRDLL /D_WINDLL 
 /Yu"CedrusPCH.h" /Fpscons-out\dbg\obj\CedrusPCH-LSCommon.pch /ZI
PlatformCryptoKeyProvider_wincrypt.cpp

最后,这是链接命令行:

link /nologo /MACHINE:X86 /DEBUG -manifest /dll /out:scons-out\dbg\obj\LSCommon.dll 
/implib:scons-out\dbg\obj\LSCommon.lib /LIBPATH:scons-out\dbg\lib 
/LIBPATH:C:\Projects\licenser\scons-out\dbg\lib /LIBPATH:scons-out\dbg\obj 
/LIBPATH:. /LIBPATH:C:\Projects\licenser /LIBPATH:C:\Projects\licenser\scons-out\dbg\obj 
/LIBPATH:C:\Projects\wxWidgets\lib\vc_dll_vc8 /LIBPATH:C:\Projects\boost\install\lib 
"/LIBPATH:C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Lib" 
"/LIBPATH:C:\Program Files\Bonjour SDK\lib\win32" unicows.lib winmm.lib comctl32.lib 
rpcrt4.lib ws2_32.lib oleacc.lib kernel32.lib user32.lib gdi32.lib winspool.lib 
comdlg32.lib advapi32.lib shell32.lib oleacc.lib ole32.lib oleaut32.lib uuid.lib 
odbc32.lib odbccp32.lib boost_signals-vc80-mt-gd-1_39.lib boost_system-vc80-mt-gd-1_39.lib 
boost_date_time-vc80-mt-gd-1_39.lib boost_regex-vc80-mt-gd-1_39.lib 
boost_wserialization-vc80-mt-gd-1_39.lib boost_serialization-vc80-mt-gd-1_39.lib 
boost_thread-vc80-mt-gd-1_39.lib wxbase28ud.lib wxbase28ud_net.lib wxbase28ud_xml.lib 
wxmsw28ud_adv.lib wxmsw28ud_aui.lib wxmsw28ud_core.lib wxmsw28ud_html.lib wxmsw28ud_qa.lib 
wxmsw28ud_richtext.lib wxmsw28ud_xrc.lib LSBase.lib disphelper.lib Crypt32.lib 
/PDB:scons-out\dbg\obj\LSCommon.pdb /DEBUG 
scons-out\dbg\obj\Licenser\src\dll_template_instantiation_export_LSCommon.obj 
scons-out\dbg\obj\Licenser\src\secure\ConcreteMessageSigningAlgorithm_DSA_with_SHA1.obj 
scons-out\dbg\obj\Licenser\src\secure\CryptoObjectFactory.obj 
scons-out\dbg\obj\Licenser\src\secure\EntropyCalculation.obj 
scons-out\dbg\obj\Licenser\src\data\LSAccount.obj 
scons-out\dbg\obj\Licenser\src\data\LSAccountHistory.obj 
scons-out\dbg\obj\Licenser\src\server_daemon\LSAccountHistoryRequestPacket.obj 
scons-out\dbg\obj\Licenser\src\server_daemon\LSAccountRequestPacket.obj 
scons-out\dbg\obj\Licenser\src\data\LSActivation.obj 
scons-out\dbg\obj\Licenser\src\server_daemon\LSActivationRequestPacket.obj 
scons-out\dbg\obj\Licenser\src\data\LSBlob.obj 
scons-out\dbg\obj\Licenser\src\data\LSCompositePrimaryKey.obj 
scons-out\dbg\obj\Licenser\src\data\LSDatabaseElementBase.obj 
scons-out\dbg\obj\Licenser\src\server_daemon\LSDoActivateReplyPacket.obj 
scons-out\dbg\obj\Licenser\src\server_daemon\LSDoActivateRequestPacket.obj 
scons-out\dbg\obj\Licenser\src\server_daemon\LSDoManualActivateReplyPacket.obj 
scons-out\dbg\obj\Licenser\src\server_daemon\LSDoManualActivateRequestPacket.obj 
scons-out\dbg\obj\Licenser\src\data\LSLicense.obj 
scons-out\dbg\obj\Licenser\src\data\LSLicenseHistory.obj 
scons-out\dbg\obj\Licenser\src\server_daemon\LSLicenseHistoryRequestPacket.obj 
scons-out\dbg\obj\Licenser\src\server_daemon\LSLicenseRequestPacket.obj 
scons-out\dbg\obj\Licenser\src\server_daemon\LSLoginReplyPacket.obj 
scons-out\dbg\obj\Licenser\src\server_daemon\LSLoginRequestPacket.obj 
scons-out\dbg\obj\Licenser\src\data\LSMachine.obj 
scons-out\dbg\obj\Licenser\src\server_daemon\LSMachineRequestPacket.obj 
scons-out\dbg\obj\Licenser\src\server_daemon\LSNet.obj 
scons-out\dbg\obj\Licenser\src\data\LSPhyActivation.obj 
scons-out\dbg\obj\Licenser\src\data\deprecated_streamables\LSPhyActivation_LegacyStreamingHelper.obj 
scons-out\dbg\obj\Licenser\src\data\LSPrimaryKey.obj 
scons-out\dbg\obj\Licenser\src\data\LSPrimaryKeyDefinitions.obj 
scons-out\dbg\obj\Licenser\src\data\LSProduct.obj 
scons-out\dbg\obj\Licenser\src\data\LSProductHistory.obj 
scons-out\dbg\obj\Licenser\src\server_daemon\LSProductHistoryRequestPacket.obj 
scons-out\dbg\obj\Licenser\src\server_daemon\LSProductRequestPacket.obj 
scons-out\dbg\obj\Licenser\src\data\LSSimplePrimaryKey.obj 
scons-out\dbg\obj\Licenser\src\data\LSUser.obj 
scons-out\dbg\obj\Licenser\src\data\LSUserHistory.obj 
scons-out\dbg\obj\Licenser\src\server_daemon\LSUserHistoryRequestPacket.obj 
scons-out\dbg\obj\Licenser\src\server_daemon\LSUserRequestPacket.obj 
scons-out\dbg\obj\Licenser\src\server_daemon\streaming_versioning\StreamableClassInfoVersionTranslator.obj
scons-out\dbg\obj\Licenser\src\data\deprecated_streamables\LSProduct_deprecated_v_2.obj 
scons-out\dbg\obj\Licenser\src\secure\deprecated_streamables\DSA.obj 
scons-out\dbg\obj\Licenser\src\secure\deprecated_streamables\DSAKeyPair.obj 
scons-out\dbg\obj\Licenser\src\secure\deprecated_streamables\DSAPublicKey.obj 
scons-out\dbg\obj\Licenser\src\secure\deprecated_streamables\Hash.obj 
scons-out\dbg\obj\Licenser\src\secure\deprecated_streamables\SHA1.obj 
scons-out\dbg\obj\Licenser\src\server_daemon\LSActivationApprovalStrategy.obj 
scons-out\dbg\obj\Licenser\src\data\LSDatabaseElementT.obj 
scons-out\dbg\obj\Licenser\src\data\LSPairPrimaryKeyT.obj 
scons-out\dbg\obj\Licenser\src\data\LSSimplePrimaryKeyT.obj 
scons-out\dbg\obj\Licenser\src\secure\windows_crypto\PlatformCryptoKeyProvider_wincrypt.obj
scons-out\dbg\obj\Licenser\src\secure\windows_crypto\Scoped_RAII_AutoReleaseWincryptHandleFactory.obj

此外,PCH标头未明确包含在每个单独的文件中,但在命令行选项中,我有/ FI强制包括项目中编译的每个文件上的PCH.

最佳答案 我好像已经解决了自己的问题.预编译头文件时,cl.exe会生成.obj文件.因为我们使用boost的内部魔法自动链接到Windows上的所需库,我们的boost头#includes也在预编译头中,这些链接也包含在.obj文件中.不幸的是,这个.obj文件没有添加到需要链接的.obj文件列表中(在这种情况下创建.dll).

它的工作原理是手动将编译PCH期间生成的.obj文件附加到LINKFLAGS参数.这样做100%完全解决了我一直遇到的问题.也许是时候更新msvc.py工具并将补丁发送到SCons了!

点赞