Nov 23, 2009

Vs2008: Error Lnk2019

free web hosting
Open Discussion & Free Web Hosting > Computers & Tech > Programming > Programming General > C, C++ & Visual C++

Vs2008: Error Lnk2019

xboxrulz
Hey guys I've got some errors. My friend told me it's missing the body of my function. However, my body is obviously there when you look at this post:

pointofsales.h:
CODE
#define LIMIT 100
void posmath (int *quantity, double *price, char taxable);
void initPOS();

stdheader.h:
CODE
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

pointofsales.cpp:
CODE
#include "stdheader.h"
#include "pointofsales.h"

void initPOS(){
    cout << "Point of Sales" << endl;
    cout << "==============\n" << endl;
    int quantity[LIMIT], intCount = 0;
    double price[LIMIT];
    char taxable[LIMIT];
    do {
        cout << "Quantity: ";
        cin >> quantity[intCount];
        if (quantity[intCount] == 0){
            intCount--;
            break;
        }
        cout << "Price: ";
        cin >> price[intCount];
        cout << "Taxable [y/n]: ";
        cin >> taxable[intCount];
        intCount++;
    } while (intCount <= LIMIT);
    posmath(quantity, price, *taxable);
}

libpos.cpp (not finished):
CODE
#include "stdheader.h"
#include "pointofsales.h"

void posmath (int *quantity, double *price, char *taxable){
    int i, tqty = 0;
    double tprice = 0, sprice = 0, ptax[LIMIT], ftax[LIMIT];
    for (i = 0; i <= LIMIT; i++){
        tqty += quantity[i];
        if (*taxable == 'y'){
            ftax[i] = price[i] * 0.05;
            ptax[i] = price [i] * 0.08;
        }
        price[i] = price[i] + ftax[i] + ptax[i];
    }

}


Build Error:
QUOTE
1>------ Build started: Project: Workshop2, Configuration: Debug x64 ------
1>Linking...
1>pointofsales.obj : error LNK2019: unresolved external symbol "void __cdecl posmath(int *,double *,char)" (?posmath@@YAXPEAHPEAND@Z) referenced in function "void __cdecl initPOS(void)" (?initPOS@@YAXXZ)
1>D:\devel\c++\Workshop2\x64\Debug\Workshop2.exe : fatal error LNK1120: 1 unresolved externals
1>Build log was saved at "file://d:\devel\c++\Workshop2\Workshop2\x64\Debug\BuildLog.htm"
1>Workshop2 - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


This is a console application, I tried both compiling it to x86 and x86_64.

Please help?

Thanks,
xboxrulz

 

 

 


Comment/Reply (w/o sign-up)

turbopowerdmaxsteel
Modify the second line in your pointofsales.h to: void posmath (int *quantity, double *price, char *taxable);. Notice the missing * for the third parameter.

You need to do two more changes. Change the 22nd line in pointofsales.cpp to } while (intCount < LIMIT); and line 7 of libpos.cpp to for (i = 0; i < LIMIT; i++){. This will prevent a runtime stack error from throwing up because you are trying to access an element at an index greater than that of the declared arrays' size. If the array was not zero-based like we have in Visual Basic, you would have to check the upper bound with the <= operator and initialize the lower bound with 1. For zero-based arrays it is 0 for the lower and < [Size] for the upper bound checking operator.

Comment/Reply (w/o sign-up)

xboxrulz
Thanks, I can't believe I made such novice mistakes.

I forgot that I was telling it to count more than the LIMIT allows.

The compiler should be more specific because the error made no sense to me.

Thanks,
xboxrulz

Comment/Reply (w/o sign-up)

xboxrulz
After added structs, I'm getting LNK2019 errors again. What exactly is this LNK2019 error?

CODE
/*  pointsofsales.h
*  Workshop1's Point of Sales header file.
*  Copyright (C) 2009 Adrien Kwok.
*
*  This program is free software: you can redistribute it and/or modify
*  it under the terms of the GNU General Public License Version 3
*  as published by the Free Software Foundation.
*
*  This program is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU General Public License for more details.
*
*  You should have received a copy of the GNU General Public License
*  along with this program.  If not, see <http://www.gnu.org/licenses/>.
*
*/
#define LIMIT 100
struct POS{
        int quantity[LIMIT];
        double price[LIMIT], ftax[LIMIT], ptax[LIMIT], tftax, tptax;
        char taxable[2];
};
void posmath(struct POS sales, int *intCount, double *total, double *stotal);
void initPOS();


CODE
/*  pointofsales.cpp
*  Workshop1's Point of Sales program file.
*  Copyright (C) 2009 Adrien Kwok.
*
*  This program is free software: you can redistribute it and/or modify
*  it under the terms of the GNU General Public License Version 3
*  as published by the Free Software Foundation.
*
*  This program is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU General Public License for more details.
*
*  You should have received a copy of the GNU General Public License
*  along with this program.  If not, see <http://www.gnu.org/licenses/>.
*
*/

#include "stdheader.h"
#include "pointofsales.h"

void initPOS(){
    system("cls");
    cout << "Point of Sales" << endl;
    cout << "==============\n" << endl;
    struct POS sales;
    int intCount = 0;
    double total, stotal;
    do {
        cout << "Quantity: ";
        cin >> sales.quantity[intCount];
        if (sales.quantity[intCount] != 0){
            cout << "Price: ";
            cin >> sales.price[intCount];
            cout << "Taxable [y/n]: ";
            cin >> sales.taxable[intCount];
            intCount++;
        }
    } while (intCount < LIMIT && sales.quantity[intCount] != 0);
    posmath(sales, &intCount, &total, &stotal);
    cout << "\n" << endl;
    printf("Subtotal: %.2lf\n", stotal);
    printf("GST (5%): %.2lf\n", sales.tftax);
    printf("PST (8%): %.2lf\n", sales.tptax);
    printf("Total: %.2lf\n", total);
    cout << "\n" << endl;
}


CODE
/*  libpos.cpp
*  Workshop1's Point of Sales library file.
*  Copyright (C) 2009 Adrien Kwok.
*
*  This program is free software: you can redistribute it and/or modify
*  it under the terms of the GNU General Public License Version 3
*  as published by the Free Software Foundation.
*
*  This program is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU General Public License for more details.
*
*  You should have received a copy of the GNU General Public License
*  along with this program.  If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "stdheader.h"
#include "pointofsales.h"

void posmath (POS& sales, int *intCount, double *total, double *stotal){
    int i;
    for (i = 0; i < (*intCount); i++){
        if (sales.taxable[i] == 'y'){
            sales.ftax[i] = sales.price[i] * 0.05;
            sales.ptax[i] = sales.price[i] * 0.08;
        } else {
            sales.ftax[i] = 0;
            sales.ptax[i] = 0;
        }
        sales.tftax += sales.ftax[i];
        sales.tptax += sales.ptax[i];
        *stotal += (sales.quantity[i] * sales.price[i]);
        *total += (sales.quantity[i] + sales.ftax[i] + sales.ptax[i]);
        cout << *stotal << endl;
        cout << *total << endl;
    }
}


Many thanks,
xboxrulz

 

 

 


Comment/Reply (w/o sign-up)


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)


See Also,

*SIMILAR VIDEOS*
Searching Video's for Vs2008:, Error, Lnk2019
advertisement



Vs2008: Error Lnk2019

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com