有一个GCC编译器/连接选项更改主的名字吗? [英] is there a GCC compiler/linker option to change the name of main?

查看:88
本文介绍了有一个GCC编译器/连接选项更改主的名字吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的软件具有正常使用一主一个不同的单元测试。
我只是喜欢它,如果有一个选项,GCC来指定要使用的主要功能。

My software has one main for normal use and a different one for unit tests. I would just love it if there was an option to gcc to specify which "main" function to use.

推荐答案

把它们在不同的文件,并指定用于正常使用的一个.c文件和一个.c文件进行测试。

Put them in separate files, and specify one .c file for normal use, and one .c file for testing.

另外,的#define 上使用测试命令行测试构建和使用这样的:

Alternately, #define testing on the commandline using test builds and use something like:

int main(int argc, char *argv[])
{
#ifdef TESTING
    return TestMain(argc, argv);
#else
    return NormalMain(argc, argv);
#endif
}

int TestMain(int argc, char *argv[])
{
    // Do testing in here
}

int NormalMain(int argc, char *argv[])
{
    //Do normal stuff in here
}

这篇关于有一个GCC编译器/连接选项更改主的名字吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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