如何有文库构建与断言接通和断开侧由端? [英] How to have library builds with asserts turned on and off side-by-side?

查看:120
本文介绍了如何有文库构建与断言接通和断开侧由端?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个库,我使用该库中的程序。我经常做同断言开机并计划code的改变,运行测试那么如果测试通过我运行断言关闭来衡量我刚才所做的更改对性能的影响的基准。我也希望把我的库测试的断言和关闭它们在基准库中。所以,我经常需要切换断言在程序和库同时设置。

I have written a library and I use that library in a program. I often make a change in the program code, run tests with asserts turned on and then if the tests pass I run a benchmark with asserts turned off to measure the performance impact of the change I just made. I also want to turn the asserts on in my library for the tests and to turn them off in the library for the benchmark. So I frequently need to switch the assert setting simultaneously in the program and the library.

匹配磁带库和程序断言设置(NDEBUG)(使用该库)不能手动因为得到它错误意味着未定义的行为,因为有人称在头(定义冲突导致不确定的行为),而事实上我得到与GCC一个崩溃的程序,当我建立与断言图书馆断言关闭程序。我一直没能找出什么标准的方式来做到这一点。我考虑有我的库构建的系统安装两个二进制文件(也可能是抱怨,如果它们包含了错误的断言设置(NDEBUG)头)命名为libfoo的-1.0和libfoo的断言-1.0或类似的东西。

Matching the assert settings (NDEBUG) for the library and the program (that uses the library) must not be manual because getting it wrong means undefined behavior as there are asserts in the headers (conflicting definitions causes undefined behavior) and indeed I get a crashing program with GCC when I build an assert-off program with an assert-on library. I haven't been able to find out what the standard way to do this is. I'm considering having my library build system install two binaries (and possibly headers that complain if they are included with the wrong assert setting (NDEBUG)) named libfoo-1.0 and libfoo-assert-1.0 or something like that.

什么是相匹配的断言以这样的方式库和程序之间设置的切换断言同时在这两个设置是简单,快速,不容易出错的最佳方式?

What is the best way to match the assert setting between libraries and programs in such a way that switching the assert setting in both at the same time is easy, fast and not error prone?

推荐答案

通常情况下,构建系统被设置为做不同的构建(例如调试/发布,辑阵/单线程)反正。得到的库和可执行文件要么放在不同的目录或有不同的名称来区分它们。这是没有什么不同。

Normally, build systems are set up to do different builds (e.g. debug/release, mutli/single threaded) anyway. The resultant libraries and executables are either placed in different directories or have different names to distinguish them. This is no different.

如果你觉得你需要额外的构建类型断言/ noassert,然后只需添加这个额外的构建类型。唯一的问题是命名约定,什么是在默认情况下,如果没有指定特定的构建类型来完成的。

If you feel you need additional build types for assert/noassert, then just add this additional build type. The only question is the naming convention and what is done by default if no particular build type is specified.

这篇关于如何有文库构建与断言接通和断开侧由端?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆