底线:使用 VS2012 构建,在我的项目中定义了一个宏 (WIN32_LEAN_AND_MEAN) 我在任何地方都找不到#define-ed:不在 C/C++ 中 --> 预处理器,不是从父级或项目依赖项继承的 ( microsoft.cpp.props),而不是在命令行中。 vcxproj 中的任何地方都没有提到它。
编译项目中的单个源/ header ,我发现它已经在 header 的第一行定义了。把这个放在我的标题的顶部:
#pragma once
#ifndef WIN32_LEAN_AND_MEAN
#pragma message ("WIN32_LEAN_AND_MEAN not defined")
#else
#pragma message ("WIN32_LEAN_AND_MEAN defined")
#endif
/* ... */
将“WIN32_LEAN_AND_MEAN defined”打印到构建输出控制台。
根据发布的建议in another - very similar - question ,我试图重新定义宏:
#define WIN32_LEAN_AND_MEAN 123
#ifndef WIN32_LEAN_AND_MEAN
#pragma message ("WIN32_LEAN_AND_MEAN not defined")
#else
#pragma message ("WIN32_LEAN_AND_MEAN defined")
#endif
显然会收到构建警告:
C:\sys\inc\myproj\myproj_someheader.h(5): warning C4005: 'WIN32_LEAN_AND_MEAN' : macro redefinition
command-line arguments : see previous definition of 'WIN32_LEAN_AND_MEAN'
但是,如前所述,当前定义的宏不在该项目配置 (vcxproj) 中,也不在任何公共(public)属性中。
我的问题是:我怎样才能找到那个宏的实际来源?
最佳答案
在您的开发系统上的任何地方都没有#define WIN32_LEAN_AND_MEAN。
有很多#ifdef WIN32_LEAN_AND_MEAN(或等价物)。
关键是您定义它,如果您需要它/想要它。
http://web.archive.org/web/20121219084749/http://support.microsoft.com/kb/166474
VC_EXTRALEAN and WIN32_LEAN_AND_MEAN are used to exclude rarely-used services from Windows headers. VC_EXTRALEAN can only be used in MFC projects, but WIN32_LEAN_AND_MEAN can be used in any project.
如果您想查看宏是如何为您的特定项目扩展的,您可以使用 /P 开关,并查看相应的 .i 文件:
The C++ compiler has a /P switch which means pre-process to a file.
You can enable this from Project -> Properties -> Configuration Properties -> C/C++ -> Preprocessor -> Preprocess to a File.
After this option is set, you will get a .i file for every .cpp file.
Be warned that these .i files are huge files.
附录:
我进入 MSVS 2015 并创建了一个 quick'n'dirty 测试程序:
// TestWin32LeanAndMean.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#ifndef WIN32_LEAN_AND_MEAN
#pragma message ("WIN32_LEAN_AND_MEAN not defined")
#else
#pragma message ("WIN32_LEAN_AND_MEAN defined")
#endif
int main()
{
std::cout << "Hello World" << std::endl;
return 0;
}
编译日志:
1>------ 构建开始:项目:TestWin32LeanAndMean,配置:调试 Win32 ------ 1> stdafx.cpp 1> TestWin32LeanAndMean.cpp 1> WIN32_LEAN_AND_MEAN 未定义 1> TestWin32LeanAndMean.vcxproj -> D:\paul\proj\msvs_2015\TestWin32LeanAndMean\Debug\TestWin32LeanAndMean.exe ========== 构建:1 次成功,0 次失败,0 次更新,0 次跳过 ==========
然后我进入项目 > 属性 > 预处理器,并添加“WIN32_LEAN_AND_MEAN”:
MSVS 预处理器定义:
_DEBUG;_CONSOLE;%(PreprocessorDefinitions);WIN32_LEAN_AND_MEAN
构建仍然说“未定义”(?!?)
1>------ 构建开始:项目:TestWin32LeanAndMean,配置:调试 Win32 ------ 1> stdafx.cpp 1> TestWin32LeanAndMean.cpp 1> WIN32_LEAN_AND_MEAN 未定义 1> TestWin32LeanAndMean.vcxproj -> D:\paul\proj\msvs_2015\TestWin32LeanAndMean\Debug\TestWin32LeanAndMean.exe
所以我手动编辑了我的 .vcsproj 文件并重建了:
TestWin32LeanAndMean.vcxproj:
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PreprocessorDefinitions>WIN32_LEAN_AND_MEAN;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
...
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PreprocessorDefinitions>WIN32_LEAN_AND_MEAN;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
...
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<PreprocessorDefinitions>WIN32_LEAN_AND_MEAN;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
...
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<PreprocessorDefinitions>WIN32_LEAN_AND_MEAN;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
...
我终于得到了 WIN32_LEAN_AND_MEAN"的定义:
1>------ Rebuild All started: Project: TestWin32LeanAndMean, Configuration: Debug Win32 ------
1> stdafx.cpp
1> TestWin32LeanAndMean.cpp
1> WIN32_LEAN_AND_MEAN defined
1> TestWin32LeanAndMean.vcxproj -> D:\paul\proj\msvs_2015 \TestWin32LeanAndMean\Debug\TestWin32LeanAndMean.exe
要准确查看 MSVS 宏预处理器在做什么,您应该能够使用“/P”(“对文件进行预处理”)。
根据我的经验 - 在上面的测试中 - “WIN32_LEAN_AND_MEAN”在环境中通常NOT DEFINED。
如果它是以某种方式定义的,那么要查看的地方将是:
a) MSVS > 项目 > 属性
b) Windows 资源管理器 > 项目 > .vcxproj 文件
c) MSVS 安装文件夹 > 模板 > 项目模板
关于c++ - 找到一些宏被#define-ed的地方,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54188263/
我的瘦服务器配置了nginx,我的ROR应用程序正在它们上运行。在我发布代码更新时运行thinrestart会给我的应用程序带来一些停机时间。我试图弄清楚如何优雅地重启正在运行的Thin实例,但找不到好的解决方案。有没有人能做到这一点? 最佳答案 #Restartjustthethinserverdescribedbythatconfigsudothin-C/etc/thin/mysite.ymlrestartNginx将继续运行并代理请求。如果您将Nginx设置为使用多个上游服务器,例如server{listen80;server
让我们计算MRI范围内的类别:defcount_classesObjectSpace.count_objects[:T_CLASS]endk=count_classes用类方法定义类:classAdefself.foonilendend然后运行:putscount_classes-k#=>3请解释一下,为什么是三个? 最佳答案 查看MRI代码,每次你创建一个Class时,在Ruby中它是Class类型的对象,ruby会自动为这个新类创建“元类”类,这是另一个单例类型的Class对象。C函数调用(class.c)是:rb_define
我正在使用RubyonRails3.0.9,我想生成一个传递一些自定义参数的link_toURL。也就是说,有一个articles_path(www.my_web_site_name.com/articles)我想生成如下内容:link_to'Samplelinktitle',...#HereIshouldimplementthecode#=>'http://www.my_web_site_name.com/articles?param1=value1¶m2=value2&...我如何编写link_to语句“alàRubyonRailsWay”以实现该目的?如果我想通过传递一些
我正在学习http://ruby.railstutorial.org/chapters/static-pages上的RubyonRails教程并遇到以下错误StaticPagesHomepageshouldhavethecontent'SampleApp'Failure/Error:page.shouldhave_content('SampleApp')Capybara::ElementNotFound:Unabletofindxpath"/html"#(eval):2:in`text'#./spec/requests/static_pages_spec.rb:7:in`(root)'
如何将send与+=一起使用?a=20;a.send"+=",10undefinedmethod`+='for20:Fixnuma=20;a+=10=>30 最佳答案 恐怕你不能。+=不是方法,而是语法糖。参见http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_expressions.html它说Incommonwithmanyotherlanguages,Rubyhasasyntacticshortcut:a=a+2maybewrittenasa+=2.你能做的最好的事情是:
如何找到调用此方法的位置?defto_xml(options={})binding.pryoptions=options.to_hifoptions&&options.respond_to?(:to_h)serializable_hash(options).to_xml(options)end 最佳答案 键入caller。这将返回当前调用堆栈。文档:Kernel#caller.例子[0]%rspecspec10/16|===================================================62=====
我对如何计算通过{%assignvar=0%}赋值的变量加一完全感到困惑。这应该是最简单的任务。到目前为止,这是我尝试过的:{%assignamount=0%}{%forvariantinproduct.variants%}{%assignamount=amount+1%}{%endfor%}Amount:{{amount}}结果总是0。也许我忽略了一些明显的东西。也许有更好的方法。我想要存档的只是获取运行的迭代次数。 最佳答案 因为{{incrementamount}}将输出您的变量值并且不会影响{%assign%}定义的变量,我
我想找到在某些文本中找到一些(让它是两个)句子的好方法。什么会更好-使用正则表达式或拆分方法?你的想法?应JeremyStein的要求-有一些例子示例:输入:ThefirstthingtodoistocreatetheCommentmodel.We’llcreatethisinthenormalway,butwithonesmalldifference.IfwewerejustcreatingcommentsforanArticlewe’dhaveanintegerfieldcalledarticle_idinthemodeltostoretheforeignkey,butinthis
我有一个数组数组,想将元素附加到子数组。+=做我想做的,但我想了解为什么push不做。我期望的行为(并与+=一起工作):b=Array.new(3,[])b[0]+=["apple"]b[1]+=["orange"]b[2]+=["frog"]b=>[["苹果"],["橙子"],["Frog"]]通过推送,我将推送的元素附加到每个子数组(为什么?):a=Array.new(3,[])a[0].push("apple")a[1].push("orange")a[2].push("frog")a=>[[“苹果”、“橙子”、“Frog”]、[“苹果”、“橙子”、“Frog”]、[“苹果”、“
我使用的第一个解析器生成器是Parse::RecDescent,它的指南/教程很棒,但它最有用的功能是它的调试工具,特别是tracing功能(通过将$RD_TRACE设置为1来激活)。我正在寻找可以帮助您调试其规则的解析器生成器。问题是,它必须用python或ruby编写,并且具有详细模式/跟踪模式或非常有用的调试技术。有人知道这样的解析器生成器吗?编辑:当我说调试时,我并不是指调试python或ruby。我指的是调试解析器生成器,查看它在每一步都在做什么,查看它正在读取的每个字符,它试图匹配的规则。希望你明白这一点。赏金编辑:要赢得赏金,请展示一个解析器生成器框架,并说明它的