【发布时间】:2013-03-15 15:36:11
【问题描述】:
下面的代码有问题。它给我带来了错误,什么也没告诉我。
我有一个文件 memory.h 我有:
#ifndef BLOCK_SIZE
#define BLOCK_SIZE 8
#endif
我还有 configuration.ac 文件,片段如下:
AC_ARG_WITH([block-size],
[AS_HELP_STRING([--with-block-size],["Define blocksize to initialize with. Default value: 8]")],
[bsize="$withval"],
[])
if test ! -z "${bsize}"; then
if test "${bsize}" > 0 ; then
AC_DEFINE_UNQUOTED([BLOCK_SIZE], [$b_size], [Defining block size in bytes])
else
AC_DEFINE_UNQUOTED([BLOCK_SIZE], [8], [Default block size : 8B])
fi
fi
后来我使用命令./configure --with-block-size=16 --with-allocator=STR_MIN 来完成makefile的制作。但是现在当我使用make 命令时,我得到了很多错误:
memory.c: In function 'initialize':
memory.c:15:59: error: expected expression before ')' token
memory.c: In function 'allocate':
memory.c:26:41: error: expected expression before ')' token
memory.c:53:56: error: expected expression before ';' token
memory.c: In function 'defragment':
memory.c:140:73: error: expected expression before ')' token
memory.c: In function 'diagnoze':
memory.c:174:183: error: expected expression before ',' token
所有有错误的行如下所示:
mem -> unused_list -> address = malloc(count * BLOCK_SIZE);
new -> address = space -> address + size * BLOCK_SIZE;
看起来编译器根本看不到 BLOCK_SIZE。现在只有一个问题为什么。 了解我,我可能在这段代码中吃了后一两个。但我找不到它,也不知道还有什么会导致这个问题。我之前使用的所有其他 automake 命令(包括 ./con..)都没有抛出任何错误。
【问题讨论】:
-
@Dcortez.. 你的头文件是否有保护,即避免重新定义?
-
它有
#ifndef _MEMORY_H #define _MEMORY_H some code #endif -
@Dcortez.. 只是为了确认
memory.c包括memory.h并且它的路径可通过-I选项作为make文件结构的一部分使用。你能确认是不是这样吗? -
memory.c 包括 memory.h 我不确定第二个,但它使用类似
gcc -DHAVE_CONFIG_H -I. -I../src/include include -g -O2 -MT memory.lo -MD -MP -MF .deps/memory.Tpo -c memory.c -fPIC -DPIC -o .libs/memory.o的命令。 memory.h 在 './src/include' 所以应该是这样 -
我不知道为什么答案消失了。使用引号
AC_DEFINE_UNQUOTED([BLOCK_SIZE], ["$b_size"], [Defining block size in bytes])的任何方式都将错误更改为memory.c:15:47: error: invalid operands to binary * (have 'int' and 'char *')所以现在编译器看到它但像我想要的那样处理 char* 而不是 int 。 makefile 中的 LDFLAGS 为空。
标签: c makefile configure automake