当前位置: 技术问答>linux和unix
不知道问题出在哪了,求解答!
来源: 互联网 发布时间:2016-09-14
本文导语: 使用vxworks底下的gcc编译一个工程,又出了问题,以下先列出报错的内容: In file included from C:/Tornado2.2/target/h/taskLib.h:144, from C:/PROGRA~1/MATLAB/R2010a/rtw/c/src/ext_mode/common/ext_work.h:23, ...
使用vxworks底下的gcc编译一个工程,又出了问题,以下先列出报错的内容:
In file included from C:/Tornado2.2/target/h/taskLib.h:144,
from C:/PROGRA~1/MATLAB/R2010a/rtw/c/src/ext_mode/common/ext_work.h:23,
from test2.h:28,
from test2_data.c:18:
C:/Tornado2.2/target/h/stdlib.h:124: conflicting types for `ExtModeCalloc'
C:/PROGRA~1/MATLAB/R2010a/rtw/c/src/ext_mode/common/mem_mgr.h:25: previous declaration of `ExtModeCalloc'
C:/Tornado2.2/target/h/stdlib.h:128: conflicting types for `ExtModeMalloc'
C:/PROGRA~1/MATLAB/R2010a/rtw/c/src/ext_mode/common/mem_mgr.h:23: previous declaration of `ExtModeMalloc'
make: *** [test2_data.o] Error 0x1
其中
taskLib.h的144行为 #include "stdlib.h"
stdlib.h的124行为extern void *calloc (size_t __nelem, size_t __size);
128行为extern void *malloc (size_t __size);
mem_mgr.h的内容摘要如下
#ifndef __MEM_MGR__
#define __MEM_MGR__
struct MemBufHdr {
struct MemBufHdr *memBufNext;
struct MemBufHdr *memBufPrev;
char *MemBuf;
int size;
};
typedef struct MemBufHdr MemBufHdr;
extern void ExtModeFree(void *mem);
extern void *ExtModeMalloc(uint32_T size);
extern void *ExtModeCalloc(uint32_T number, uint32_T size);
#endif /* __MEM_MGR__ */
ExtModeMalloc,ExtModeCalloc两个个函数在mem_mgr.c文件中定义如下
PUBLIC void *ExtModeCalloc(uint32_T number, uint32_T size)
{
uint32_T numBytes = number*size;
void *mem = ExtModeMalloc(numBytes);
if (mem == NULL) goto EXIT_POINT;
memset(mem, 0, numBytes);
EXIT_POINT:
return mem;
}
PUBLIC void *ExtModeMalloc(uint32_T size)
{
boolean_T keepTrying = false;
MemBufHdr *LocalMemBuf; /* Requested buffer (NULL if none available). */
MemBufHdr *FreeMemBuf; /* First free buffer big enough for request. */
/*
* Must allocate enough space for the requested number of bytes plus the
* size of the memory buffer header.
*/
int sizeToAlloc = size + sizeof(MemBufHdr);
while (!keepTrying) {
keepTrying = true;
LocalMemBuf = NULL;
FreeMemBuf = NULL;
/* Initialize the free queue. */
if (FreeQueue == NULL) initFreeQueue();
/* Find first free packet big enough for our request. */
FreeMemBuf = findFirstFreeMemBuf(sizeToAlloc);
if (FreeMemBuf == NULL) {
/* We couldn't find a free buffer. Run garbage collection to merge
free buffers together and try again. */
sortQueue(FreeQueue);
FreeMemBuf = findFirstFreeMemBuf(sizeToAlloc);
}
/* No free buffers are available which satisfy the request. */
if (FreeMemBuf == NULL) goto EXIT_POINT;
/*
* Found a free buffer with enough space. Carve out the exact buffer size
* needed from the end of the free buffer.
*/
LocalMemBuf = (MemBufHdr *)(FreeMemBuf->MemBuf +
FreeMemBuf->size -
sizeToAlloc);
/*
* The pointer to the free memory must be longword aligned. If it
* is not, adjust the size to allocate and try again.
*/
{
int alignBytes = (int)LocalMemBuf % 4;
if (alignBytes) {
sizeToAlloc += (4-alignBytes);
keepTrying = false;
}
}
}
/* Set up the new packet's info. */
LocalMemBuf->memBufPrev = NULL;
LocalMemBuf->memBufNext = NULL;
LocalMemBuf->MemBuf = (char *)LocalMemBuf + sizeof(MemBufHdr);
LocalMemBuf->size = size;
/* Insert the newly created buffer into the InUseQueue. */
inUseQueueInsert(LocalMemBuf);
/* Update the free packet's size to reflect giving up a piece. */
FreeMemBuf->size -= sizeToAlloc;
EXIT_POINT:
if (LocalMemBuf) {
#ifdef VERBOSE
numBytesAllocated += sizeToAlloc;
printf("nBytes allocated: %d out of %d.n", numBytesAllocated, EXTMODE_STATIC_SIZE);
#endif
return LocalMemBuf->MemBuf;
}
#ifdef VERBOSE
printf("nBytes allocated: %d out of %d.", numBytesAllocated+sizeToAlloc, EXTMODE_STATIC_SIZE);
printf("nMust increase size of static allocation!n");
#endif
return NULL;
}
奇怪的是这两个函数并非是类的成员函数,为什么加上了PUBLIC?,且这两个函数的定义中(甚至整个mem_mgr.c文件)并未包含calloc和 malloc,虽然mem_mgr.c包含了stdlib.h,另外从makefile中可以看出mem_mgr.c比test2_data.c先编译
In file included from C:/Tornado2.2/target/h/taskLib.h:144,
from C:/PROGRA~1/MATLAB/R2010a/rtw/c/src/ext_mode/common/ext_work.h:23,
from test2.h:28,
from test2_data.c:18:
C:/Tornado2.2/target/h/stdlib.h:124: conflicting types for `ExtModeCalloc'
C:/PROGRA~1/MATLAB/R2010a/rtw/c/src/ext_mode/common/mem_mgr.h:25: previous declaration of `ExtModeCalloc'
C:/Tornado2.2/target/h/stdlib.h:128: conflicting types for `ExtModeMalloc'
C:/PROGRA~1/MATLAB/R2010a/rtw/c/src/ext_mode/common/mem_mgr.h:23: previous declaration of `ExtModeMalloc'
make: *** [test2_data.o] Error 0x1
其中
taskLib.h的144行为 #include "stdlib.h"
stdlib.h的124行为extern void *calloc (size_t __nelem, size_t __size);
128行为extern void *malloc (size_t __size);
mem_mgr.h的内容摘要如下
#ifndef __MEM_MGR__
#define __MEM_MGR__
struct MemBufHdr {
struct MemBufHdr *memBufNext;
struct MemBufHdr *memBufPrev;
char *MemBuf;
int size;
};
typedef struct MemBufHdr MemBufHdr;
extern void ExtModeFree(void *mem);
extern void *ExtModeMalloc(uint32_T size);
extern void *ExtModeCalloc(uint32_T number, uint32_T size);
#endif /* __MEM_MGR__ */
ExtModeMalloc,ExtModeCalloc两个个函数在mem_mgr.c文件中定义如下
PUBLIC void *ExtModeCalloc(uint32_T number, uint32_T size)
{
uint32_T numBytes = number*size;
void *mem = ExtModeMalloc(numBytes);
if (mem == NULL) goto EXIT_POINT;
memset(mem, 0, numBytes);
EXIT_POINT:
return mem;
}
PUBLIC void *ExtModeMalloc(uint32_T size)
{
boolean_T keepTrying = false;
MemBufHdr *LocalMemBuf; /* Requested buffer (NULL if none available). */
MemBufHdr *FreeMemBuf; /* First free buffer big enough for request. */
/*
* Must allocate enough space for the requested number of bytes plus the
* size of the memory buffer header.
*/
int sizeToAlloc = size + sizeof(MemBufHdr);
while (!keepTrying) {
keepTrying = true;
LocalMemBuf = NULL;
FreeMemBuf = NULL;
/* Initialize the free queue. */
if (FreeQueue == NULL) initFreeQueue();
/* Find first free packet big enough for our request. */
FreeMemBuf = findFirstFreeMemBuf(sizeToAlloc);
if (FreeMemBuf == NULL) {
/* We couldn't find a free buffer. Run garbage collection to merge
free buffers together and try again. */
sortQueue(FreeQueue);
FreeMemBuf = findFirstFreeMemBuf(sizeToAlloc);
}
/* No free buffers are available which satisfy the request. */
if (FreeMemBuf == NULL) goto EXIT_POINT;
/*
* Found a free buffer with enough space. Carve out the exact buffer size
* needed from the end of the free buffer.
*/
LocalMemBuf = (MemBufHdr *)(FreeMemBuf->MemBuf +
FreeMemBuf->size -
sizeToAlloc);
/*
* The pointer to the free memory must be longword aligned. If it
* is not, adjust the size to allocate and try again.
*/
{
int alignBytes = (int)LocalMemBuf % 4;
if (alignBytes) {
sizeToAlloc += (4-alignBytes);
keepTrying = false;
}
}
}
/* Set up the new packet's info. */
LocalMemBuf->memBufPrev = NULL;
LocalMemBuf->memBufNext = NULL;
LocalMemBuf->MemBuf = (char *)LocalMemBuf + sizeof(MemBufHdr);
LocalMemBuf->size = size;
/* Insert the newly created buffer into the InUseQueue. */
inUseQueueInsert(LocalMemBuf);
/* Update the free packet's size to reflect giving up a piece. */
FreeMemBuf->size -= sizeToAlloc;
EXIT_POINT:
if (LocalMemBuf) {
#ifdef VERBOSE
numBytesAllocated += sizeToAlloc;
printf("nBytes allocated: %d out of %d.n", numBytesAllocated, EXTMODE_STATIC_SIZE);
#endif
return LocalMemBuf->MemBuf;
}
#ifdef VERBOSE
printf("nBytes allocated: %d out of %d.", numBytesAllocated+sizeToAlloc, EXTMODE_STATIC_SIZE);
printf("nMust increase size of static allocation!n");
#endif
return NULL;
}
奇怪的是这两个函数并非是类的成员函数,为什么加上了PUBLIC?,且这两个函数的定义中(甚至整个mem_mgr.c文件)并未包含calloc和 malloc,虽然mem_mgr.c包含了stdlib.h,另外从makefile中可以看出mem_mgr.c比test2_data.c先编译
|
看着有点晕……
这个都是函数声明冲突,和函数定义没有关系。所以楼主不用看任何.c文件,看头文件就可以了。
可以看看预处理的结果:把make的时候编译test2_data.c的gcc命令行复制出来,加个-E参数,然后在输出的结果里面找找ExtModeCalloc看看到底声明成了什么样子
这个都是函数声明冲突,和函数定义没有关系。所以楼主不用看任何.c文件,看头文件就可以了。
可以看看预处理的结果:把make的时候编译test2_data.c的gcc命令行复制出来,加个-E参数,然后在输出的结果里面找找ExtModeCalloc看看到底声明成了什么样子
|
这就不明白了。
难道前面的某些头文件里面有这种东西? #define calloc ExtModeCalloc
难道前面的某些头文件里面有这种东西? #define calloc ExtModeCalloc