FLTK 不适用于 Stroustrup 标头
我目前正在通过 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 上编译它。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在我看来,当您调用编译器时,在
/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.我使用以下步骤在 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.
#include <cstdlib>
to the file std_lib_facilities.h to avoid an atoi not declared error in the next stepmake
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.aRun the a.out executable
使用 PDF FLTK-Tutorial.pdf 中的源代码中的示例程序,
我必须添加以下行才能在我的 Ubuntu Linux 中进行干净的编译。
您必须正确配置编译行。 FLTK 有 fltk-config 工具来帮助进行配置。
fltk-config
获取 fltk-config 的帮助消息。阅读输出以确定您需要为编译、链接以及您正在使用的包的任何兼容性(gl、glut、forms 等)添加哪些内容。
将此信息复制到您的编译命令中。
您还可以使用
--compile prgrname.cxx
开关直接编译。包含 -g 因为您需要 gdb 支持。例如:
给出(对我来说):
添加输出名称和输入程序:
虽然 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.
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:
Gives (for me):
Add an output name and the input programs:
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.