VC ++ 2010项目中的链接器错误1120。

时间:2013-10-22 23:06:49

标签: c++ visual-studio-2010 visual-c++ linker-errors

我正在进行我的第一个VC ++项目,并使用以下代码。该项目有以下文件。

Project1.cpp

#include "stdafx.h"
#include <iostream>
#include "PopulateDB.h"

using namespace std;

int main (void)
{

    PopulateDB x;
    x.calcUpload();


    return 0;
}

PopulateDB.h

#pragma once
#include "mysql_connection.h"
#include <cppconn/driver.h>

class PopulateDB
{
public:
    int calcUpload(void);
    PopulateDB(void);
    ~PopulateDB(void);

private:

    int updateMA(sql::Connection &);
};

PopulateDB.cpp

#include "StdAfx.h"
#include "PopulateDB.h"
#include <iostream>
#include "mysql_connection.h"
#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>
#include "Technical.h"

using namespace std;

int updateMA(sql::Connection& con)
{
    sql::Statement *stmt;
    sql::ResultSet *res;
    int i;

    stmt = con.createStatement();
    res = stmt->executeQuery("SELECT * from PriceAMS");

    while(res->next())
    {
        cout << "Symbol " << i << " = " << res->getBlob("Symbol") << endl;
        i++;
    }

    delete stmt;
}

int calcUpload(void)
{
    cout << "Running Connection..." << endl;

    try 
    {
        sql::Driver *driver;
        sql::Connection *con;
        sql::Statement *stmt;
        sql::ResultSet *res;

/* Create a connection */
        driver = get_driver_instance();
        con = driver->connect("tcp://127.0.0.1:3306", "nishantd", "mySQLDB%passWord2013"); //we can initialize the user/pass in constructor
/* Connect to the MySQL test database */
        con->setSchema("testMMDB");
        cout << "Looks like it connected..." << endl;

        updateMA(*con);

        delete con;
    }

    catch (sql::SQLException &e)
    {
        cout << "# ERR: SQLException in " << __FILE__;
        cout << "(" << __FUNCTION__ << ") on line " << __LINE__ << endl;
        cout << "# ERR: " << e.what();
        cout << " (MySQL error code: " << e.getErrorCode();
        cout << ", SQLState: " << e.getSQLState() << " )" << endl;
    }
    return 0;
}


PopulateDB::PopulateDB(void)
{
}


PopulateDB::~PopulateDB(void)
{
}

Technical.h

#pragma once
#include <vector>

class Technical
{
public:

    float StandardMovingAverage(std::vector<float> values);
    float StdDev(std::vector<float> values);
    float Variance(std::vector<float> values);
    int RSI(std::vector<float> values);

    Technical(void);
    ~Technical(void);

};

Technical.cpp

#include "StdAfx.h"
#include "Technical.h"
#include <cmath>
#include <vector>

using namespace std;

float Technical::StandardMovingAverage(vector <float> values)
{
    int sum=0;
    for(int i=0; i < values.size(); i++)
        sum+=values[i];
    return sum/values.size();
}

float Technical::StdDev(vector <float> values)
{
    float E=0;
    float ave = StandardMovingAverage(values); //this function just calculates the mean values
    for(int i=0; i < values.size(); i++)
        E+=(values[i]- ave)*(values[i]- ave);
    return sqrt(1/values.size()*E);
}

float Technical::Variance(vector <float> values)
{
    return StdDev(values)*StdDev(values);
}


Technical::Technical(void)
{
}


Technical::~Technical(void)
{
}

我在VC ++ 2010中收到以下错误。有警告我目前无视

1>Project1.obj : error LNK2001: unresolved external symbol "public: int __thiscall PopulateDB::calcUpload(void)" (?calcUpload@PopulateDB@@QAEHXZ)
1>D:\Project\CPP\Project1\Release\Project1.exe : fatal error LNK1120: 1 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

我正在尝试解决此问题并让我的代码正常工作。它更令人沮丧,因为我怀疑我缺少一些非常基本的东西,因为我是VC ++的新手并且代码目前的形状并没有做太多。

非常感谢所有帮助

谢谢, 尼克

1 个答案:

答案 0 :(得分:1)

您正在调用名为PopulateDB::calcUpload的函数 - 类PopulateDB的成员函数。但是你从未真正实现过这个功能。您确实实现了一个名为::calcUpload的不同的独立非成员函数,但您没有调用它。

在您的实施文件中,将其设为

int PopulateDB::calcUpload() {...}