gpt4 book ai didi

知道程序输出文件名的 c 宏

转载 作者:行者123 更新时间:2023-11-30 15:25:17 27 4
gpt4 key购买 nike

有没有办法有条件地包含 取决于构建输出的代码部分 文件名带有 GCC(特别是 mingw/codeblocks)

例如:

我有 2 个配置文件:

项目 1 编译为 foo.exe 项目2编译为bar.exe

两个项目都包含一个名为 myheaders.h 的文件

在 myheaders.h 中,有关于 程序,

 #define APP_TITLE                     "my project"
#define APP_VERSION 0,0,0,1
#define APP_VERSION_STR "0,0,0,1"

我的问题:以下情况是否可能

          #if __OUTPUT__ =="foo.exe"
#define APP_TITLE "my project"
#define APP_VERSION 0,0,0,1
#define APP_VERSION_STR "0,0,0,1"
#endif

#if __OUTPUT__ =="bar.exe"
#define APP_TITLE "side project"
#define APP_VERSION 0,0,2,2
#define APP_VERSION_STR "0,0,2,2"
#endif

我知道我可以使用 #defines 传递给编译器 命令行选项,但似乎没有 处理资源文件

我的资源文件如下

          #include "myheaders.h"

VS_VERSION_INFO VERSIONINFO
FILEVERSION APP_VERSION
PRODUCTVERSION APP_VERSION
FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
FILEFLAGS VS_FF_PRERELEASE
FILEOS VOS__WINDOWS32
FILETYPE VFT_APP
FILESUBTYPE VFT2_UNKNOWN

BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "000004b0"
BEGIN
VALUE "ProductName", APP_TITLE
VALUE "ProductVersion", APP_VERSION_STR
VALUE "FileDescription", APP_DESCRIPTION
VALUE "FileVersion", APP_VERSION_STR
VALUE "CompanyName", APP_AUTHOR
VALUE "LegalCopyright", APP_COPYRIGHT
VALUE "Comments", APP_COMMENTS
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x000,0x4b0
END
END

APP_TITLE 在所有源文件中扩展为正确的字符串,除了资源文件,它只会导致语法错误..

如果我在没有宏条件的情况下定义 APP_TITLE ,则一切正常..

最佳答案

更新:资源是使用 rc.exe 编译的,而不是 C/C++ 编译器。您需要使用 rc.exe 的/d 选项来指定 /d MYPROJECT/d SIDEPROJECT

然后在代码中:

      #ifdef MYPROJECT
#define APP_TITLE "my project"
#define APP_VERSION 0,0,0,1
#define APP_VERSION_STR "0,0,0,1"
#endif

#ifdef SIDEPROJECT
#define APP_TITLE "side project"
#define APP_VERSION 0,0,2,2
#define APP_VERSION_STR "0,0,2,2"
#endif

关于知道程序输出文件名的 c 宏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28005286/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com