tags:

views:

53

answers:

2

I have some code here to call minizip(), a boilerplate dirty renamed main() of the minizip program, but when I compile, I get undefined reference 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[];
{
    ...
}
+2  A: 

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**).)

jamesdlin
This fixed it, thanks.
Jookia
+1  A: 

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[])
    {
        ...
    }
kirbuchi
jamesdlin
Interesting, doesn't work on gcc though
kirbuchi