错误:被称为对象“0”不是一个函数。

时间:2021-11-07 17:02:42

I receive the following error for my code (client.c):

我的代码(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

Here's the code reduced to an SSCCE:

下面是简化为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;
}

The headers could still be reduced in number (<stdio.h>, "msg.h" and "mfs.h" are the ones likely to be necessary for this to be a true SSCCE).

header仍然可以减少( ,“味精。h”和“mfs。h“可能是这成为真正的SSCCE所必需的。” )。h>

Here's the original code — the line numbers from the compilation apply to this:

这里是原始代码——来自编译的行号应用于此:

#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;
}

Also here's the Makefile:

也这是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

And when I echo $LD_LIBRARY_PATH here's the output: /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/:

当我回回$LD_LIBRARY_PATH时,这里是输出:/afs/ cs.wisc.edu/u/j/j/a/jalal/jalal/jalal/jalal/jalal/j/jalal/jr/2015/03/p5 - linux/:)。

in which /afs/cs.wisc.edu/u/j/a/jalal/fall2013/p5-linux/ is the path to my project files. My best guess is that there's something wrong in the process of linking in Makefile as it seems client.c can't find mfs.h function prototypes which are defined in mfs.c. Here's the list of files in my project directory: 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

其中/afs/ cs.wisc.edu/u/j/j/a/jalal/fall2013/p5 -linux/是我的项目文件的路径。我最好的猜测是,在Makefile中链接的过程中出现了一些错误,因为它似乎是客户端。c找不到mfs。h函数原型,在mfs.c中定义。下面是我的项目目录中的文件列表:bare。img客户机。c的例子。c的例子。img主要。c Makefile mfs。c mfscat * mfs。h mfsput *味精。服务器h。c测试仪。c udp。c udp.h

Please let me know what I am possibly missing in my Makefile and how to fix it.

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

1 个解决方案

#1


1  

I changed my Makefile to the following

我将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

And also changed the following lines in msg.h:

并在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

as they were previously the same name as my prototypes in mfs.h Now it's fixed.

因为它们以前和我在mfs中的原型相同。h现在是固定的。

#1


1  

I changed my Makefile to the following

我将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

And also changed the following lines in msg.h:

并在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

as they were previously the same name as my prototypes in mfs.h Now it's fixed.

因为它们以前和我在mfs中的原型相同。h现在是固定的。