gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 07:20:35 24 4
gpt4 key购买 nike

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

项目1.cpp

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

using namespace std;

int main (void)
{

PopulateDB x;
x.calcUpload();


return 0;
}

填充数据库.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 &);
};

填充数据库.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)
{
}

技术.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);

};

技术.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++ 的新手,而且代码在目前的状态下并没有做太多事情。

非常感谢所有帮助

谢谢,尼克

最佳答案

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

在你的实现文件中,制作它

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

关于c++ - VC++ 2010 项目中的链接器错误 1120。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19529913/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com