Cannot use libclang with Qt - c++

I encountered a strange bug when I tried to use libclang in a Qt application.
test.cpp
#include <QApplication>
#include <QMainWindow>
#include <clang-c/Index.h>
int main (int argc, char *argv[]) {
QApplication a(argc, argv);
QMainWindow w;
w.show();
CXIndex index = clang_createIndex(0, 0);
Q_UNUSED(index)
return a.exec();
}
test.pro
QT += core widgets
TARGET = test
TEMPLATE = app
SOURCES += test.cpp
LIBS += -lclang
Shell commands and output:
$ ls
test.cpp test.pro
$ qmake
$ make
g++ -c -pipe -march=x86-64 -mtune=generic -O2 -pipe -fstack-protector --param=ssp-buffer-size=4 -Wall -W -D_REENTRANT -fPIE -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I/usr/lib/qt/mkspecs/linux-g++ -I. -I/usr/include/qt -I/usr/include/qt/QtWidgets -I/usr/include/qt/QtGui -I/usr/include/qt/QtCore -I. -o test.o test.cpp
g++ -Wl,-O1,--sort-common,--as-needed,-z,relro -Wl,-O1 -o test test.o -lclang -lQt5Widgets -lQt5Gui -lQt5Core -lGL -lpthread
$ ./test
Two passes with the same argument (-alloca-hoisting) attempted to be registered!
Segmentation fault
If I manually run g++ without using qmake, I get the same error:
$ g++ -fPIE test.cpp -o test -I/usr/include/qt -I/usr/include/qt/QtWidgets -lQt5Widgets -lclang
$ ./test
Two passes with the same argument (-alloca-hoisting) attempted to be registered!
Segmentation fault
If I comment the w.show(); line the program compiles and runs even if it enters the main loop without the window shown.
If I comment the CXIndex index = clang_createIndex(0, 0); and Q_UNUSED(index) lines, the program compiles and runs. It enters the main loop with the window visible.
I also compiled this with clang and I get the same error message.
I searched the web and I found only this result with a similar error message but I don't know if and how it can help me: http://comments.gmane.org/gmane.comp.compilers.llvm.devel/34647 .
I am using Qt 5.1 and ArchLinux, I have the clang package (version 3.3) installed which includes the libclang headers and the files /usr/lib/libclang.so and /usr/lib/libclang.a.
What is the reason why this program does not work and how can I fix it?
Update: I've found this page.
Running LIBGL_ALWAYS_INDIRECT=1 ./test works well, but I want more than this. I shouldn't have to set that environment variable to be able to run my program.

I can answer the part of you question about what's going wrong, I don't know how to fix it.
First, removing the CXIndex index = clang_createIndex(0, 0); wouldn't fix things if you didn't have -Wl,--as-needed removing it only fixes it because the linker noticed you didn't actually call into libclang and so didn't actually link your program to it without the CXIndex index = clang_createIndex(0, 0); line.
The reason things a breaking is because whatever Mesa backend you are using (either ATI or NVIDIA) also links against clang. What seems to be happening is that when your program is first loaded and dynamic links resolved the linker goes and loads libclang and other LLVM stuff libclang links to and runs the constructors for global objects, which is how LLVM registers it's built in passes automatically. So at this point all of the built in LLVM passes are registered, then QT starts up and it creates an OpenGL context so Mesa loads the appropriate DRI backend and as it happens on your system that backend uses clang/LLVM, and for some reason it seems that all those constructors run again and LLVM notices that "two" passes (actually the same pass trying to register itself twice) share the same name and aborts your program.
Like I said I don't really know why the constructors are running twice and I don't know how to make it stop. Try asking on the mesa-users mailing list if you don't get an answer there try mesa-dev
Mesa mailing lists: http://mesa3d.org/lists.html
EDIT: You should make sure that your copy of Mesa is linked against the same version of LLVM that you are trying to use, if it's not fixing the pass registration thing will be the least of your problems.
Try doing ls /usr/lib64/llvm/libLLVM-?.?.so if you get two things back you have two versions of libLLVM which is not a problem on it's own, but if you're linking against one version and Mesa links against a different version that might explain things.

Related

GCC can not recognize Qt libraries or/and include files

I am trying to compile my Qt app from console. Here is specs:
MCBC 3.0 (has preinstalled Qt and gcc), Qt 4.6.4, gcc v4.1.2, qmake v2.01a.
My test qt app contains only 2 files: basket.pro and main.cpp.
basket.pro:
TARGET = basket
TEMPLATE = app
SOURCES += main.cpp
HEADERS +=
main.cpp:
#include <QtGui/QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
return a.exec();
}
I need to compile that app from console.
I got 2 virtual machines. VM #1 has installed QtCreator, and QtCreator compile this app without troubles, also app can be compiled from the console by "qmake" and "make". But there is VM#2, which does not have installed QtCreator, and it is where problems come from.
I tried compile app by commands "qmake make", trying to use Makefile, created by QtCreator, trying to use only gcc comands with explicitly defined paths to Qt libs, include-files and linked libs, but always I got the same errors. For example, I use 2 gcc comands, which used by QtCreator for successful compile this app:
g++ -c -pipe -g -Wall -W -D_REENTRANT -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/lib/qt46/mkspecs/linux-g++ -I. -I/usr/lib/qt46/include/QtCore -I/usr/lib/qt46/include/QtGui -I/usr/lib/qt46/include -I. -o main.o main.cpp
g++ -o basket main.o -L/usr/lib/qt46/lib -lQtGui -L/usr/lib/qt46/lib -lQtCore -lpthread
And so after executing second command I got same error as always:
[root#ARM basket]# ./build_g++_step2
main.o: In function `basic_string<char, string_char_traits<char>, __default_alloc_template<true, 0> >::data(void) const':
/usr/lib/gcc-lib/i586-linux/2.95.4/../../../../include/g++-3/std/bastring.h:152: undefined reference to `QApplication::QApplication(int &, char **, int)'
/usr/lib/gcc-lib/i586-linux/2.95.4/../../../../include/g++-3/std/bastring.h:152: undefined reference to `QApplication::exec(void)'
/usr/lib/gcc-lib/i586-linux/2.95.4/../../../../include/g++-3/std/bastring.h:152: undefined reference to `QApplication::~QApplication(void)'
/usr/lib/gcc-lib/i586-linux/2.95.4/../../../../include/g++-3/std/bastring.h:152: undefined reference to `QApplication::~QApplication(void)'
collect2: ld returned 1 exit status
Please tell what I missed.
Your GCC compiler is version 2.95 (a much too old version from the previous century, which is not conforming to C++11 standard, and which was known to be quite buggy), since /usr/lib/gcc-lib/i586-linux/2.95.4/is used. Run simply g++ -v or g++ --version to check the version of your compiler. (You could have some PATH issue, or you could have misinstalled your build tools).
You should upgrade your compiler to some much newer version (at least GCC 6 and preferably GCC 7 in july 2017)
BTW, I recommend upgrading also your Qt library. Current version (in july 2017) is Qt5.9 and you should use some Qt5.
Then you need to regenerate your makefile, adding more in QT, as answered by ilbeldus
Notice that you could use pkg-config to help compiling Qt applications (perhaps in your Makefile). You still need to explicitly use moc. For example you might compile some Qt C++ GUI file foo.cc (after having used moc) with e.g.
g++ -Wall -g -c $(pkg-config --cflags Qt5Gui) foo.c
and you would use $(pkg-config --libs Qt5Gui) for link options.
I don't recommend using your old MCBC thing (even with googling I didn't find what that is), notably if it is so obsolete.
You are missing the setup of the QT variable in your .pro file.
Add QT += core gui to it, re-run qmake and try to recompile
See the docs here: http://doc.qt.io/qt-4.8/qmake-variable-reference.html#qt

Creating a GUI using Qt

Is it possible to create user interfaces using the Qt framework without utilizing the Qt Creator program? It seems that when using this program half of the work must be done by you anyway, so why not learn how it works more fundamentally (insofar as the Qt API is concerned) and implement the programs yourself?
It seems that Qt implements XML files and does a lot of heavy lifting for you when using the creator program (i.e. automatically including class member functions, etc). I have previously implemented GUIs in Java and did not have to dabble in XML. Does Java handle this behind the scenes, or does Qt approach the problem differently?
Qt has more than way to create a GUI. There is the old QtWidgets module which works with "classical" desktop UI widgets and has a C++ API. The XML file is just a convenient way to describe your interface, qmake will generate C++ headers from the XMLs and generate a lot of the boilerplate for you.
If you prefer, you can do all the work yourself entirely in C++ by instantiating the various QWidget subclasses (QMainWindow, QLabel, etc.) and using their APIs.
(I'm not familiar enough with Java to answer that part of the question.)
However, I suggest you to take a look at Qt Quick which allows for a better and more modern way to deal with GUIs, and gives you a lot more freedom. (It's also a lot easier and faster to work with.)
If you want more details on either of them, just write a comment :)
Yes it is possible. I am not going to make any statement on what is the best way because I do not even know how to use Qt Creator. Personally, I just use a text editor to create the source files. I have done that for ten years. I also agree with you on understanding API and structuring of the code.
Yes, here's the code for how to create a simple window and a button.
#include <QApplication>
#include <QPushButton>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QPushButton *quitButton = new QPushButton("Quit", 0);
connect(quitButton, SIGNAL(clicked()), &app, SLOT(quit()));
return 0;
}
A good Qt tutorial:
http://meetingcpp.com/index.php/br/items/an-introduction-into-qt-part-ii.html
QtCreator, if using g++ compiler:
When there are errors in code, allow right-click on errors list then Show Outputs (O shortcut)… and you can see g++ command with all options:
g++ -c -pipe -g -std=gnu++0x -Wall -W -D_REENTRANT -fPIC -D_GLIBCXX_USE_CXX11_ABI=0 -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I../my-project -I. -I../../../anaconda3/include/qt -I../../../anaconda3/include/qt/QtWidgets -I../../../anaconda3/include/qt/QtGui -I../../../anaconda3/include/qt/QtCore -I. -I. -I../../../anaconda3/mkspecs/linux-g++ -o mainwindow.o ../my-project/mainwindow.cpp
So it only creates a MakeFile in build-your-project-title-Debug (or Release). If you edit it, you have all informations:
MAKEFILE = Makefile
####### Compiler, tools and options
CC = gcc
CXX = g++
DEFINES = -D_GLIBCXX_USE_CXX11_ABI=0 -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB
CFLAGS = -pipe -g -Wall -W -D_REENTRANT -fPIC $(DEFINES)
CXXFLAGS = -pipe -g -std=gnu++0x -Wall -W -D_REENTRANT -fPIC $(DEFINES)
INCPATH = -I../sans_titre -I. -I../../../anaconda3/include/qt -I../../../anaconda3/include/qt/QtWidgets -I../../../anaconda3/include/qt/QtGui -I../../../anaconda3/include/qt/QtCore -I. -I. -I../../../anaconda3/mkspecs/linux-g++
…
You can reproduce it or just use QtCreator to define this MakeFile first then run under CLI with:
make

Error using Qt 5.1.1 in code::blocks

I am trying to combine Code::Blocks IDE and Qt 5.1.1 on my win7 32bit. In CB I use MinGW's g++ compiler which supports C++0x.
I downloaded "qt-windows-opensource-5.1.1-mingw48_opengl-x86-offline.exe" and installed at "D:\Qt-library\5.1.1\mingw48_32\".
Then in CB I added three tools named "qmake -project" , "qmake" and "make" at Tools->Configure tools->add.
"qmake -project" with Executable "D:\Qt-library\5.1.1\mingw48_32\bin\qmake.exe", Parameters: "-project -platform win32-g++"
"qmake" with Excutable same as "qmake -project", no parameter;
"make" with Excutable "D:\Qt-library\Tools\mingw48_32\bin\mingw32-make.exe", no parameter
Working directory all set to "${PROJECT_DIR}"
And I clicked project->properties, selected "This is a custom Makefile"
Then I clickd the "qmake -project" menu item in Tools menu which I created as above, qmake generated a .pro file.
Because I use
#include <QApplication>
instead of
#include <QtGui/QApplication>
in main.cpp file so I added "QT += widgets" in the .pro file.
Then click "qmake" in Tools menu, makefiles are generated. If I directly make, it won't compile, because it doesn't support some C++11 grammars,
so I edited the Makefile.Debug and makefile.Release, it looks like:
CC = gcc
CXX = g++
DEFINES = -DUNICODE -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN
CFLAGS = -pipe -fno-keep-inline-dllexport -O2 -Wall -Wextra $(DEFINES)
CXXFLAGS = -pipe -fno-keep-inline-dllexport -O2 -frtti -Wall -Wextra -fexceptions -mthreads $(DEFINES)
I added -std=c++0x at the line CXXFLAGS, so it become
CXXFLAGS = -pipe -std=c++0x -fno-keep-inline-dllexport -O2 -frtti -Wall -Wextra -fexceptions -mthreads $(DEFINES)
(it won't work for my version of MinGW if I use -std=c++11)
Then click "make" in the Tools menu, I get two errors:
I don't know what the hell was that but some how I modified my main function from
int main(int argc, char** argv)
to int qMain(int argc, char** argv). Then make again, the two qMain error disappeared but I got this:
And now, I didn't do any thing, make again, that error disappeared !!!
But generated .exe file won't do anything, either double click or run in command line, nothing would happen (by the way, although I included , I didn't write any Qt code)
If I remove
#include <QApplication>
and build the project in normal way(cancel "This is a custom Makefile" and build directly), my program goes well.
Another thing very weird, I added CONFIG += debug and CONFIG -= release in the .pro file, qmake will generate both Makefile.Debug and Makefile.Release(whatever CONFIG or debug and release is uper or lower case), but generated .o files and .exe files are all in release directory, no debug file, why was that ?
Anyone has any ideas ? I'll be very thankful for your suggestions.
The problem is solved(although not perfectly).
The fact is that the program did do something, but somehow no console window appear(before I add Qt header, I wrote the program in C++ and use cout to print messages), thus no output can be seen, even if I run the program in console. I found this by writing a simple Qt GUI program to print the results, it works. But I don't know the reason why console wouldn't appear with QApplication included but no Qt code in the program (whatever I set project->properties->build targets->select build target options->type to GUI or console).
On the other hand, I can run the Qt GUI program by double clicking the .exe file in the debug directory, but not in Code::Blocks, it pops up "cannot locate program entry InterlockedCompareExchange#12 on dynamic link library libstdc++-6.dll". Thus I can't debug the program through CB.

Linking SDL library in a Makefile, c++

I'm working on a collaborative project and the guy who controls the master branch of the project works on a mac. Because of this, there are a few minor differences in his makefile that don't translate well to me on Windows. I use MinGW to hold my libraries, and compile using g++.
Makefile (as I thought it should go)
bomb: source/Level.cpp source/Level.h source/main.cpp
g++ -o bomb source/Level.cpp source/main.cpp -Wall -I. -I\MinGW\include\SDL -lSDLmain -lSDL -lSDL_image
The Makefile that works for him:
bomb: source/Level.cpp source/Level.h source/main.cpp
g++ -o bomb source/Level.cpp source/main.cpp -Wall -I. -I/Library/Frameworks/SDL.framework/Headers -lSDLmain -lSDL -lSDL_image -framework
My include files for the SDL library are at "C:\MinGW\include\SDL". Using that knowledge, how would I correctly write the makefile? As a side note, the error I get when using my current makefile is:
C:\MinGW\msys\1.0\src\mingwrt/../mingw/main.c:73: undefined reference to 'WinMain#16'
Have you tried adding -lmingw32 to the end of the libraries list? And do you have a int main(int argc, char** argv) function defined somewhere? Also, see the SDL FAQ

Stroustrup's Simple_window.h

I am trying to get the graphics examples to work from Stroustrup's Principles and Practices ...C++, to no avail (yet). I have installed the fltk stuff, and know that is working fine as I managed to get a window to display using with a program suggested in the appendix of his book:
#include <FL/Fl.H>
#include <FL/Fl_Box.H>
#include <FL/Fl_Window.H>
int main(){
Fl_Window window(200,200, "title here");
Fl_Box box(0,0,200,200,"Hey, hello wrld");
window.show();
return Fl::run();
}
However, trying my own using his Simple_window.h (can be found on his site) gives "reference to ‘Window’ is ambiguous", since it's already at usr/include/X11/X.h . So I tried specifying the namespace to the relevant one:
struct Simple_window : Graph_lib::Window { //Changed Window to inc. namespace
Simple_window(Point xy, int w, int h, const string& title );
bool wait_for_button(); // simple event loop
.
.
.
But this gives me a bunch more errors I don't understand:
$ clear; g++ -Wno-deprecated window.cpp -o holz
/tmp/ccIFivNg.o: In function `main':
window.cpp:(.text+0x64): undefined reference to `Simple_window::Simple_window(Point, int, int, String const&)'
/tmp/ccIFivNg.o: In function `Graph_lib::Window::~Window()':
window.cpp:(.text._ZN9Graph_lib6WindowD2Ev[_ZN9Graph_lib6WindowD5Ev]+0x14): undefined reference to `vtable for Graph_lib::Window'
etc.
I feel mastering graphics is going to be a long and rocky road -_-
To anyone in the same predicament, I leave here what I did to finally be able to compile and get the window of the first program with FLTK on section 12.3 of Stroustrup's book "Programming: Principles and Practice using C++, 2nd Edition".
After installing FLTK on Kubuntu 14.04 with
$ sudo apt install libfltk1.3-dev
I could compile the example program on Appendix D with the use of
$ fltk-config --compile fltkTest.cpp
Thanks to this post, I could see how I could finally get it on track with the first example of chapter 12. Comparing the command of cwivagg and Nathan with the command generated with fltk-config, I ended with this command
$ clang++ -I/usr/include/cairo -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng12 -I/usr/include/freetype2 -I/usr/include/cairo -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng12 -g -O2 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_THREAD_SAFE -D_REENTRANT -Wl,-Bsymbolic-functions -lfltk_images -lfltk -lX11 -std=c++11 -o 's12_3_first' 's12_3_first.cpp' Simple_window.cpp Graph.cpp GUI.cpp Window.cpp
I had to add -lfltk_images and -std=c++11
However, now I had to deal with the errors that the compiler gave me. To get a working program, I had to do several changes to the sources that Stroustrup gave on http://www.stroustrup.com/Programming/PPP2code/
I uncommented std_lib_facilities.h on Graph.h
To resolve the ambiguity of Window, I needed to specify Graph_lib::Window on line 9 of Simple_window.h
std_lib_facilities.h on lines 107 and 113 uses a i<0 comparison when i is
unsigned (but these are just warnings).
Graph.h line 159 uses fl_color() but the compiler says it should be Fl_Color
I needed to uncomment the constructors for Point in Point.h
There are several redefinitions on Simple_window.cpp of Simple_window.h
On Simple_window.cpp I commented out the definitions for the constructor,
cb_next and wait_for_button (which is not the same as the one on
Simple_window.h). On Simple_window.h I commented out the definitions of
wait_for_button and next. By the way, wait_for_button does not work in
either form.
In GUI.cpp there is another redefinition for the constructor of Menu. I
commented it out.
I changed the last line of the example of section 12.3
from
win.wait_for_button;
to
Fl::run();
which I took from the example on Appendix D, because otherwise the window does
not close with its close button.
With all these changes I finally have the window as it should be, and the window close either with the Next button or the close button of the said window (with wait_for_button I needed to end the program from Konsole with Ctrl-c after I tried to close it with the close button of the window).
I hope the next person do not have to spend all the time I had to.
Edit: Well, checking at my system and the compiling command, I realized that there are several carpets repeated... and that they actually don't exist in my Kubuntu system. So, I have to write down in my answer what I finally do to get the window working:
To get an object file:
$ clang++ -O2 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_THREAD_SAFE -D_REENTRANT -g -std=c++11 -c Simple_window.cpp
To get the first program that we wanted
% clang++ -O2 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_THREAD_SAFE -D_REENTRANT -Wl,-Bsymbolic-functions -lfltk_images -lfltk -lX11 -g -std=c++11 Simple_window.o Graph.o GUI.o Window.o -o z3 s12_3_first.cpp
These are a hell lot easier (I almost can write them every time I need them)
Well this doesn't really have anything to do with graphics as such. Problem seems to be that you've only included on your command line one of the source files you need to compile. Judging by his web site
g++ graph.cpp GUI.cpp Simple_window.cpp Window.cpp
seems to be more like it. But I have no actual experience of this.
Tomolak, when you said this 'made progress', it pleased me greatly. Don't know if you were being sarcastic, but whatever.
I have solved this problem (or at least I have managed to get a window to appear with a triangle in it). However, this was only after commenting out and editing large portions of Stroustrup's code. I do not feel his book is very suitable for a beginner. I would also not recommend trying to compile any of his examples using Linux.
To anyone googling these issues, my final solution was this command:
$ g++ -Wno-deprecated -I/usr/local/include -I/usr/include/freetype2 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_THREAD_SAFE -D_REENTRANT -o 'windows_working' win_test.cpp Graph.cpp GUI.cpp Simple_window.cpp Window.cpp /usr/local/lib/libfltk.a -lXext -lXft -lfontconfig -lXinerama -lpthread -ldl -lm -lX11
This includes everything that is required with respect to the fltk stuff and Stroustrup stuff. Here, my program is win_test.cpp and the output is windows_working. I obtained this looking through the shell script provided with the fltk files and put in /usr/inc/bin. It is called fltk-config.
Also, helpful hints are: download the fltk source from their site, not just the FL one from Stroustrup's site. Then read the readme and follow the instructions exactly before trying the test program in appendix D of the book. Then try his example code repeatedly fixing the errors you find until it works.
If you think I could help or want to know how I got my solution, email me (but I am a newb and so am unlikely to be of use).
Nathan,
Your answer was immensely helpful to me in my own struggle to implement Stroustrup's simple triangle program. I would like to post my own solution based on yours. With one change to Stroustrup's code and a greatly expanded compile script, I got the triangle to appear.
g++ -I/usr/localinclude -I/usr/local/include/FL/images -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_THREAD_SAFE -D_REENTRANT -o 'myimplementationofstroustrup.o' 'myimplementationofstroustrup.cpp' 'Simple_window.cpp' 'Graph.cpp' 'GUI.cpp' 'Window.cpp' /usr/local/lib/libfltk.a -lpthread -ldl -lm -lX11 -L/usr/local/lib -lfltk_images -lfltk_png -lfltk_z -lfltk_jpeg -lfltk
The differences with yours are as follows:
1) I had to add quotes to all my .cpp files... system difference, perhaps?
2) I had to add six flags at the end that you didn't use, or else I got more "undefined reference" errors.
3) I had to specify "Graph_lib::Window" on Line 17 of Simple_window.h because of an ambiguous reference error. This was the only change I had to make to Stroustrup's code.
This summary of issues and fixes is also very helpful in getting it to work on the different platforms. Actual corrected code is available for download:
FLTK issue compiling - PPP2ndEd
There is a very detailed walkthrough of how to fix this in a thread at the book's forum:
https://groups.google.com/forum/#!msg/ppp-public/BtlzdWGuQpQ/KuDN4u-SPKgJ
Based on that I made a github repository that has implemented all those changes and more, and includes details on how to build the project:
https://github.com/cortical-iv/hello_fltk
I have spent about two weeks on this dang problem, and my knowledge (which is largely gained from others) is really embodied in that code frankly and will be updated constantly. But this is stack overflow, so in terms of changes I had to make to the code, most are found at that forum but since it isn't nice to give link answers, here they are:
Simple_window.h
Resolve namespace clash Change struct Simple_window : Window { to
struct Simple_window : Graph_lib::Window {
Simple_window() converted to declaration (remove definition).
Convert wait_for_button() from definition to declaration (comment out entire def in while loop) and change from void to bool to be consistent with definition in Simple_window.cpp.
Turned cb_next(...) to declaration
Turn void next() to declaration
Graph.h
1. Uncomment #include "std_lib_facilities.h"
2. Change fl_color to Fl_Color (~ line 159)
Graph.cpp
1. Replace can_open with:
bool can_open(const string& s)
// check if a file named s exists and can be opened for reading
{
ifstream ff(s);
return ff.is_open();
}
Point.h
1. Uncomment constructors
Point(int xx, int yy) : x(xx), y(yy) { }
Point() :x(0), y(0) { }
Gui.h
1. In Menu : Widget, change Menu(Point xy ...) to declaration rather than def, comment out Widget def stuff.
Once you've done the above, it should compile if you run the following command at your terminal:
g++ -w -Wall -std=c++11 Graph.cpp Window.cpp GUI.cpp Simple_window.cpp main.cpp `fltk-config --ldflags --use-images` -o hello_fltk
If you installed fltk using cmake, then you can also build the example using cmake/make: there is a CMakeLists.txt file at the repository.