在为多个平台开发 C++ 时,我正在研究在构建过程中使用 SCons。我在构建配置中完成了 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(减去包含路径)吐出的命令行:
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 header 并未明确包含在每个单独的文件中,但在命令行选项中,我有/FI 强制在项目中编译的每个文件中包含 PCH。
最佳答案
我好像解决了自己的问题。预编译头文件时,cl.exe 会生成一个.obj 文件。因为我们正在使用 boost 的内部魔法自动链接到 Windows 上所需的库,并且我们的 boost header #includes 也在预编译 header 中,所以这些链接也包含在 .obj 文件中。不幸的是,这个 .obj 文件没有添加到需要链接的 .obj 文件列表中(在这种情况下生成 .dll)。
它起作用的原因是手动将 PCH 编译期间生成的 .obj 文件附加到 LINKFLAGS 参数。这样做 100% 完全解决了我一直遇到的问题。也许是时候更新 msvc.py 工具并将补丁发送到 SCons 了!
关于c++ - SCons、Boost::ASIO、Windows 预编译 header 和链接器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/998881/
我需要在客户计算机上运行Ruby应用程序。通常需要几天才能完成(复制大备份文件)。问题是如果启用sleep,它会中断应用程序。否则,计算机将持续运行数周,直到我下次访问为止。有什么方法可以防止执行期间休眠并让Windows在执行后休眠吗?欢迎任何疯狂的想法;-) 最佳答案 Here建议使用SetThreadExecutionStateWinAPI函数,使应用程序能够通知系统它正在使用中,从而防止系统在应用程序运行时进入休眠状态或关闭显示。像这样的东西:require'Win32API'ES_AWAYMODE_REQUIRED=0x0
大约一年前,我决定确保每个包含非唯一文本的Flash通知都将从模块中的方法中获取文本。我这样做的最初原因是为了避免一遍又一遍地输入相同的字符串。如果我想更改措辞,我可以在一个地方轻松完成,而且一遍又一遍地重复同一件事而出现拼写错误的可能性也会降低。我最终得到的是这样的:moduleMessagesdefformat_error_messages(errors)errors.map{|attribute,message|"Error:#{attribute.to_s.titleize}#{message}."}enddeferror_message_could_not_find(obje
我的瘦服务器配置了nginx,我的ROR应用程序正在它们上运行。在我发布代码更新时运行thinrestart会给我的应用程序带来一些停机时间。我试图弄清楚如何优雅地重启正在运行的Thin实例,但找不到好的解决方案。有没有人能做到这一点? 最佳答案 #Restartjustthethinserverdescribedbythatconfigsudothin-C/etc/thin/mysite.ymlrestartNginx将继续运行并代理请求。如果您将Nginx设置为使用多个上游服务器,例如server{listen80;server
我遵循MichaelHartl的“RubyonRails教程:学习Web开发”,并创建了检查用户名和电子邮件长度有效性的测试(名称最多50个字符,电子邮件最多255个字符)。test/helpers/application_helper_test.rb的内容是:require'test_helper'classApplicationHelperTest在运行bundleexecraketest时,所有测试都通过了,但我看到以下消息在最后被标记为错误:ERROR["test_full_title_helper",ApplicationHelperTest,1.820016791]test
我是rails的新手,想在form字段上应用验证。myviewsnew.html.erb.....模拟.rbclassSimulation{:in=>1..25,:message=>'Therowmustbebetween1and25'}end模拟Controller.rbclassSimulationsController我想检查模型类中row字段的整数范围,如果不在范围内则返回错误信息。我可以检查上面代码的范围,但无法返回错误消息提前致谢 最佳答案 关键是您使用的是模型表单,一种显示ActiveRecord模型实例属性的表单。c
我正在尝试编写一个将文件上传到AWS并公开该文件的Ruby脚本。我做了以下事情:s3=Aws::S3::Resource.new(credentials:Aws::Credentials.new(KEY,SECRET),region:'us-west-2')obj=s3.bucket('stg-db').object('key')obj.upload_file(filename)这似乎工作正常,除了该文件不是公开可用的,而且我无法获得它的公共(public)URL。但是当我登录到S3时,我可以正常查看我的文件。为了使其公开可用,我将最后一行更改为obj.upload_file(file
我克隆了一个rails仓库,我现在正尝试捆绑安装背景:OSXElCapitanruby2.2.3p173(2015-08-18修订版51636)[x86_64-darwin15]rails-v在您的Gemfile中列出的或native可用的任何gem源中找不到gem'pg(>=0)ruby'。运行bundleinstall以安装缺少的gem。bundleinstallFetchinggemmetadatafromhttps://rubygems.org/............Fetchingversionmetadatafromhttps://rubygems.org/...Fe
在Cooper的书BeginningRuby中,第166页有一个我无法重现的示例。classSongincludeComparableattr_accessor:lengthdef(other)@lengthother.lengthenddefinitialize(song_name,length)@song_name=song_name@length=lengthendenda=Song.new('Rockaroundtheclock',143)b=Song.new('BohemianRhapsody',544)c=Song.new('MinuteWaltz',60)a.betwee
我是Google云的新手,我正在尝试对其进行首次部署。我的第一个部署是RubyonRails项目。我基本上是在关注thisguideinthegoogleclouddocumentation.唯一的区别是我使用的是我自己的项目,而不是他们提供的“helloworld”项目。这是我的app.yaml文件runtime:customvm:trueentrypoint:bundleexecrackup-p8080-Eproductionconfig.ruresources:cpu:0.5memory_gb:1.3disk_size_gb:10当我转到我的项目目录并运行gcloudprevie
我有两个Rails模型,即Invoice和Invoice_details。一个Invoice_details属于Invoice,一个Invoice有多个Invoice_details。我无法使用accepts_nested_attributes_forinInvoice通过Invoice模型保存Invoice_details。我收到以下错误:(0.2ms)BEGIN(0.2ms)ROLLBACKCompleted422UnprocessableEntityin25ms(ActiveRecord:4.0ms)ActiveRecord::RecordInvalid(Validationfa