编译程序给出“未定义的引用”

时间:2012-11-16 01:11:56

标签: c++

我迷失在这里。我一直在我的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

2 个答案:

答案 0 :(得分:2)

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

答案 1 :(得分:1)

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

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

进行关联时
相关问题