c++ - 未定义的方法引用

标签 c++ linker

<分区>

我知道有人多次问过这个问题,但他们得到的解决方案并没有解决我的问题(因为我是 C++ 的菜鸟)。

我有 3 个文件。 main.cpp 、Sql.cpp、Sql.hpp。我在我的主要文件中包含了 Sql.hpp。当我从 main 调用方法 getDate() 时,它工作正常。但是,当我从 main 方法调用方法 select() 时,我在标题中得到了错误。以下是两种方法和调用:

选择()

void select(const string table, const string column, const string condition, const string condition_2, const string condition_3) {
    otl_stream s;
    const string select = str(format("SELECT %2% FROM %1% WHERE %3% < 20130619 AND %4% = 'someValue' AND (%5% = 'someValue' OR %5% = 'someValue' ")
        % table % column % condition % condition_2 % condition_3);
    cout << select;

获取日期()

string Sql::getDate() {
    time_t rawtime;
    struct tm *timeinfo;
    char buffer [80];

    time (&rawtime);
    timeinfo = localtime (&rawtime);

    strftime (buffer, 80,"%Y%m%d", timeinfo);
    string date = buffer;

    return date;
}

主要

Sql sql(host, user, pwd, db, driver);
if(sql.open()) {
    cout << "Datenbankverbindung erfolgreich" << endl;
    sql.getDate();
    sql.select(table, column, condition, condition2, condition3);   
}

我得到的错误如下:

g++ "-IC:\\Users\\USERNAME\\Desktop\" -O0 -g3 -Wall -c -fmessage-length=0 -o "src\\Main.o" "..\\src\\Main.cpp" 
g++ -o edv-vac-xml.exe "src\\xml.o" "src\\sql.o" "src\\header\\tinyxml2\\tinyxml2.o" "src\\Main.o" -lodbc32 -lcomctl32 
src\Main.o: In function `main':
C:\Users\USERNAME\Desktop\edv-vac-xml\Debug/../src/Main.cpp:39: undefined reference to `Sql::select(std::string, std::string, std::string, std::string, std::string)'

collect2: ld returned 1 exit status 

最佳答案

如果select应该是sql类的例程。你应该添加

void Sql::select(...) {
 ...
}

关于c++ - 未定义的方法引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17298272/

相关文章:

c++ - 我应该对显然不能抛出的简单函数使用 noexcept 吗?

c++ - 动态链接时英特尔 PARDISO 分解速度较慢

c++ - 惰性符号绑定(bind)失败 : symbol not found

linux - lib{library name}.a/.so 是 Linux 中静态库的命名约定吗?

c++ - 外部库中未定义的 OLE 引用,即使与 libole32 链接时也是如此

java - 使用 JNI 在 .jar 中查找 Java 类

c++ - cin.get() 的运行时错误

c++ - 模板运算符链接器错误

c++ - 使用 unordered_map 而不是 map 时出现链接器错误?

c++ - 正确使用cpp中的定义宏替换函数的名称