问题描述
我正在使用C ++编写Stroustrup的原则和实践。我试图让下面的程序编译。
#include< FL /
#include< FL / Fl_Box.H>
#include< Fl / Fl_Window.H>
int main()
{
Fl_Window窗口(200,200,窗口标题);
Fl_Box框(0,0,200,200,嘿,我是说,你好,世界!
window.show();
return Fl :: run();
}
我试着用 g ++ -std = c ++ 11 trial.cpp -o trial
但是它引发了以下错误
/ tmp / ccaLRS7L.o:在函数`main'中:
trial.cpp :( .text + 0x26):未定义引用`Fl_Window :: Fl_Window(int,int,char const *)'
trial.cpp (。text + 0x5f):未定义的引用`Fl_Window()。 :: show()'
trial.cpp :(。text + 0x64):未定义的引用`Fl :: run()'
trial.cpp :(。text + 0x84):undefined 'fl_Window ::〜Fl_Window()'
trial.cpp :( .text + 0xae):未定义的引用`Fl_Window ::〜Fl_Window()'
/tmp/ccaLRS7L.o: Fl_Box ::〜Fl_Box()':
trial.cpp :( .text._ZN6Fl_BoxD5Ev] + 0x13):未定义引用`vtable for Fl_Box'
trial.cpp :( .text._ZN6Fl_BoxD2Ev [_ZN6Fl_BoxD5Ev] + 0x1f):未定义引用`Fl_Widget ::〜Fl_Widget()'
collect2:错误:ld返回1退出状态
我从终端安装了FLTK 1.3版。我在我的电脑上运行Linux mint 17。如何编译此代码?
解决方案您必须将其与库链接:
g ++ -std = c ++ 11 trial.cpp -lfltk -o trial
对于你的代码,这个库已经足够了,但根据你使用的类,你可能需要添加:
-lfltk_forms -lfltk_gl -lfltk_images
也可以使用:g ++ -std = c ++ 11`fltk-config --cxxflags` trial.cpp`fltk-config --ldflags` -o trial
注意:在代码文件(cpp和includes)后面加上链接参数(-l)是很重要的,否则会导致编译错误。
I am working through Stroustrup's Principles and Practices using C++. I am trying to get the following program to compile.
#include <FL/Fl.H> #include <FL/Fl_Box.H> #include <Fl/Fl_Window.H> int main() { Fl_Window window(200, 200, "Window title"); Fl_Box box(0,0,200,200,"Hey, I mean, Hello, World!"); window.show(); return Fl::run(); }
I tried compiling it with
g++ -std=c++11 trial.cpp -o trial
but then it threw the following error/tmp/ccaLRS7L.o: In function `main': trial.cpp:(.text+0x26): undefined reference to `Fl_Window::Fl_Window(int, int, char const*)' trial.cpp:(.text+0x50): undefined reference to `Fl_Box::Fl_Box(int, int, int, int, char const*)' trial.cpp:(.text+0x5f): undefined reference to `Fl_Window::show()' trial.cpp:(.text+0x64): undefined reference to `Fl::run()' trial.cpp:(.text+0x84): undefined reference to `Fl_Window::~Fl_Window()' trial.cpp:(.text+0xae): undefined reference to `Fl_Window::~Fl_Window()' /tmp/ccaLRS7L.o: In function `Fl_Box::~Fl_Box()': trial.cpp:(.text._ZN6Fl_BoxD2Ev[_ZN6Fl_BoxD5Ev]+0x13): undefined reference to `vtable for Fl_Box' trial.cpp:(.text._ZN6Fl_BoxD2Ev[_ZN6Fl_BoxD5Ev]+0x1f): undefined reference to `Fl_Widget::~Fl_Widget()' collect2: error: ld returned 1 exit status
I installed FLTK version 1.3 from terminal. I am running Linux mint 17 on my computer. How do I compile this code?
解决方案You have to link it with the libraries:
g++ -std=c++11 trial.cpp -lfltk -o trial
For your code this library is enough, but depending on what classes you use you might need to add:
-lfltk_forms -lfltk_gl -lfltk_images
also.You can also use
fltk-config
as mentioned here:g++ -std=c++11 `fltk-config --cxxflags` trial.cpp `fltk-config --ldflags` -o trial
Note: it is important to have the linking parameters (-l) after your code files (cpp and includes), otherwise you get compile errors.
这篇关于用g ++编译FLTK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!