簡體   English   中英

用 g++ 編譯 FLTK

[英]Compile FLTK with g++

我正在使用 C++ 完成 Stroustrup 的原則和實踐。 我正在嘗試編譯以下程序。

#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();
}

我嘗試用g++ -std=c++11 trial.cpp -o trial編譯它,但它拋出了以下錯誤

    /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

我從終端安裝了 FLTK 1.3 版。 我在我的電腦上運行 Linux mint 17。 我如何編譯這段代碼?

您必須將其與庫鏈接:

g++ -std=c++11 trial.cpp -lfltk -o trial

對於您的代碼,這個庫就足夠了,但根據您使用的類,您可能還需要添加: -lfltk_forms -lfltk_gl -lfltk_images

您還可以使用此處提到的fltk-config

g++ -std=c++11 `fltk-config --cxxflags` trial.cpp  `fltk-config --ldflags` -o trial

注意:在代碼文件(cpp 和包含)之后使用鏈接參數 (-l) 很重要,否則會出現編譯錯誤。

fltk-config 是一個不錯的選擇,但如果您想使用更多標志或更改它們,請嘗試此操作。

$ fltk-config --compile your_file >> makefile

現在你有了所有的標志。 您可以使用 --cxxflags 但這種方式有效。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM