C 编译器看不到的常量
我对下面的代码有问题。它给了我错误,什么也说不出来 我有一个文件memory.h,其中我有:C 编译器看不到的常量,c,makefile,configure,automake,C,Makefile,Configure,Automake,我对下面的代码有问题。它给了我错误,什么也说不出来 我有一个文件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]")
#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;
看起来编译器根本看不到块大小。现在有一个问题是为什么。
了解我,我可能在这段代码中吃了后两种。但我找不到它,也不知道还有什么会导致这个问题。我之前使用的automake的所有其他命令(包括./con..)都没有抛出任何错误。就像我想的那样愚蠢。我只是换了一行:
AC_DEFINE_UNQUOTED([BLOCK_SIZE], [$bsize], [Defining block size in bytes])
正如有人建议的那样,没有遗漏的引语,只是简单到多。
无论如何谢谢你的帮助。@Dcortez。。您的头文件是否有保护,即避免重新定义?它有
\ifndef\u MEMORY\u H#define\u MEMORY\u H一些代码#endif
@Dcortez。。只需确认memory.c
包括memory.h
,它的路径作为make
文件构造的一部分通过-I
选项提供。你能确认是否是这种情况吗?memory.c包含memory.h我不确定第二个,但它使用的命令如下gcc-DHAVE\u CONFIG\u h-I.-I../src/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”中,所以应该是soI,我不知道为什么答案会消失。任何使用引号AC_DEFINE_UNQUOTED([BLOCK_SIZE],“$b_SIZE”],[Defining BLOCK SIZE in bytes])
的方法都将错误更改为内存。c:15:47:error:invalid operans to binary*(具有“int”和“char*”)
所以现在编译器可以看到它,但可以像char*一样处理,而不是我想要的int。makefile中的LDFLAGS是空的。对于像我这样试图找出这个神奇的地方的人来说:变量最初设置为$b_size