开发者

Calling a main-like function using argv[]

I have some code here to call minizip(), a boilerplate dirty renamed main() of the minizip program, but when I compile, I get *undefined re开发者_运维技巧ference to `minizip(int, char**)*. Here's the code.

int minizip(int argc, char* argv[]);

void zipFiles(void)
{
 char arg0[] = "BBG";
 char arg1[] = "-0";
 char arg2[] = "out.zip";
 char arg3[] = "server.cs";

 char* argv[] = {&arg0[0], &arg1[0], &arg2[0], &arg3[0], 0};

 int argc = (int)(sizeof(argv) / sizeof(argv[0])) - 1;

 minizip(argc, argv);
}

int minizip(argc,argv)
    int argc;
    char *argv[];
{
    ...
}


Is all of that code in the same file? If not, and if the caller is C++ code and minizip is C code, the caller might need the minizip declaration within an extern "C" block to indicate that it will be calling a C function and therefore will need C linkage.

(Also, don't retype error messages. Copy and paste them so that they are exact. In this case, the compiler most likely reported an undefined reference to minizip(int, char**).)


Why are you declaring the function arguments again in:

int minizip(argc,argv)
    int argc;
    char *argv[];
{
    ...
}

It' should say

int minizip(int argc,char *argv[])
    {
        ...
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜