PLEASE HELP! WAITING ONLINE! error LNK2019: unresolved external symbol referenced in function
<p>Please help......I am crazy about this problem....tried but nothing works...</p>

<p>I got three LNK2019 errors:</p>

<blockquote>
  <p>optimal.obj : error LNK2019: unresolved external symbol "double * __cdecl matm(int,int,int,double *,double *)" (?matm@@YAPANHHHPAN0@Z) referenced in function _main</p>
  
  <p>optimal.obj : error LNK2019: unresolved external symbol "int __cdecl readfile(char *,double * *,double * *,double * *,double * *,int *,double *)" (?readfile@@YAHPADPAPAN111PAHPAN@Z) referenced in function _main</p>
  
  <p>optimal.obj : error LNK2019: unresolved external symbol "int __cdecl strtrim(char *)" (?strtrim@@YAHPAD@Z) referenced in function "int __cdecl parse_cplex_log(int,double *)" (?parse_cplex_log@@YAHHPAN@Z)</p>
  
  <p>C:\Users\~~~~\Dropbox\Programming\C++\~~\Debug\HW3.exe : fatal error LNK1120: 3 unresolved externals</p>
</blockquote>

<p>Source code:</p>

<pre><code>#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;string.h&gt;
#include &lt;sys/types.h&gt;
#include &lt;sys/stat.h&gt;
#include &lt;math.h&gt;
#include &lt;windows.h&gt;

#define LOGNOTFOUND 1
#define NOTOPTIMAL 2
#define BADLOGFILE 4
#define NOMEMORY 5
#define NOTYPEA 3
#define EPSILON 1.0e-05
#define MAXSTEP 500

double *matm(int la, int mid,int lb,double *a, double *b);
int writelpfile_and_script(double *g, double *x, int n,double *l, double *u);
void remove_if_exists(char *filename);
char does_it_exist(char *filename);
int solve();
int parse_cplex_log(int n, double *a);
int readfile(char *filename, double **retv,double **cov, double **lb,double **ub, int*    nsec,double *lda);
double getsigma(double lambda,double *y, double *Q, double *x, double *mu, int numsec);
int strtrim(char *s);
int main(int argc, char *argv[])
{
    int numsec; int retcode=0,i,j,k,m,d,step=1;
    if(argc &lt;=1){
        printf("usage: solver filename\n"); retcode = 1; goto BACK;
    }


    double *Q; double *mu; double lambda; double *lx; double *ux;   //These should be read through the input file
    double *x;double *x1;double *g;double *y,tmp = 0, sigma;
    retcode = readfile(argv[1],&amp;mu,&amp;Q,&amp;lx,&amp;ux,&amp;numsec,&amp;lambda);
    // to check the input file
    for (i=0;i&lt;numsec;i++){
        if (lx[i]&gt;ux[i]){
            printf("Error: please check the bounds of the input file!\n");
            retcode = 1;
            goto BACK;
        }
    }
    double *qx;
    qx = (double *)calloc(numsec,sizeof(double));
    x=(double *)calloc(numsec,sizeof(double));
    x1=(double *)calloc(3*numsec,sizeof(double));
    y=(double *)calloc(numsec,sizeof(double));
    g=(double *)calloc(numsec,sizeof(double));
    //==================================  Step 1 ==================================

    //initial x, in this case we manully define this initial value
    double checksum1 = 0, checksum2 = 0, residual1,residual2,test,result[3],ret =   100000;

    for (i=0;i&lt;numsec;i++) checksum2 += ux[i];

    if (checksum2 &lt; 1-EPSILON){
        printf("There is no feasible solution for this program!");
        retcode = 1;
        goto BACK;
    }
    for (i=0;i&lt;numsec;i++) checksum1 += lx[i];
    if (checksum1 &gt; 1+ EPSILON){
        printf("There is no feasible solution for this program!");
        retcode = 1;
        goto BACK;
    }

    //  ------------------ to generate one initial vector -----------------------
    for (i=0;i&lt;numsec;i++) x1[i] = lx[i];

    if ((1-EPSILON&lt;checksum1)&amp;&amp;(checksum1 &lt; 1+EPSILON)){
        printf("Already found a feasible solution");
    }
    else{
        i = 0;
        residual1 = 1 - checksum1;
        while ((ux[i]-lx[i])&lt;residual1){
            checksum1 += (ux[i] - lx[i] );
            x1[i] = ux[i];
            residual1 = 1 - checksum1;
            i++;
        }
        x1[i] += residual1;

    }
    //  ------------------to generate another initial vector --------------------
    for (i=0;i&lt;numsec;i++) x1[numsec+i] = ux[i];

    if ((1-EPSILON&lt;checksum2)&amp;&amp;(checksum2 &lt; 1+EPSILON)){
        printf("Already found a feasible solution");
    }
    else{
        i = 0;
        residual2 = checksum2 - 1;
        while ((ux[i]-lx[i])&lt;residual2){
            checksum2 -= (ux[i] - lx[i] );
            x1[numsec+i] = lx[i];
            residual2 = checksum2 - 1;
            i++;
        }
        x1[numsec+i] -= residual2;
    }
    //  ------------------to generate a third initial vector --------------------
    for (i=0;i&lt;numsec;i++) x1[2*numsec+i] = (x1[i] + x1[numsec+i])/2.0;


    //==================================  Step 2 ==================================
    //=========================== Step 2(a) =======================================
    for (m=0;m&lt;3;m++){
        step = 0;
        for ( i=0;i&lt;numsec;i++) x[i] = x1[m*numsec+i];

        for ( i=0;i&lt;numsec;i++)
        {
            *(g+i)=2*(*(matm(numsec,numsec,1,Q,x)+i))-*(mu+i);
        }
        //========================= Step 2(b) ========================================
        while (step &lt; MAXSTEP)
        {
            retcode=writelpfile_and_script(g,x,numsec,lx,ux);

            if (!retcode)   retcode=solve();
            if (!retcode)
            {
                retcode=parse_cplex_log(numsec,y);
                test = *(matm(1,numsec,1,g,y));
                if (test&lt;0)
                {
                    //============================== Step 2(c) ==========================================
                    sigma=getsigma(lambda,y,Q,x,mu,numsec);
                    if (sigma &lt; 0) break;
                    else if (sigma &gt; 1) sigma = 1;
                    for (i=0;i&lt;numsec;i++){
                        x[i] += sigma*y[i];
                    }
                }
                else break;
            }
            step++;
        }
        printf("step = %d \n",step);
        qx = matm(numsec,numsec,1,Q,x);
        result[m]=*(matm(1,numsec,1,x,qx))*lambda-*matm(1,numsec,1,mu,x);
        printf("With initial vecotr x%d, the optimal value is: %f \n",m+1,result[m]);
        printf("The optimal solution is: \n");
        for (i=0;i&lt;numsec;i++) {
            printf("x_%d = %f\n",i+1,x[i]);
            x1[m*numsec+i] = x[i];
        }
        // to choose the smaller optimal value
        if (ret&gt;result[m]){
            ret = result[m];
            d = m;
        }
    }
    printf("The final optimal value is: %f\n",ret);
    printf("The final optimal solution is:\n");
    // to get the final optimal solution
    for (i=0;i&lt;numsec;i++){
        x[i] = x1[d*numsec+i];
        printf("solution_%d = %f\n",i+1,x[i]);
    }
BACK:
    return retcode;
    free(x);free(x1);free(y);free(g);free(qx);

}
int writelpfile_and_script(double *g, double *x, int n,double *l, double *u)
{
    //if successful, return 0, otherwise return 1
    int retcode = 0, i, j;
    double thisg;
    double thisdev;
    double diff1;
    double diff2;

    FILE *out = NULL;
    remove_if_exists("partb.lp");
    out = fopen("partb.lp", "w");
    if(out == NULL){
        printf("cannot write LP\n"); retcode = 1; goto BACK;
    }
    //write obj function
    fprintf(out,"Minimize ");
    for(j = 0; j &lt; n; j++){
        thisg = *(g+j);
        if(thisg!= 0){
            if(thisg&gt; 0) fprintf(out," +");
            fprintf(out," %g x_%d", thisg, j);
        }
    }
    //write constraints
    fprintf(out,"\nSubject to:\n");

    for(i = 1; i &lt;= 1; i++){
        fprintf(out,"S_%d: ", i);
        for(j = 0; j &lt;(n-1); j++)
        {
            fprintf(out,"x_%d + ",j);
        }
        fprintf(out,"x_%d = 0\n",n-1);
    }

    fprintf(out,"Bounds\n");
    for(j = 0; j &lt;n; j++){
        fprintf(out,"x_%d &lt;= %g\n", j,*(u+j)-(*(x+j)));
        fprintf(out,"x_%d &gt;= %g \n",j,*(l+j)-(*(x+j)));
    }

    fprintf(out,"END\n");

    fclose(out);

    printf("wrote LP to file partb.lp\n");

    out = fopen("gocplex","w");
    if(out == NULL){
        retcode = 1;
        goto BACK;
    }

    fprintf(out,"r partb.lp\n o \n d sol var - \n xecute ren hidden.dat signal.dat\n       quit\n");
    fclose(out);

BACK:
    return retcode;
}
void remove_if_exists(char *filename)
{
    if( does_it_exist(filename) == 0){
        remove(filename);
    }
}
char does_it_exist(char *filename)
{
    struct stat buf;

    // the function stat returns 0 if the file exists

    if( 0 == stat(filename, &amp;buf) ){
        return 0;
    }
    else return 1;
}
int solve()
{
    //if successful return 0
    int retcode = 0, maxtries, numtries;
    FILE *input = NULL;
    char signalfound, fileisthere;

    //remove_if_exists will remove (delete) a file if it exists

    remove_if_exists("cplex.log");
    remove_if_exists("signal.dat");
    remove_if_exists("solution.dat");

    fileisthere = does_it_exist("hidden.dat");

    if(fileisthere == 1){
        input = fopen("hidden.dat", "w");
        if(input == NULL){
            printf("cannot create hidden file -- quitting\n");
            retcode = 1; goto BACK;
        }
        fclose(input);
    }

    fileisthere = does_it_exist("partb.lp");
    if(fileisthere == 1){
        printf("error: LP file not found\n");
        retcode = 1; goto BACK;
    }

    // now we can run the cplex script

    system("cplex &lt; gocplex");

    signalfound = 0;
    maxtries = 500;
    for(numtries = 1; numtries &lt; maxtries; numtries++){
        fileisthere = does_it_exist("signal.dat");  //0 if the file exists
        if(fileisthere == 0){
            printf("\ncplex done!\n");
            signalfound = 1;
            break;
        }
        else{
            Sleep(100);
        }
    }

    if(signalfound == 0) retcode = 2;

BACK:
    return retcode;

}
int parse_cplex_log(int n,double *solution)
{

    int retcode = 0, j = 0, optstatus = 0;
    FILE *input;
    char buffer[81];
    double objval;

    for (j = 0;j&lt;n;j++) solution[j] = 0;

    input = fopen("cplex.log", "r");
    if(input == NULL){
        optstatus = LOGNOTFOUND; goto BACK;
    }

    for(;;){
        if((EOF == fscanf(input,"%s",buffer))){
            optstatus = NOTOPTIMAL; goto BACK;
        }
        if(0 == strcmp(buffer, "Optimal:"))
            break;
    }

    //if we are here, the problem was optimized

    fscanf(input,"%s",buffer); fscanf(input,"%s",buffer);
    fscanf(input,"%s",buffer);

    objval = atof(buffer);

    for(;;){
        if((EOF == fscanf(input,"%s",buffer))){
            optstatus = BADLOGFILE; goto BACK;
        }
        if(0 == strcmp(buffer, "Variable"))
            break;
    }

    fscanf(input,"%s",buffer); fscanf(input,"%s",buffer);
    fscanf(input,"%s",buffer);

    int test = 0;
    char x[10];

    strcpy(x,"x");

    for(;;){
        char c[2];

        if (EOF == fscanf(input,"%s",buffer) )
            break;
        sscanf(buffer, "%1s", c);
        if (strcmp(c,x)) break;

        j = strtrim(buffer);

        fscanf(input, "%s", buffer);
        solution[j] = atof(buffer);
    }

    fclose(input);
    goto BACK;

BACK:

    return retcode;
}

double getsigma(double lambda,double *y, double *Q, double *x, double *mu, int numsec)
{   
    double sigma,uy=0,*qy,*yqy,*xqy;
    for (int i=0;i&lt;numsec;i++)
    {
        uy=uy+y[i]*mu[i];
    }
    qy=(double *)calloc(numsec,sizeof(double));
    yqy=xqy=(double *)calloc(1,sizeof(double));

    qy=matm(numsec,numsec,1,Q,y);
    yqy=matm(numsec,1,1,y,qy);
    xqy=matm(numsec,1,1,x,qy);
    sigma=(uy-2*lambda**(xqy))/(lambda**(yqy))/2;

    return sigma;
    free(qy);
    free(yqy); free(xqy);
}
</code></pre>
