我迷失在這裏。我一直在我的Mac上的LLVM上成功編譯我的程序,但是當我去到Linux服務器並嘗試使用g ++編譯時,我遇到了一些鏈接器錯誤。編譯程序給出「undefined reference」
下面是摘錄:
/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
會有道理。我把Graph.cpp放在一個名爲'include'的文件夾中,我的其他文件就是一個目錄。我怎樣才能鏈接這個文件?我編輯了我的原始帖子,以顯示我目前正在編譯的內容。 – Yep
通常,'include'目錄只包含'.h'文件。但無論如何,你可以做這樣的事情:'g ++ - 4.6 -std = C++ 0x * .cpp include/Graph.cpp -lfltk -lfltk_images' –
你知道,我剛剛擺脫包含目錄和哦,好主嗎?工作。你讓我從那裏得到了一些灰頭髮,我的好人。願原力與你同在。 – Yep