FLTK 不适用于 Stroustrup 标头

发布于 2024-12-23 14:40:55 字数 1341 浏览 3 评论 0 原文

我目前正在通过 Stroustrup 的《编程:使用 C++ 的原理和实践》一书学习 C++,目前正在学习第 12 章。几天以来,我一直在尝试让 FLTK 与特定的标头一起工作。

我已经使用 MacPorts 安装了 FLTK。当我尝试编译包括 Simple_window.h 的代码时,出现以下错误:

bash-3.2# fltk-config --compile main.cpp

/usr/bin/g++-4.2 -arch i386 -I/opt/local/include -pipe -arch i386 -arch i386 
-D_THREAD_SAFE -D_REENTRANT -o main main.cpp -arch i386 -arch i386
 /opt/local/lib/libfltk.a -lpthread -framework Carbon -framework 
ApplicationServices 

Undefined symbols:
  "vtable for Graph_lib::Window", referenced from:
      __ZTVN9Graph_lib6WindowE$non_lazy_ptr in cc1oxcSA.o
     (maybe you meant: __ZTVN9Graph_lib6WindowE$non_lazy_ptr)
  "vtable for Graph_lib::Button", referenced from:
      __ZTVN9Graph_lib6ButtonE$non_lazy_ptr in cc1oxcSA.o
 (maybe you meant: __ZTVN9Graph_lib6ButtonE$non_lazy_ptr)
  "Simple_window::Simple_window(Point, int, int, String const&)", referenced from:
  _main in cc1oxcSA.o
  "Graph_lib::Window::draw()", referenced from:
  vtable for Simple_windowin cc1oxcSA.o
  "typeinfo for Graph_lib::Window", referenced from:
  typeinfo for Simple_windowin cc1oxcSA.o
ld: symbol(s) not found
collect2: ld returned 1 exit status

我不知道这意味着什么。我在此处阅读了答案(SO)。我创建了 .o 文件。我正在尝试使用 fltk-config 在 Mac OS 上编译它。

I'm currently learning c++ with the book Programming: Principles and Practice Using C++ from Stroustrup and am in chapter 12. I'm now trying since days to get FLTK with the specific headers working.

I have installed FLTK with MacPorts. When i'm trying to compile the code including Simple_window.h, i get the following errors:

bash-3.2# fltk-config --compile main.cpp

/usr/bin/g++-4.2 -arch i386 -I/opt/local/include -pipe -arch i386 -arch i386 
-D_THREAD_SAFE -D_REENTRANT -o main main.cpp -arch i386 -arch i386
 /opt/local/lib/libfltk.a -lpthread -framework Carbon -framework 
ApplicationServices 

Undefined symbols:
  "vtable for Graph_lib::Window", referenced from:
      __ZTVN9Graph_lib6WindowE$non_lazy_ptr in cc1oxcSA.o
     (maybe you meant: __ZTVN9Graph_lib6WindowE$non_lazy_ptr)
  "vtable for Graph_lib::Button", referenced from:
      __ZTVN9Graph_lib6ButtonE$non_lazy_ptr in cc1oxcSA.o
 (maybe you meant: __ZTVN9Graph_lib6ButtonE$non_lazy_ptr)
  "Simple_window::Simple_window(Point, int, int, String const&)", referenced from:
  _main in cc1oxcSA.o
  "Graph_lib::Window::draw()", referenced from:
  vtable for Simple_windowin cc1oxcSA.o
  "typeinfo for Graph_lib::Window", referenced from:
  typeinfo for Simple_windowin cc1oxcSA.o
ld: symbol(s) not found
collect2: ld returned 1 exit status

I have no idea what this means. I read the answers here (SO). I created the .o files. I'm trying to compile this on Mac OS with fltk-config.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

浅唱々樱花落 2024-12-30 14:40:55

在我看来,当您调用编译器时,在 /opt/local/lib/libfltk.a 前面应该有一个 -l (破折号 ell)。或者您可以将 /opt/local/lib/libfltk.a 替换为 -L/opt/local/lib -lfltk 这可能更传统。

It seems to me that there should be a -l (dash ell) in front of /opt/local/lib/libfltk.a when you invoke the compiler. Or you could replace /opt/local/lib/libfltk.a with -L/opt/local/lib -lfltk which might be more conventional.

蝶…霜飞 2024-12-30 14:40:55

我使用以下步骤在 Linux 上运行了 FLTK 程序“12.3 第一个示例”:

,然后解压并转到Programming-code/GUI 文件夹。

  • 在该文件夹中,将 #include 添加到文件 std_lib_facilities.h 以避免下一步中出现 atoi not statements 错误
  • 在命令行中运行 make编程代码/GUI 文件夹。这应该创建文件 libbookgui.a。
  • 假设程序名为Example.cpp,运行以下命令:

    gcc `fltk-config --use-forms --use-gl --use-images --ldflags`Example.cpp libbookgui.a

  • 运行a.out 可执行文件

I got the FLTK program '12.3 A first example' working on Linux using the following steps:

then unzip it and go to the Programming-code/GUI folder.

  • In that folder, add #include <cstdlib> to the file std_lib_facilities.h to avoid an atoi not declared error in the next step
  • Run make at the command line in the Programming-code/GUI folder. This should create the file libbookgui.a.
  • Assuming the program is named Example.cpp, run the following command:

    gcc `fltk-config --use-forms --use-gl --use-images --ldflags`Example.cpp libbookgui.a

  • Run the a.out executable

绝對不後悔。 2024-12-30 14:40:55

使用 PDF FLTK-Tutorial.pdf 中的源代码中的示例程序,

我必须添加以下行才能在我的 Ubuntu Linux 中进行干净的编译。

// 3 includes just below are not in the example but are required
// for a clean compile
#include <Fl/x.H>
#include <stdlib.h>
#include <stdio.h>

您必须正确配置编译行。 FLTK 有 fltk-config 工具来帮助进行配置。

fltk-config
获取 fltk-config 的帮助消息。阅读输出以确定您需要为编译、链接以及您正在使用的包的任何兼容性(gl、glut、forms 等)添加哪些内容。

将此信息复制到您的编译命令中。

您还可以使用--compile prgrname.cxx开关直接编译。包含 -g 因为您需要 gdb 支持。

例如:

fltk-config --cxxflags --ldflags

给出(对我来说):

-I/usr/include/freetype2 -g -O2 -D_THREAD_SAFE -D_REENTRANT -Wl,-Bsymbolic-functions -lfltk

添加输出名称和输入程序:

gcc -I/usr/include/freetype2 -g -O2 -D_THREAD_SAFE -D_REENTRANT -Wl,-Bsymbolic-functions -lfltk mousedrawtest.cpp mousedraw.cpp -o b.out

虽然 FLTK 需要学习的内容较少,但它不适合胆小的人。 Erco (Greg Ercolano) 的教程非常出色,并且是针对许多常见挑战的示例代码。 http://seriss.com/people/erco/fltk/

http://www.fltk.org/documentation.php/doc-1.1/basics.html

还有很多其他不错的搜索:FLTK教程

当从简单的示例程序转换为真正的面向对象模型,请记住范围,特别是对于顶层窗口及其内容。

今天,星期三,我对 gdb、作用域和名称空间的了解比星期一要多得多。

Using a sample program from source code found in a PDF FLTK-Tutorial.pdf

I had to add the following lines to get a clean compile in my Ubuntu Linux.

// 3 includes just below are not in the example but are required
// for a clean compile
#include <Fl/x.H>
#include <stdlib.h>
#include <stdio.h>

You must configure your compile line correctly. FLTK has fltk-config tool to help with the configuration.

fltk-config
to get the help message for fltk-config. Read the output to determine what you need to put in for the compile, the link, and any of the compatibility (gl, glut, forms, etc.) for packages you are using.

Copy this information into your compile command.

You can also use the --compile prgrname.cxx switch to compile directly. Include -g because you will want gdb support.

For example:

fltk-config --cxxflags --ldflags

Gives (for me):

-I/usr/include/freetype2 -g -O2 -D_THREAD_SAFE -D_REENTRANT -Wl,-Bsymbolic-functions -lfltk

Add an output name and the input programs:

gcc -I/usr/include/freetype2 -g -O2 -D_THREAD_SAFE -D_REENTRANT -Wl,-Bsymbolic-functions -lfltk mousedrawtest.cpp mousedraw.cpp -o b.out

While there is less to learn for FLTK, it is not for the faint of heart. Erco's (Greg Ercolano) tutorials are excellent and sample code for many common challenges. http://seriss.com/people/erco/fltk/

http://www.fltk.org/documentation.php/doc-1.1/basics.html

There are a number of other good ones search: FLTK tutorial

When converting from simple sample programs to a real object oriented model, keep in mind scope, particularly for the top level window and its contents.

Today, Wednesday, I know much more about gdb, scope, and namespace than I did on Monday.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文