0

以符号 '%' 开头的行应该在输出文件中按原样传递,但是这些行是否有一些 CPP 宏,这些宏也会被扩展:

来源(test.x):

#ifdef ONE
#warning "ONE is defined"
#else
#warning "NO ONE!!!!!1111"
#endif

%
% hello, ONE
%

运行 rpcgen:

# rpcgen test.x -DONE
test.x:2:2: warning: #warning "ONE is defined" [-Wcpp]
test.x:2:2: warning: #warning "ONE is defined" [-Wcpp]
test.x:2:2: warning: #warning "ONE is defined" [-Wcpp]
test.x:2:2: warning: #warning "ONE is defined" [-Wcpp]

结果(test.h):

/*
 * Please do not edit this file.
 * It was generated using rpcgen.
 */

#ifndef _TEST_H_RPCGEN
#define _TEST_H_RPCGEN

#include <rpc/rpc.h>


#ifdef __cplusplus
extern "C" {
#endif


 hello, 1


#ifdef __cplusplus
}
#endif

#endif /* !_TEST_H_RPCGEN */

所以“ONE”被“1”替换,但最好保持原样(在结果 test.h 中考虑“#ifdef ONE”)

有什么办法可以避免吗?

4

1 回答 1

0

所以,我有一个使用 CPP 包装器的解决方法:

  1. somedir/cpp <- Wrapped 取消定义有问题的宏。例如:

    #!/bin/sh

    执行 /usr/bin/cpp -U_LP64

  2. 运行 rpcgen 作为 rpcgen -Y somedir

于 2012-12-12T12:21:14.070 回答