13

在我的 c/c++ 文件中,有多个#define。举个例子:

#ifdef LIBVNCSERVER_HAVE_LIBZ
  /* some code */
#ifdef LIBVNCSERVER_HAVE_LIBJPEG
  /* some more code */

你能告诉我如何修改我的 Makefile.in 以便在编译期间在所有文件中都有那些#define 吗?

谢谢你。

4

3 回答 3

21
-DLIBVNCSERVER_HAVE_LIBZ -DLIBVNCSERVER_HAVE_LIBJPEG

你可以把那些传进去CPPFLAGS

CPPFLAGS = -DLIBVNCSERVER_HAVE_LIBZ -DLIBVNCSERVER_HAVE_LIBJPEG

或创建新变量

CUSTOMDEFINES = -DLIBVNCSERVER_HAVE_LIBZ -DLIBVNCSERVER_HAVE_LIBJPEG

并将其传递给CPPFLAGS = -DEXISTINGFLAGS $(CUSTOMDEFINES)

那些最终将传递给gcc/g++ -D...

$(CC) $(CPPFLAGS)
于 2010-01-26T00:56:31.910 回答
3

将下面的行添加到您的 makefile 中:

DEFINES=LIBVNCSERVER_HAVE_LIBZ LIBVNCSERVER_HAVE_LIBJPEG
...
...进一步在你的makefile中它说...的那一行。
...
    $(cc) ($(addprefix -D, $(DEFINES))) .....
...
...

这是作为示例,您只需将另一个定义添加到DEFINES该行上引用的变量中,如图所示$(cc) -D$(DEFINES),make 将自动扩展变量并编译那些是#ifdefd 的。

感谢R Samuel Klatchko指出了一个小错误……这是专门为 GNU 制作的,您可以使用 addprefix 正确地做到这一点 ($(addprefix -D, $(DEFINES)))

于 2010-01-26T01:06:38.050 回答
0

Don't modify your Makefile.in. (and consider using Automake and converting your Makefile.in to a much simpler Makefile.am). The whole point of those #defines is to let the configure script define them in config.h, and your source files should #include <config.h>. If you are maintaining the package, you will need to write tests in configure.ac to determine whether or not the system being used has libvncserver installed with jpeg and zlib support. If you modify Makefile.in to always define them, then you are making the assumption that your code is only being built on machines where those features are available. If you make that assumption, you should still add checks to configure.ac to confirm it, and have the configure script fail if the dependencies are not met.

于 2010-02-03T14:45:32.280 回答