我正在使用Eclipse-CDT在Ubuntu x64上设置一个C++项目.我基本上是在打招呼世界并链接到商业第三方图书馆.
我已经包含了链接到其库的头文件,但我仍然遇到链接器错误.除了明显的问题之外,这里是否存在一些可能的问题(例如我99%肯定我正在链接到正确的库).
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: *** …
在编译以下头文件时,我得到了一个未定义的引用"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)
我找不到这个有什么问题.
这个问题可能是重复的,但我不确定,因为我的程序在一个文件中.
// 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退出状态