我收到以下代码错误(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;
}
报头的数量仍然可以减少(
<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函数原型。下面是我的项目目录中的文件列表: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中的原型同名
现在修好了。