简体   繁体   English

使用 VS2010 在“Release”配置中编译 libjson 时出现问题

[英]Problem compiling libjson in “Release” configuration with VS2010

I downloaded the libjson package and added it to my VS2010 projects folder.我下载了libjson package 并将其添加到我的 VS2010 项目文件夹中。 I created a new project called checkJson and added the following code:我创建了一个名为 checkJson 的新项目并添加了以下代码:

#include "../../libjson/libjson.h"
int main(){ return 0;}

When I compile I get an error: "Release build of libjson, but NDEBUG is not on"编译时出现错误:“发布 libjson 的构建,但未启用 NDEBUG”

Since this is the first time I am using Visual Studio I think I have very basic mistake here.由于这是我第一次使用 Visual Studio,我认为我在这里犯了非常基本的错误。 Can you help me please?你能帮我吗?

Moreover, if there is a problem with this package, or if you know some other json parsing packages that I could use without lots of configuration issues I don't care using them instead of this package.此外,如果这个 package 有问题,或者如果你知道其他一些 json 解析包,我可以在没有很多配置问题的情况下使用它们,我不在乎使用它们而不是这个 ZEFE90A8E604A7C840E88D03A678。

For starters, try compiling your project in "Release" configuration.对于初学者,请尝试在“发布”配置中编译您的项目。

If it works (and i believe it should), you may try and define the NDEBUG variable even in debug configuration.如果它有效(我相信它应该有效),即使在调试配置中,您也可以尝试定义 NDEBUG 变量。 But it may yield unexpected results !但它可能会产生意想不到的结果!

Visual Studio will add the NDEBUG directive to the preprocessor settings of a project when it is created. Visual Studio 将在创建项目时将 NDEBUG 指令添加到项目的预处理器设置中。 It's possible that somewhere along the line this was removed or changed.这条线的某处可能已被删除或更改。 Go into the project properties and select the appropriate configuration (in this case "Release"). Go 进入项目属性和 select 适当的配置(在本例中为“发布”)。 Then go into Configuration Properties -> C/C++ -> Preprocessor .然后 go 进入Configuration Properties -> C/C++ -> Preprocessor At the top you will see Preprocessor Directives .在顶部,您将看到Preprocessor Directives In this property make sure that NDEBUG is present.在此属性中确保存在 NDEBUG。 If not add it.如果没有添加它。 Note that this property will contain multiple preprocessor definitions each separated by a semi-colon.请注意,此属性将包含多个预处理器定义,每个定义用分号分隔。 For instance, in a 32 bit Windows console application you will see something like this -例如,在 32 位 Windows 控制台应用程序中,您将看到如下内容 -

WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) . WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)

Do not add #define NDEBUG to any header or source file in your project unless you absolutely know what you are doing.不要#define NDEBUG添加到项目中的任何 header 或源文件中,除非您完全知道自己在做什么。 If you do not wrap it with the appropriate #ifdef/#endif directives this can cause issues with non-release builds.如果您不使用适当的 #ifdef/#endif 指令包装它,这可能会导致非发布版本出现问题。

Add JSON_DEBUG to the preprocessor settings can save you.JSON_DEBUG添加到预处理器设置可以节省您的时间。 but I meet another error msg:但我遇到另一个错误消息:

error C2059: syntax error : ''  

and

//#define JSON_DEPRECATED_FUNCTIONS 

Is there a warning like "Warning C4603: 'NDEBUG': macro is not defined or definition is different after precompiled header".?是否有类似“Warning C4603: 'NDEBUG': macro is not defined or definition is different after precompiled header”之类的警告?

If yes, than just place the #define NDEBUG AFTER the #include "stdafx.h" or move it into stdafx.h如果是,那么只需将 #define NDEBUG 放在 #include "stdafx.h" 之后或将其移至 stdafx.h

I had also to comment the line #define JSON_DEPRECATED_FUNCTIONS in JSONOptions.h, but after that i was at least able to compile.我还必须在 JSONOptions.h 中注释#define JSON_DEPRECATED_FUNCTIONS行,但在那之后我至少能够编译。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM