相关疑难解决方法(0)

GCC C++链接器错误:未定义引用'vtable for XXX',未定义引用'ClassName :: ClassName()'

我正在使用Eclipse-CDT在Ubuntu x64上设置一个C++项目.我基本上是在打招呼世界并链接到商业第三方图书馆.

我已经包含了链接到其库的头文件,但我仍然遇到链接器错误.除了明显的问题之外,这里是否存在一些可能的问题(例如我99%肯定我正在链接到正确的库).

  1. 有没有办法确认我链接的静态库是64位?
  2. 有没有办法确认该库是否具有我期望它具有的类(和方法)?

Eclipse说:

Building target: LinkProblem
Invoking: GCC C++ Linker
g++ -L/home/notroot/workspace/somelib-3/somelib/target/bin -o"LinkProblem"  ./src/LinkProblem.o   -lsomelib1 -lpthread -lsomelib2 -lsomelib3
./src/LinkProblem.o: In function `main':
/home/notroot/workspace/LinkProblem/Debug/../src/LinkProblem.cpp:17: undefined reference to `SomeClass::close()'
./src/LinkProblem.o: In function `SomeOtherClass':
/home/notroot/workspace/somelib-3/somelib/include/sql/somefile.h:148: undefined reference to `SomeClass::SomeClass()'
/home/notroot/workspace/somelib-3/somelib/include/sql/somefile.h:148: undefined reference to `vtable for SomeOtherClass'
/home/notroot/workspace/somelib-3/somelib/include/sql/somefile.h:151: undefined reference to `SomeClass::~SomeClass()'
./src/LinkProblem.o: In function `~SomeOtherClass':
/home/notroot/workspace/somelib-3/somelib/include/sql/somefile.h:140: undefined reference to `vtable for SomeOtherClass'
/home/notroot/workspace/somelib-3/somelib/include/sql/somefile.h:140: undefined reference to `SomeClass::~SomeClass()'
/home/notroot/workspace/somelib-3/somelib/include/sql/somefile.h:140: undefined reference to `SomeClass::~SomeClass()'
collect2: ld returned 1 exit status
make: *** …

c++ linker g++ eclipse-cdt

70
推荐指数
7
解决办法
15万
查看次数

未定义引用'vtable for class'构造函数

在编译以下头文件时,我得到了一个未定义的引用"vtable for student":

student.h

class student
{
private:
    string names;
    string address;
    string type;

protected:
    float marks;
    int credits;

public:
    student();
    student(string n,string a,string t,float m);
    ~student();
    string getNames();
    string getAddress();
    string getType();
    float getMarks();
    virtual void calculateCredits();
    int getCredits();
};

student::student(){}

student::student(string n, string a,string t,float m)
{
    names = n;
    address = a;
    marks = m;
}

student::~student(){}
Run Code Online (Sandbox Code Playgroud)

我找不到这个有什么问题.

c++ constructor class

41
推荐指数
1
解决办法
9万
查看次数

为什么我的C++编译器说虚拟成员没有定义?

这个问题可能是重复的,但我不确定,因为我的程序在一个文件中.

// my-program.cpp

class A
{
public:
  virtual void foo();
};

class B : public A
{
public:
  void foo() {}
};

int main()
{
  B myB;
}
Run Code Online (Sandbox Code Playgroud)

然后我输入g++ my-program.cpp终端,编译器给我这个警告:

用于体系结构x86_64的未定义符号:"typeinfo for A",引用自:bin信息为cce8BmNY.o"vtable for A",引用自:c :: -inline虚拟成员函数没有定义.ld:找不到架构的符号x86_64 collect2:ld返回1退出状态

c++ g++

2
推荐指数
1
解决办法
114
查看次数

标签 统计

c++ ×3

g++ ×2

class ×1

constructor ×1

eclipse-cdt ×1

linker ×1