我的代码(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中可能缺少的内容以及如何修复它。
答案 0 :(得分:1)
我将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中的原型同名 现在已经修好了。