Building wxWidgets Hello world - c++

The wxWidgets hello world example does not provide sufficient information to build wxWidgets in any one particular environment.
The Code::Blocks wxWidgets hello world example does provide sufficient information, but it does not seem likely that a newbie, or even a quite sophisticated user, could figure out all the necessary steps on their own, because there are arcane magic words required.
The Code Yarns example uses CMake, thus could run in many particular environments, but seems to assume that you have already set up wxWidgets and compiled it for your particular environment, and there does not seem to be a CMakeLists.txt file to compile wxWidgets for your particular environment.
wxWidgets is supposed to be cross platform and cross environment, and I am trying to set up a project to compile in several environments: on Windows10 Visual Studio, Windows 10 TDM-GCC, Windows 10 Code::Blocks, Ubuntu Code::Blocks, and Ubuntu 10 gcc.
And apart from the Code::Blocks environments, having trouble. Apart from Code::Blocks, I cannot find "Hello World" examples that actually set up wxWidgets on the target so that the Hello World will actually compile and run.
The wxWidgets samples directory is not particularly useful, since the samples assume an environment, and do not describe setting up that environment and the actions that will cause the sample to build and run.

Installation guide
I know this is a old question but I struggled really hard to find a guide for an installation on wxwidgets. You can use the vckpg importer by Microsoft. Make sure you have git installed before you follow this routine. I will write this for Windows with Visual Studio 2017:
Clone the following repository to a directory of your choice:
git clone https://www.github.com/Microsoft/vcpkg
Then open up powershell (ps) (run it as admin) and navigate to the cloned vcpkg folder
Now in ps, while you are in the vcpkg folder run the following command \.vcpkg integrate install so we have a user-wide integration of the vcpkg paket manager and can #include libraries in our c++ projects
Now to install wxwidgets 32-Bit run \.vcpkg install wxwidgets --triplet x86-windows. For the 64-Bit Version run \.vcpkg install wxwidgets --triplet x64-windows
Now open up the properties of your project in Visual Studio.
For the integration of the 64-Bit wxwidgets version choose all configurations and as plattform x64. Then go to C/C++ -> General -> Additional Include Directories and add the following folderpath YOUR_FOLDER_PATH\vcpkg\packages\wxwidgets_x64-windows\include;YOUR_FOLDER_PATH\vcpkg\packages\wxwidgets_x64-windows\lib. Do the same for the x86 configuration but with the wxwidgets_x86-windows folderpath instead.
As a last step go to in the properties under C/C++ -> Preprocessor and under the point Preprocessordefinition add the following as extra point WXUSINGDLL=1 (do it for the x64 and for the x86 plattform configuration if you want to use both)
Now you should be able to use the library and run the hello world project.

To build an app, first you need to have the library compiled. To achieve that you can get precompiled binaries or the sources (see Downloads) and compile them yourself (see Building).
Instructions might still not be perfect for everyone, and you are welcome to improve them - even call it your first contribution ;)

The installation instructions that I was looking for are to be found in wxWidgets/docs/install.txt

There are multiple ways to setup wxWidgets on Windows and use it in a project.
If your project is going to use CMake there are 2 main options (other than compiling stuff yourself some other way):
Use vcpkg - which, in theory, is the easiest, but I couldn't get it to work (in time). Here is some info on that: https://www.wxwidgets.org/blog/2019/01/wxwidgets-and-vcpkg/
The problem is find_package couldn't find the package, so then I just went to 2:
Download the lastest compiled headers, libs & bins from the wxwidgets and put them in a folder like c:/wxwidgets. Then, in your Cmake file, before the call to find_package, do:
SET(wxWidgets_ROOT_DIR "c:/wxwidgets/")
SET(wxWidgets_LIB_DIR "c:/wxwidgets/lib/vc14x_x64_dll")
SET(wxWidgets_CONFIGURATION "mswd")
The LIB_DIR is using VS2019 x64 in my case.
mswd just means build this for Debug
Finally, when adding the executable, do not forget the WIn32:
add_executable(membot WIN32 ${project_SRCS})
P.S.: Remember to extract the headers include folder near the lib.

Related

Theme and Icons Problem with GTK3 Installed with vcpkg

I am using Visual Studio 2019 on Windows 10 and am trying to use GTK in C++ and installed it using vcpkg.
I've installed GTK using vcpkg according to the guide from GTK. I'm using Visual Studio 2019 and it is able to compile and run the example program here, but there is an issue regarding the theme and icons. According to the installation guide, under the section Building and distributing your application there are some things that must be done to get themes and icons to work.
I've started by downloading the Windows theme the guide suggests and have it in a share directory and then I've created a settings.ini file in an etc directory. It says to place this in the "install directory", which I assume is where Visual Studio is placing the exe for the program. I've tried it in both build and release, in the source files, in the top project directory - all with no success (and I did make sure it is targeting x64).
Just in case I also tried placing these where vcpkg is installed as well as where vcpkg installs gtk. No luck. When the program runs I get the warning
(gtkExample0.exe:16772): Gtk-WARNING **: Could not find the icon 'window-minimize-symbolic-ltr'. The 'hicolor' theme
was not found either, perhaps you need to install it.
You can get a copy from:
http://icon-theme.freedesktop.org/releases
So it seems that it is never finding the ssettings.ini file telling it to use the Windows 10 theme. Has anyone had any luck with getting this to work (both from VS2019 debugging runs and in deployment)?
To summarize the files:
share\themes\Windows10\gtk-3.0\gtk-3.20\ (downloaded from suggested GitHub repo)
etc\settings.ini contains:
[Settings]
gtk-theme-name=Windows10
gtk-font-name=Segoe UI 9
I've placed these in
<VS2019Project>\x64\Release,
<VS2019Project>\x64\Debug,
C:<path_to_vcpkg>\vcpkg\packages\gtk_x64-windows,
C:<path_to_vcpkg>\vcpkg\installed\x64-windows
All with no change when running from VS2019 under Release or Debug.
Theme and icons considered as external resources are not distributed by vcpkg, and the instructions given in the distribution guide from GTK regarding where these resources should be layout on windows 10 are not crystal clear. The problem has also been reported here vcpkg issue#4417.
The solution proposed hereunder is to install
all the resources in the <VS2019Project>\x64\Release directory of your VS project where your .exe application lives [This is a local solution the problem. A global approach should consider the setting of some user-defined free desktop environment variables which is not discussed here]. Icons can be picked from an ancillary MSYS2 distribution and the theme as indicated in the GTK Guide. The solution should be replicated for the Debug branch.
Supposing you have MSYS2, install mingw-w64-x86_64-adwaita-icon-theme package with the pacman package manager if not already done on your MSYS2 installation pacman -Syu mingw-w64-x86_64-adwaita-icon-theme.
Copy C:\msys64\mingw64\share\icons to <VS2019Project>\x64\Release\share\icons
you should get both hicolor and Adwaita icons as subdirectories of your target dir.
Copy the theme resources downloaded in the source gtk-3.20 directory directly into <VS2019Project>\x64\Release\share\themes\Windows10\gtk-3.0\. Do not locate these resources into a gtk-3.20 subfolder: to understand why consult this article Theme Location [assuming here that no global desktop environment variable has been set].
Create a <VS2019Project>\x64\Release\etc\gtk-3.0 directory, put your settings.ini into it.
Recompile and you should obtain a windows 10 look and feel for your application window.

Build (compile) a basic standalone .exe application using Qt-creator on Windows 8

I have installed Qt-5.7 on windows 8 because I couldn't build my released .exe from Linux (my favorite) in order to be used on Windows OS even after searching a lot on internet (Where there have to be cross-compilation...). After the installation, I just want to make sure that I can build/run a first application (one of the examples provided by default by Qt-creator "filesystembrows") and I have follow the official guide in order to build Qt as shared libraries, but the issue is that when I type the first command line I get: 'nmake' is not recognized as an internal or external command' Also it still show the same message even though a update the variable environment of the system with C:\Qt\Qt5.7.0\5.7\mingw53_32\bin which one is the default path set-up when installing Qt on windows. Any help just to make a stand alone .exe for Windows (as shared libraries ) please
Why not build your project by using qtcreator ?
Did you test your build environnement by making a test application with qtcreator ?
P.S.: If you want, I can explain how to build application using Visual Studio as a compiler and QtCreator as an IDE.
nmake is a build tool provided with Visual Studio and with Windows SDK. You don't have it, apparently.
It seems you're using a mingw build of Qt; it comes with a bundled copy of mingw. There, the build tool is simply called make.

OpenCV 3.0 include tracker

I want to use a tracker, described on the OpenCV 3.0 documentation site. In OpenCV 2.x, it was necessary to recompile OpenCV including the contrib library. But as it is in the OpenCV 3 documentation, I guess that I do not have to recompile it anymore, right? But what do I have to #include in C++?
I'm trying to do this for quit a while and do not find any solution. Thank you!
EDIT
Thank you! The recompiling-process worked for me without any errors. I got still several errors: He does not find 'opencv_highgui300d.dll', 'opencv_imgcodecs300d.dll'and 'opencv_core300d.dll'.
I fixed this, because I had to change the 'Path' system variable to
...\cmake-output\vc12\x86\install\x86\vc12\bin
As far as I know the tracking module is still in the "contrib" module.
You have to re-compile OpenCV 3.0 using the contrib section that you may download from this github repo. When you compile OpenCV using CMake you have to specify the OPENCV_EXTRA_MODULES_PATH atribute as being the location where you have extracted the module.
If you have any issues, just let me know :)
[EDIT]
Download OpenCV from here and OpenCV_Contrib module from here. Unzip them and place them in the same directory (I have put mine in D:/OPENCV-BUILD)/
Open CMake and set the source code path to D:/OPENCV-BUILD/opencv-master
Set the "Where to build the binaries" path to D:/OPENCV-BUILD/cmake-output/vc12/x86. Here, vc12 is the platform toolset used by VS2013 and x86 is the platform target (you may build it for x64 also)
Press the configure button and select your generator (a.k.a the compiler you'd like to use). Select Visual Studio 12 2013 (for x86 build) or Visual Studio 12 2013 Win64 (for x64 build).
Wait until it's done configuring. A bunch of red lines will appear, dont't worry it's all good :)
Search for the following lines and uncheck them:
WITH_CUDA -> this will disable support for GPU accelerated algorithms using CUDA technology. You can build the library with CUDA support also, but it's a bit more complicated and it takes much longer. If you don't need it, un-check it :)
BUILD_DOCS, BUILD_PERF_TESTS, BUILD_TESTS. These are just some tests of the modules of the library (that I have never ever used)... Again, if you don't need them, un-check them :)
Everything related to Matlab (if you have these options). I have Matlab installed and CMake wanted to create some Matlab bindings for OpenCV. I had some issues at compiling the library with these options, so I deleted them (see the image below)
Search for "extra" and in the OPENCV_EXTRA_MODULES_PATH set the path to your "modules" folder from the contrib module (mine is D:/OPENCV-BUILD/opencv_contrib-master/modules)
Now click again on the "Configure" button. Wait until it says "Configuring done", and after that press on the "Generate" button. We're done with CMake!
In the output folder you have selected (D:\OPENCV-BUILD\cmake-output\vc12\x86) you'll find OpenCV.sln. Open it using VS2013.
In Visual Studio, select the configuration you'd like to build (I recommend you to build both for Debug and Release). Let's say you select 'Debug' first. Now right click on the solution and select "Build Solution". Wait until it's done.
In the 'CMakeTargets' folder you'll find a project named INSTALL. Right click on it and select 'Project Only -> Build Only INSTALL'). This creates a new folder named install and copies the result of the build there (libs, dlls, include files, etc.).
Repeat steps 10 and 11 for the 'Release' configuration.
After these steps, you'll have the files you need in your install folder (mine is D:\OPENCV-BUILD\cmake-output\vc12\x86\install)
The following link points to a very clear and nice explanation of how to install OpenCV properly and not have any problems with compilation and provided libraries.
This is the proper way to get a clean installation on Windows 7:
https://coderwall.com/p/wgaiwa/setup-opencv-with-vs2012-on-win7-64bit?p=1&q=author%3AVentsy
Hope it helps

Via Windows command line, how can we compile a Netbeans C/C++ application?

Let's take this simple C/C++ application Netbeans project folder.
In Netbeans IDE, we just hit build button on the toolbar to build the application.
I want to do that automatically via Windows command line, how can I do that?
I did google, and found some related posts though not very helpful for me except telling me to call ant dist - though I don't have the build.xml in my Netbeans 8 project.
p.s. I have hundreds of student submissions and need to verify which one is compilable.
I also post on Netbeans forum here.
I want to do that automatically via Windows command line, how can I do that?
NetBeans uses Makefile-based projects as default for C/C++ projects, so you can use make to build your project:
cd <Project dir>
make
It's also possible to build other make-targets (eg. make all or make test (builds / runs tests)).
Note: The Cygwin bin dir (CYGWIN_HOME\bin) must be in system PATH - same applies to other environments (MinGW, Gcc etc).

How to make Qt4 work using Code::Blocks in Linux Mint

I'm trying to use Qt4 using the Code::Blocks IDE. I'm running Linux Mint and I'm getting some errors. I looked around and found some people that had the same problem as me, but I can't seem to get their solutions working on my computer.
I installed Qt4 using the command
sudo apt-get install qt4-dev-tools
And when I type whereis qt4, I get qt4: /usr/lib/qt4 /usr/include/qt4 /usr/share/qt4
If I select "Create new Projet" in Code::Blocks and Select Qt4 project, it asks for Qt's location, which is $(#qt4) by default. If I click next, it says Code::Blocks doesn't know the "qt4" variable and gives me a prompt to set the base location, the include directory, etc.
Since I don't have any idea as to what I should be putting in there since nothing works (either it says "QTCore cannot be found in the specified directory", or the "lib" directory couldn't be found, etc.).
I tried what was posted on this forum: http://crunchbang.org/forums/viewtopic.php?id=18210, but it didn't solve my problem and I get the same errors.
In the "/usr/share/qt4" directory, there's a link to the "include" directory, but not to the "lib" directory.
I'm pretty new to Linux and all of this, so I'd like it if the answer was very detailed explaining what I did wrong / what I have to do.
Install the QtSDK
As a first step I would advise you to download directly the QtSDK, from the project site here.
Note: You could also use the precompiled version for your Mint version,
but in my personal experience, when working with external SDK,
you have more independence in development, it also allows you to work
freely with multiple versions of Qt simultaneously without move any
dependence of your OS.
You can follow the graphics steps to install the SDK, I advise you to check the option "download source", later this is going to be used for debugging code, and if necessary will allow the recompilation of some classes.
Now your QtSDK is installed on the folder eg "/usr/local"
So, all references inside your IDE should refer to this location.
Install the C::B
You can use the version available in "Software Manager"
Configure the C::B
When we start a new project and asks the location of our SDK we indicate this directory /usr/local/QtSDK/Desktop/Qt/4.8.1/gcc
Now the project is ready!
Note: "/usr/local" and "4.8.1" are variables depending on where
and what version you have installed.
Is very likely that your build directory, is not correctly assigned in "Settings->Compiler and Debugger->Toolchain ...->Compiler's Directory"
will be the default "usr" which should be replaced by "/usr/bin"
Now, when compiling with the standard project ".pro" and if your project has the requirement to use a "moc" tool strategy, the simplest way to do that, is use a customized Makefile, with all stages of compilation.
To learn how to make a customized makefile, you can read this answer.
And although I would advise again:
Although that CB is an optimal environment for working with wxWidgets, and C/C++ in general, I personally think that in the case of working with Qt, QtCreator provides a development environment more native and optimized to work with your projects QT.