FLTK applications in Cygwin: GUI doesn't show? - c++

#include <FL/Fl.H>
#include <FL/Fl_Window.H>
int main() {
Fl_Window win(400, 400);
win.show();
return Fl::run();
}
I'm compiling with "fltk-config --compile main.cpp". The code compiles without incident, but when the application is run I only get a console window and no GUI.
I've also tried using fluid from terminal (via "fluid main.cpp"); I'm not even sure I'm using this correctly since, as I understand, fluid is a graphical editor. In any case, the result is "Can't open display: ". I found the same error but for a different situation here. Somebody in that thread suggested doing "export DISPLAY=:0.0", which I tried. Now when using fluid the error has simply changed to "Can't open display: :0.0".
It's worth noting that I've also tried using Qt4 as a framework (using qmake/make to compile), but I have the exact same problem. Console loads, no GUI of any sort, despite using code that various sources say should work.
edit
I found this question. I used DependencyWalker to find .dlls used by my .exe, and placed copies of those .dlls directly into my project folder. This did not fix my problem, or change it in any way. For reference, the .dlls I used were: cygfontconfig-1, cyggcc_s-1, cygstdc++-6, cygwin1, cygX11-6, cygXft-2, kernel32.
I also tried the same solution for Qt, again with no success. In that case, the .dlls were cygwin1, cyggcc_s-1, cygstdc++-6, cygqtcore-4, cygqtgui-4, kernel32.
For some good news, I've found that can successfully build an application with the Qt Creater SDK, so the problem lies somewhere with my manual compiles only. In any event, I'd still like to solve this problem. I dislike using an SDK for small projects, and I'd like to keep my library options open.

If fltk-config --cxxflags and fltk-config --ldflags do not output -mno-cygwin, then your FLTK was compiled to work with Cygwin's X Window System - something you probably want to avoid. Add -mno-cygwin to your Makefile and your FLTK application should work.
I always liked MinGW+MSYS more.

Related

Error while compiling my c++ program

I am a c++ beginner and after reading many articles on good ways to learn programming, I have found that its a good practice to learn programming through using command line interface than through IDE's. So therefore I am trying to learn c++ through command line interface. I am following my first tutorial of a "hello world" program. I am using MinGW compiler to compile my code. As I try to compile my code in the windows command prompt, I am getting an error. I have searched throughout the internet but can't seem to find an answer for this problem. The command I use to compile my code is "g++ Motto.cpp -o Motto.exe" and I get the problem "g++:error:CreateProcess:No such file or directory". I have checked for the path environment variable and it has the MinGW path. I have also checked the MinGW folder and found that all the executives needed are installed. Please help me fix the problem.
Here is the code:
#include <iostream>
int main()
{
std::cout << "Hello world\n";
return 0;
}
That usually means the g++ cannot find some executables that it needs to run during the compilation. Especially with MinGW the installation can be little tricky.
Make sure the paths to the MinGW installation is in your PATH environment variable (echo %PATH%) and also try to restart the computer.
If you installed manually and not with the MinGW installer (mingw-get), make sure you have downloaded and installed all the prerequisities (core, c++, binutils, runtime, etc.).
The g++ --version only prints the version, so it does not need to call another executables which the compilation does (like cc/c++, ar, etc).
Check the bin folder inside your MinGW installation directory, if you have at least those executables there: cc, c++, c++filt, ld (and others like ar, as).
Also, check {MinGWDir}\libexec\gcc\mingw32{version} if it contains cc1, cc1plus, collect2.
Try running "make $file-you-want", or like #FCo said, "g++ -o Motto Motto.cpp", The error means that you're passing it an invalid filename to compile, or you're not in the proper directory. Make sure you have the file you want to compile in your working directory, either by typing "ls" or "dir" depending on the system you're using.
Information that would help answer this question:
What you're doing to cause the error (how are you running g++?)
What OS/Environment you're running on

Trouble getting a Qt Reference Document program to work(Minehunt)... its just blank when run... no errors though?

http://docs.huihoo.com/qt/4.7/demos-declarative-minehunt.html
When I build and run... I just get a blank white rectangle... game is MineHunt.
The source code is in the URL. I created files and copied and pasted into Qt Creator 4.7.
Running in Linux.
No need to downvote. Deploying qml apps does not seem to be easy for beginners. jdl, I don't know if I can help you. Currently I am only on Linux. But what I did:
I copied the whole folder minehunt in my destination folder (/tmp/mine). When I ran qmake I got:
WARNING: Include file
/tmp/mine/helper/qmlapplicationviewer/qmlapplicationviewer.pri not
found
So I also copied the examples/declarative/helper folder into /tmp/mine.
Looked like this:
/tmp
/mine
/minehunt
/helper
Then I changed into minhunt, did 'qmake' and 'make'. A few seconds later I had a working minehunt binary in /tmp/mine/minehunt/.
I'll try tomorrow the Windows build.
Edit: Ok, tried now under Windows 7. Qt4.
QtCreator opened.
Project ...qt\demos\declarative\minehunt\minehunt.pro
loaded. Normally in release mode compiled. No problem. A file minehunt.exe was created in ....qt\demos\declarative\minehunt\release. Started: White screen. Exactly as you described it. In ...qt\demos\declarative\minehunt I found a folder 'qml'. I moved this folder and the minehunt.exe into another folder (myMineFolder). Simulating a simple deployment this way. Clicked on minehunt.exe -> worked like a charm.
So my folder layout:
myMineFolder
qml
minehunt.exe
But of course, I have set my PATH variable correctly to my Qt installation.

Qt error: LNK1181: cannot open input file 'debug\main.obj'

Qt creator was working well, but suddenly shows a problem error: LNK1181: cannot open input file 'debug\main.obj'.
This problem shows always with any type of application either GUI or console.
I've uninstall the Qt, and install again, but the problem still exists.
I did not do anything in the Qt creator settings, I left the default settings.
The following application is simple console application occur the same problem in it.
//main.cpp
#include <QCoreApplication>
int main(int argc, char *argv[]){
QCoreApplication a(argc, argv);
return a.exec();
}
Note: I'm using Qt 5.1.1 for Windows 32-bit (VS 2010, OpenGL).
This problem also occurs if the path of your project (name of any folder) contains a white space.
This problem occurs also if you have in the .pro or .pri files something like:
HEADERS += \ \
or
SOURCES += \ \
Okay, we finally have a real answer for this generalized problem instead of the OP's typo problem if that didn't unblock you either.
Actual Problem (black-box perspective): The "Build directory" auto-filled entry breaks for projects inside whitespace directories. Qt Creator actually prohibits you and tells you not to use whitespace when making new Projects. You can still close a new project and re-name it to add whitespace, and Qt Creator will handle it gracefully. If you copy the build directory, even with whitespace in it, and paste that into the field replacing the broken auto-generated path (mine was using relative paths) then JOM will start working correctly, as QMake does not generate any errors. I can't speak for other Make tools.
Make or clone down your project with whitespace
Load it in Qt Creator
Run QMAKE
Select the "Project" button on the left-hand side
Make sure you're in the "Build" tab
Select "Browse", and then re-select the shadow directory QMAKE made
That should unblock you if it wasn't a simple issue for deleting the old QMAKE-generated folders, which is the most common problem people face with this specific error while developing within Qt Creator.
I got the error because of this:
HEADERS += \ \
$$PWD/QOakTreeViewRecursiveModel.h
instead of:
HEADERS += \
$$PWD/QOakTreeViewRecursiveModel.h
What worked for me:
Close the Qt Creator
Delete the [filename].pro.user file in your project directory
Open the project again and let Qt configure itself
Generally whenever I encounter an error like this, this is one of the first things I do as it solves a lot of problems with Qt.
Edit: This will of course reset your project build location.
The problem has been solved.
The cause of the problem was when creating a new project (GUI or Console), all source files that belong to this new project take a wrong extension ex: main.cp, but the correct extension is supposed to be ex: main.cpp.
And when changing all the source files extension from .cp to .cpp worked fine.
Or change the default source file extension from [Tools -> Option -> C++].
hmm If I remember correctly when I faced this kind of problems using your similar setup (QtCreator and Windows) running QMAKE & rebuilding the project again helped me solve this linker errors.
Run Clean and qMake and rebuild.
I has like this problem and this helped me.
I solved the problem by removing the big path and space names in the directories.
Try to create a folder in C:/ and copy or clone the project in this folder.
Remove all builder folders and configure the project again.
That solved it for me.

ui and cpp files are out of sync

Everything was fine until I decided to add another combobox (which I did not rename and is indeed called comboBox) into my .ui when I realized that ui->comboBox was not recognized. All my other widgets etc that I added awhile ago still work though. When I debug I get http://i.stack.imgur.com/xVs8X.png but i know for a fact that I created it. Usually bugs like these I could just close my Qt and start it up again and all would be well but not this time. Does anyone know how to possibly fix this issue? I'm using Qt5.1.0.
I noticed this problem after I built Qt statically. Could that be the issue?
Example:
detail.ui
trying to access the button in detail.cpp
As you can see, i can still access all of the previous widgets etc before I made Qt Statically. But now, when I make a new pushbutton, cpp file does not recognize this.
I had to run Qt5.1.0 for Desktop (MinGW4.8 32bit) prompt. cd C:\path\to\project.pro and then type mingw32-make clean
In my case there was a copy of the auto generated "ui_xyz" file in my working directory(source files) so the compiler wasn't referring to new one in the build directory.

SFML library : strange error

I'm learning SFML library and i picked a code from the tutorial. it opens a window and it should make me able to close it again but when i close it it says
Debug Error!
Run-Time Check Failure #2 - stack around variable 'App' was corrupted.
and then the console stops working.
this is my code:
int main()
{
// Create the main window
sf::Window App(sf::VideoMode(800, 600, 32), "SFML Events");
while (App.IsOpened())
{
// Process events
sf::Event Event;
while (App.GetEvent(Event))
{
// Close window : exit
if (Event.Type == sf::Event::Closed)
App.Close();
// Escape key : exit
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
App.Close();
}
// Display window on screen
App.Display();
}
return EXIT_SUCCESS;// = return 0
}
linking to the debug libraries are
sfml-system.lib
sfml-window.lib
sfml-system-d.lib//these are debug files
sfml-window-d.lib
if i ramove the first 2 and built my program it doesn't give errors but when i open it it says :
the application was unable to start correctly (0xc0150002). click ok to close the application
i have a 64 bit computer. and in microsoft vc++ 2010 i can do build solution or debug and i always do build solution.
and i am building in release mode but i have also tried both and they both didn't work
could someone please tell me what i could do to prevent this from happening or how this comes.
For these application startup issues,it is always a good idea to check if all dlls in the dependency closure are accessible - that is, are they all in the search PATH? We usually use dependency walker to check which dlls are missing, or use gflags for runtime diagnostic
While put your dlls with your exe in same folder works, it does not scale well, one way I usually do is put the library path in PATH environment variable.
And one thing to notice, sfml comes with prebuilt binrary for vs2005 and vs2008, as you are using vs2010, the underlying c runtime library(msvcrt) is different, there would be potential problems - you would better build sfml from source yourself using vs2010 or use vs2005/vs2008, just to be consistent
if you wouldnt like to use DLLs and would like to compile SFML into exe, here is tutorial:
2.0 http://www.sfml-dev.org/tutorials/2.0/start-vc.php
you need to add preprcessor directive SFML_STATIC , and include additional libs u are using in your program into linker -> input
I also had some related problems when I first time used this (and equivalent libs). Here is some points to take in count:
Do not use precompiled libraries/dlls. Learn how to use CMake, boost_build (boost libraries), Scons (mongoDB) etc. and build libraries according to currently used compiler/platform (of course if there is such possibility). After some time this process became pretty easy and simple and this will save a lot of time later for other projects.
Read SFML tutorials on making a simple project. They are easy to read and understand. May try to generate also examples with CMake and build them to see how they work. Another good tutorial is the book on SFML programming (which have a huge push on using C++11, which I think is great).
As pointed out add SFML_STATIC to "Preprocessor definitions" if don't want to use DLLs and I think is better to set "Windows (/SUBSYSTEM:WINDOWS)" in linker options (if I correctly understood from "and then the console stops working" statement).
Better to place libsndfile-1.dll and openal32.dll in release/debug folder where app is generated, from what I saw VC++ have a bad behavior on finding dlls from provided paths.