3

我在这里迷路了。我一直在我的 Mac 上的 LLVM 上成功编译我的程序,但是当我转到 Linux 服务器并尝试使用 g++ 进行编译时,我遇到了大量的链接器错误。

这是一段摘录:

/tmp/ccGbgd6T.o: In function `Scene::setBackgroundImage(String)':
Project.cpp:(.text+0x166): undefined reference to `Graph_lib::Image::Image(Point, String, Graph_lib::Suffix::Encoding)'
/tmp/ccGbgd6T.o: In function `Graph_lib::Window::~Window()':
Project.cpp:(.text._ZN9Graph_lib6WindowD2Ev[_ZN9Graph_lib6WindowD5Ev]+0xc): undefined reference to `vtable for Graph_lib::Window'
/tmp/ccGbgd6T.o: In function `Graph_lib::Shape::~Shape()':
Project.cpp:(.text._ZN9Graph_lib5ShapeD2Ev[_ZN9Graph_lib5ShapeD5Ev]+0xb): undefined reference to `vtable for Graph_lib::Shape'
/tmp/ccGbgd6T.o: In function `Graph_lib::Text::Text(Point, String const&)':
Project.cpp:(.text._ZN9Graph_lib4TextC2E5PointRK6String[_ZN9Graph_lib4TextC5E5PointRK6String]+0xe): undefined reference to `Graph_lib::Shape::Shape()'
Project.cpp:(.text._ZN9Graph_lib4TextC2E5PointRK6String[_ZN9Graph_lib4TextC5E5PointRK6String]+0x17): undefined reference to `vtable for Graph_lib::Text'
Project.cpp:(.text._ZN9Graph_lib4TextC2E5PointRK6String[_ZN9Graph_lib4TextC5E5PointRK6String]+0x67): undefined reference to `Graph_lib::Shape::add(Point)'
/tmp/ccGbgd6T.o: In function `Graph_lib::Button::Button(Point, int, int, String const&, void (*)(void*, void*))':
Project.cpp:(.text._ZN9Graph_lib6ButtonC2E5PointiiRK6StringPFvPvS5_E[_ZN9Graph_lib6ButtonC5E5PointiiRK6StringPFvPvS5_E]+0x40): undefined reference to `vtable for Graph_lib::Button'

这让我很害怕,但后来我注意到所有错误都来自同一个类:Graph_lib. 这是一个非常剪裁的版本Graph.h:(注意,这不是我的课)

#ifndef GRAPH_GUARD
#define GRAPH_GUARD 1

#include <...system stuff...>

namespace Graph_lib {
// lots of other classes in here
// this is just one
    struct Image : Shape {
        Image(Point xy, string file_name, Suffix::Encoding e = Suffix::none);
    //rest of class
    }
}

这里可能出了什么问题?

编辑:这是我用来编译的命令:

g++-4.6 -std=c++0x *.cpp -lfltk -lfltk_images
4

2 回答 2

2

似乎您忘记将项目与 链接Graph.cpp,或者任何包含Graph_lib类方法实现的文件。

于 2012-11-16T01:14:37.260 回答
1

看起来您的图形库丢失了。

使用链接时g++, use -l <Graph lib>

于 2012-11-16T01:15:22.600 回答