gpt4 book ai didi

c - 错误 : called object ‘0’ is not a function

转载 作者:太空宇宙 更新时间:2023-11-04 03:51:06 25 4
gpt4 key购买 nike

我的代码 (client.c) 收到以下错误:

make
gcc -Wall -c client.c -o client.o
client.c: In function ‘main’:
client.c:34: error: called object ‘0’ is not a function
client.c:41: error: called object ‘1’ is not a function
make: *** [client.o] Error 1

这里的代码简化为 SSCCE :

#include <stdio.h>
#include "udp.h"
#include "mfs.h"
#include "msg.h"
#include <sys/select.h>

#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>

#define BUFFER_SIZE (4096)

char buffer[BUFFER_SIZE];

msg_t msg;

int main(void)
{

int rc = MFS_Init("mumble-02.cs.wisc.edu", 100022);

printf("CLIENT:: about to send message (%d)\n", rc);

rc = MFS_Lookup(10, "hello");
printf("Lookup returned: %d\n", rc);

return 0;
}

header 的数量仍然可以减少(<stdio.h>"msg.h""mfs.h" 可能是真正的 SSCCE 所必需的)。

这是原始代码——编译中的行号适用于此:

#include <stdio.h>
#include "udp.h"
#include "mfs.h"
#include "msg.h"
#include <sys/select.h>

/* According to earlier standards */
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>



#define BUFFER_SIZE (4096)

char buffer[BUFFER_SIZE];

msg_t msg;



int main(void)
{
/*
int sd = UDP_Open(-1);
assert(sd > -1);


struct sockaddr_in saddr;
int rc = UDP_FillSockAddr(&saddr, "mumble-14.cs.wisc.edu", 100022);
assert(rc == 0);
*/
// msg.type = 100;
int rc = MFS_Init("mumble-02.cs.wisc.edu", 100022);




printf("CLIENT:: about to send message (%d)\n", rc);

rc = MFS_Lookup(10, "hello");
printf("Lookup returned: %d\n", rc);
// char message[BUFFER_SIZE];
// sprintf(message, "hello world");
/* rc = UDP_Write(sd, &saddr, (char*)&msg, sizeof( msg));
// printf("CLIENT:: sent message (%d)\n", rc);

struct timeval t;
t.tv_sec=10;
t.tv_usec=1;
fd_set r;
FD_ZERO(&r);
FD_SET(sd, &r);

rc=select(sd+1,&r,NULL,NULL,&t);
if (rc <= 0)
printf("timeout \n");


if (rc > 0) {
struct sockaddr_in raddr;
int rc = UDP_Read(sd, &raddr, (char*)&msg,sizeof(msg));
printf("CLIENT:: read %d bytes (message: '%d')\n", rc, msg.type);
}
*/
return 0;
}

另外还有 Makefile:

CC   = gcc
OPTS = -Wall

all: server client libmfs.so

server: server.o udp.o
$(CC) -o server server.o udp.o

client: client.o mfs.o udp.o
$(CC) -lmem -L. -o client client.o mfs.o udp.o

mfs: mfs.o
$(CC) -o mfs mfs.o

libmfs.so: mfs.o udp.o
$(CC) -c fpic mfs.c udp.c -Wall -Werror
$(CC) -shared -o libmfs.so mfs.o udp.o

%.o: %.c
$(CC) $(OPTS) -c $< -o $@

clean:
rm -f server.o udp.o client.o mfs.o server client libmfs.so

当我echo $LD_LIBRARY_PATH这是输出: /afs/cs.wisc.edu/u/j/a/jalal/fall2013/p5-linux/:/afs/cs.wisc.edu/u/j/a/jalal/fall2013/p5-linux/:/scratch.1/jalal/postgresql/lib/:/scratch.1/jalal/postgresql/lib/:/scratch.1/jalal/postgresql/lib/:

其中/afs/cs.wisc.edu/u/j/a/jalal/fall2013/p5-linux/是我的项目文件的路径。我最好的猜测是在 Makefile 中的链接过程中出现了问题,因为 client.c 似乎找不到 mfs.c 中定义的 mfs.h 函数原型(prototype)。这是我的项目目录中的文件列表:bare.img client.c example.c example.img main.c Makefile mfs.c mfscat* mfs.h mfsput* msg.h server.c tester.c udp.c udp.h

请让我知道我的 Makefile 中可能缺少什么以及如何修复它。

最佳答案

我将我的 Makefile 更改为以下内容

CC   = gcc
OPTS = -Wall

all: server client libmfs.so

server: server.o udp.o
$(CC) -o server server.o udp.o
libmfs.so: mfs.o udp.o
$(CC) -c -fpic mfs.c udp.c -Wall -Werror
$(CC) -shared -o libmfs.so mfs.o udp.o

client: client.o mfs.o udp.o libmfs.so
$(CC) -lmfs -L. -o client client.o mfs.o udp.o

mfs: mfs.o
$(CC) -o mfs mfs.o

#all: server client libmfs.so

%.o: %.c
$(CC) $(OPTS) -c $< -o $@

clean:
rm -f server.o udp.o client.o mfs.o server client libmfs.so

并且还更改了 msg.h 中的以下行:

#define INIT    0
#define LOOKUP 1
#define STAT 2
#define WRITE 3
#define READ 4
#define CREAT 5
#define UNLINK 6
#define SHUTDOWN 7

因为它们之前与我在 mfs.h 中的原型(prototype)同名现在已经修好了。

关于c - 错误 : called object ‘0’ is not a function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20434322/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com