Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 VS2008: Error LNK2019
Index -> Programming, C++ -> C++ Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
deltatux




PostPosted: Sun Jan 18, 2009 7:23 pm   Post subject: VS2008: Error LNK2019

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,
deltatux
Sponsor
Sponsor
Sponsor
sponsor
OneOffDriveByPoster




PostPosted: Sun Jan 18, 2009 11:19 pm   Post subject: Re: VS2008: Error LNK2019

deltatux @ Sun Jan 18, 2009 7:23 pm wrote:
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.
You function body is missing. You have a function with the same name, but they are not the same function.
DemonWasp




PostPosted: Mon Jan 19, 2009 10:42 am   Post subject: RE:VS2008: Error LNK2019

This is the line from pointofsales.h:
code:

void posmath (int *quantity, double *price, char taxable);


This is the line from libpos.cpp:
code:

void posmath (int *quantity, double *price, char *taxable){


There is a subtle but very important difference between these two lines.
deltatux




PostPosted: Tue Jan 20, 2009 5:05 pm   Post subject: RE:VS2008: Error LNK2019

Thanks, I solved it, there were also additional logic errors found.

However, once I got the compiler working I got another quirk.

Posted Image, might have been reduced in size. Click Image to view fullscreen.

Source code:
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;
        int quantity[LIMIT], intCount = 0;
        double price[LIMIT], ftax[LIMIT], ptax[LIMIT], total = 0, stotal = 0;
        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, ftax, ptax, &total, &stotal, taxable);
        cout << "\n" << endl;
        printf("Subtotal: %.2lf\n", stotal);
        printf("GST (5): %.2lf\n", ftax);
        printf("PST (8): %.2lf\n", ptax);
        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 (int quantity[], double price[], double ftax[], double ptax[], double *total, double *stotal, char *taxable){
        int i = 0;
        for (i = 0; i < LIMIT; i++){
                if (*taxable == 'y'){
                        ftax[i] = price[i] * 0.05;
                        ptax[i] = price[i] * 0.08;
                } else {
                        ftax[i] = 0;
                        ptax[i] = 0;
                }
                *stotal += (quantity[i] * price[i]);
                *total += ((*stotal) + ftax[i] + ptax[i]);
        }
}


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
void posmath(int quantity[], double price[], double ftax[], double ptax[], double *total, double *stotal, char *taxable);
void initPOS();


Any ideas for fixes?

Thanks,
deltatux
OneOffDriveByPoster




PostPosted: Tue Jan 20, 2009 5:56 pm   Post subject: Re: RE:VS2008: Error LNK2019

Please mark GNU source as NFW in the future.
deltatux




PostPosted: Tue Jan 20, 2009 7:40 pm   Post subject: RE:VS2008: Error LNK2019

NFW?

I'm not sure what that is.

deltatux
OneOffDriveByPoster




PostPosted: Tue Jan 20, 2009 11:05 pm   Post subject: Re: RE:VS2008: Error LNK2019

deltatux @ Tue Jan 20, 2009 7:40 pm wrote:
NFW?

I'm not sure what that is.
"Not for work", or rather--clarify to say "don't look at this because it has GPL on it".
deltatux




PostPosted: Wed Jan 21, 2009 1:03 am   Post subject: RE:VS2008: Error LNK2019

When did GPLing things must be for commercial use? This is an education-derived work, I've seen many educational work been GPL'd before. I just don't want people to take my work and abuse it without recognition. I could of released it under a BSD license.

Anyways, thanks for the head's up though. This is a NOT FOR WORK software. It is purely created for educational purposes only. However, you are free to distribute and modify it under the terms of GPL.

All said and done, I still need help on it. If anyone has any ideas to the problem please help.

Many thanks,
deltatux
Sponsor
Sponsor
Sponsor
sponsor
DemonWasp




PostPosted: Wed Jan 21, 2009 9:19 am   Post subject: RE:VS2008: Error LNK2019

Your implementation of posmath ( ) appears to be quite incorrect. Take a closer look at what it actually does.
deltatux




PostPosted: Wed Jan 21, 2009 10:07 pm   Post subject: RE:VS2008: Error LNK2019

Alright I fixed it, it was an array overflow. The loop is looping it more than its limit.

Thanks anyways,
deltatux
Display posts from previous:   
   Index -> Programming, C++ -> C++ Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 10 Posts ]
Jump to:   


Style:  
Search: