Visual Studio Compile Source - c++

I would like to compile the source:
https://github.com/Benjamin-Dobell/Heimdall
I'm have downloaded the source launch visual studio and open heimdall/main.cpp
However when trying F5 nothing happening.
Please help

Have a look at the Readmes (e.g. Win32):
Appendix B - Installing Heimdall Suite from Source
Heimdall and Heimdall Frontend both utilise CMake for managing the build
process. CMake can generate files for various build systems including GNU
Make and Visual Studio. However, official packages are compiled with GNU
Make and MinGW-W64 GCC/G++.
NOTE: Official builds use MinGW-W64 simply because on-going cross-platform
development is simpler when using just the one IDE (Jetbrain's CLion)
and similar toolchains.
1. Setup a MinGW-W64 build environment by utilising MSYS2:
http://msys2.github.io/
2. After installing MSYS2 a command prompt will launch, enter:
Pacman -Syu
Pacman -S mingw-w64-x86_64 mingw-w64-x86_64-clang mingw-w64-x86_64-cmake mingw-w64-x86_64-libusb mingw-w64-x86_64-qt5-static make
3. Add the MinGW-W64 binaries to your PATH environment variable:
export PATH="/mingw64/bin:$PATH"
4. Build Heimdall & Heimdall Frontend
mkdir build
cd build
cmake -G "MSYS Makefiles" -DCMAKE_BUILD_TYPE=Release -DQt5Widgets_DIR=/c/msys64/mingw64/qt5-static/lib/cmake/Qt5Widgets ..
make

You can checkout v1.4.0 tag, open msvc2012.sln and build that code instead.
You will need Qt Developer Framework (4.7 or later, but prior to 5.0) to build it

Related

Troubles installing Mingw bin folder [duplicate]

I am trying to build some open source library. I need a package management system to easily download the dependencies. At first I am using MinGW and MSYS. But the included packages are limited. Someone told me to use Mingw-w64 and MSYS2.
I downloaded the mingw-w64-install from here. When running, it reports the following error. How can I fix it?
And by the way, from the Mingw-w64 download page, I see a lot of download links. Even Cygwin is listed. How are Cygwin and Mingw-w64 related?
My current understanding is, in the time of MinGW and MSYS, MSYS is just a nice addon to MinGW, while in Mingw-w64 + MSYS2, MSYS2 is stand-alone and Mingw-w64 is just a set of libraries it can work with. Just like Cygwin can download many different packages.
Unfortunately, the MinGW-w64 installer you used sometimes has this issue. I myself am not sure about why this happens (I think it has something to do with Sourceforge URL redirection or whatever that the installer currently can't handle properly enough).
Anyways, if you're already planning on using MSYS2, there's no need for that installer.
Download MSYS2 from this page.
After the install completes, click on the MSYS2 UCRT64 in the Start menu (or C:\msys64\ucrt64.exe).
If done correctly, the terminal prompt will say UCRT64 in magenta letters, not MSYS.
Update MSYS2 using pacman -Syuu. If it closes itself during the update, restart it and repeat the same command to finish the update.
You should routinely update your installation.
Install the toolchain: (i.e. the compiler and some extra tools)
pacman -S mingw-w64-ucrt-x86_64-toolchain
Install any libraries/tools you may need. You can search the repositories by doing
pacman -Ss name_of_something_i_want_to_install
e.g.
pacman -Ss gsl
and install using
pacman -S package_name_of_something_i_want_to_install
e.g.
pacman -S mingw-w64-ucrt-x86_64-gsl
and from then on the GSL library will be automatically found by your compiler!
Make sure any compilers and libraries you install have this package prefix: mingw-w64-ucrt-x86_64-. Only use unprefixed packages for misc command-line utilities (such as grep, sed, make, etc), unless you know what you're doing.
Verify that the compiler is working by doing
gcc --version
If you want to use the toolchains (with installed libraries) outside of the MSYS2 environment, all you need to do is add C:/msys64/ucrt64/bin to your PATH.
MSYS2 provides several compiler flavors, UCRT64 being one of them. It should be a reasonable default.
MSYS has not been updated a long time. MSYS2 is more active, and you can download it from MSYS2. It has both the mingw and cygwin fork package.
To install the MinGW-w64 toolchain (reference):
Open the MSYS2 shell from the start menu
Run pacman -Sy pacman to update the package database
Reopen the shell, and run pacman -Syu to update the package database and core system packages
Reopen the shell, and run pacman -Su to update the rest
Install the compiler:
For a 32-bit target, run pacman -S mingw-w64-i686-toolchain
For a 64-bit target, run pacman -S mingw-w64-x86_64-toolchain
Select which package to install; the default is all
You may also need make. Run pacman -S make
You can now also get the stand-alone personal build of MinGW-w64 from https://winlibs.com/ which doesn't require any installation; just extract and its ready to use. This allow having multiple toolchains on the same system (e.g., one for Windows 32-bit and another for Windows 64-bit).
The most straightforward way, as far as I know, is to use Chocolatey to install MinGW:
choco install mingw
Then check with the command whereis gcc. It is going to be installed in C:\ProgramData\chocolatey\bin.
one more thing, to get make working, just copie (or rename if you wish)
with copy mingw32-make.exe make.exe in C:\ProgramData\chocolatey\bin.

Building .SLN files on Windows without Visual Studio?

I have recently been trying to set up my CMake environment and some 'hello world' code in C++. I added a CMakeLists.txt and added my configurations, but when I ran cmake . in the command line, something was different from all of the tutorials.
The people on the tutorials were using a Unix based system, so the command cmake . was producing a 'makefile'. They then built the makefile using the command make.
Since I'm on windows, it generated a msvc .sln file instead of a makefile. My question is - how can I build the .sln file, similar to how they did it on Linux? I want to do it without Visual Studio 2019 and preferably in the command prompt.
I have tried searching for this question, but haven't found what I'm looking for. Thank you in advance.
First of all, you should never do an in-tree build with cmake .. It invites problems in the form of name clashes and makes it nearly impossible to get a clean rebuild.
If you're using a recent version of CMake (which you should be), the standard way to build a project varies on whether the backend generator is single-config or multi-config.
If it's single-config (like Make or Ninja), then the commands are:
$ cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -S /path/to/sources -B /path/to/build
$ cmake --build /path/to/build
The directory /path/to/build doesn't need to exist when you invoke CMake. If you wanted a Debug build, rather than Release, you would just replace that in the first line. You should never run a single-config generator without setting CMAKE_BUILD_TYPE.
If it's multi-config, like Visual Studio, then the commands are:
$ cmake -G "Visual Studio 16 2019" -A x64 -Thost=x64 -S /path/to/sources -B /path/to/build
$ cmake --build /path/to/build --config Release
The major difference here is that the config is specified in the second (build) command, rather than the first (configure).

How to compile GMP for windows using Visual Studio

I am trying to install gmp on windows. I have found the mingw way of compiling from sources on windows.
But was unable to find binaries fro gmp 6.1.2 or visual studio project in order to compile from sources.
So the question is: Where can I download the gmp 6.1.2 binaries or compile from sources using Visual Studio.
I'll describe three ways of compiling GMP in Windows.
First
Install Visual Studio 2022 Community from this page.
Install VCPKG package manager as described here, basically just do two steps:
git clone https://github.com/Microsoft/vcpkg --depth=1
inside vcpkg directory run
cmd /c bootstrap-vcpkg.bat
Set system environment variable VCPKG_DEFAULT_TRIPLET=x64-windows-static, for doing this press WinKey+Pause, then click "Advanced system settings", then "Environment variables", inside "System variables" click "New" and set value of VCPKG_DEFAULT_TRIPLET to x64-windows-static.
Instead of this step above (setting variable) you can just pass triple directly to all vcpkg commands like vcpkg install gmp --triplet=x64-windows-static.
Inside git directory of vcpkg run following command:
vcpkg install gmp --triplet=x64-windows-static
(you may omit --triplet=x64-windows-static if you set environment variable as I told above)
It will take quite a lot of time, it will compile many packages from sources.
After full compilation is finished it will show in console path to ZIP file with compiled GMP library. On my system ZIP file was created at C:\Users\user\AppData\Local\vcpkg\archives\8d\8d1c08fabf677187083dedd12d6accf7114d91580e75611c065f1674b600bee9.zip.
Unpack this ZIP file and then you can compile your C++ program like following:
cl program.cpp /O2 /GL /EHsc /std:c++latest /Ipath_to_unpacked_zip/include/ path_to_unpacked_zip/lib/gmp.lib
As you might know cl command should be run from "x64 Native Command Prompt" command shell which can be found in "Windows Start Menu / Visual Studio 2022 /".
Also you may install MPIR instead of GMP, this is a fork of GMP, with same interface, but more preferred by Windows users. Just do vcpkg install mpir, but this can be done only if you delete GMP package first, only one of MPIR or GMP can be installed.
Second
This step doesn't compile GMP, but uses precompiled binaries from MinGW installation.
Install Visual Studio as in first step.
Go to home page of MSYS2. Download installer, link is located near "1. Download the installer:" phrase. Install it to any location, e.g. c:\bin\msys\.
After installation in Windows Start Menu go to application "MSYS2 64bit" and inside it start program "MSYS2 MSYS", it will run Unix-like shell, from it do:
pacman -S msys/binutils msys/gcc msys/mingw-w64-cross-crt-git clang64/mingw-w64-clang-x86_64-gmp
This command above will install all needed packages to use GMP. If you need more packages use -Ss option like pacman -Ss clang, this will search for CLang, so -Ss does search and -S installs.
If you need some time later, pacmans -Syu command updates all installed packages, run this command two times, one time updates base system files, second time all other packages (after first time you need to close and open MSYS shell again).
Now you need one tweak, rename two symbols inside library libmingwex.a because of collisions with libucrt.lib library of Visual Studio.
In following two commands I assume that your MSYS installation folder is c:\dev\msys\, you can change to one that you installed to.
c:\bin\msys\usr\bin\objcopy.exe --redefine-sym wcsnlen=wcsnlen_renamed --redefine-sym strnlen=strnlen_renamed c:\bin\msys\opt\x86_64-w64-mingw32\lib\libmingwex.a c:\bin\msys\opt\x86_64-w64-mingw32\lib\libmingwex_renamed.a
(this will create file libmingwex_renamed.a with renamed two symbols out of libmingwex.a library)
Now everything is ready and you can compile your C++ program like following:
cl program.cpp /O2 /GL /EHsc /std:c++latest /Ic:\bin\msys\clang64\include\ c:\bin\msys\clang64\lib\libgmp.a c:\bin\msys\usr\lib\gcc\x86_64-pc-msys\11.3.0\libgcc.a c:\bin\msys\opt\x86_64-w64-mingw32\lib\libmingwex_renamed.a
See that in command above I used 3 libraries libgmp.a and libgcc.a and libmingwex_renamed.a. Also notice that libgcc.a is taked from sub-folder \11.3.0\, it is current version of installed GCC, but when time passes MSYS2 updates GCC to later versions, so this version-subfolder should be changed accordingly.
Third
Install Visual Studio like in First and Second steps.
In this step we will use MPIR, it is a fork of GMP, really good fork more suitable for Windows.
Clone repository:
git clone https://github.com/BrianGladman/mpir --depth=1
Inside folder .\mpir\msvc\vs22\ run:
cmd /c msbuild.bat gc LIB x64 Release
Above command builds Generic version that is suitable for any CPU. After that do
cmd /c msbuild.bat skylake_avx LIB x64 Release
Which builds very optimized version, faster than generic.
Very Important. If second (skylake) builds with failure, then Generic (gc) version can be used but it can be even 5x times slower. If fast Skylake version has failed then better not to use this Third way of compiling GMP, unless you can't do others, or if slow version is enough for you.
This command above should be run as usual from "x64 Native Command Prompt" shell of Visual Studio in Start Menu.
After build is finished GMP (actually MPIR), you can compile your program as:
cl program.cpp /O2 /GL /EHsc /std:c++latest /Ipath_to_mpir_repo\msvc\vs22\lib_mpir_skylake_avx\x64\Release\ path_to_mpir_repo\msvc\vs22\lib_mpir_skylake_avx\x64\Release\mpir.lib
Note that in command above I used \lib_mpir_skylake_avx\ subfolder for optimized AVX version, please use \lib_mpir_gc\ subfolder if only Generic version is available.
Compiling GMP on Windows with VisualStudio might be tricky, however there are already some SO questions, that might help you (depending on your exact use-case):
Building GMP library with Visual Studio?
How to install MPFR and GMP for C++ on visual studio
GMP on visual studio c++
Simple answer is, that there are no sources of GMP compilable directly using VisualStudio as GMP is developed with UNIX in mind.
Summary of your options:
Use GMP version provided in your MinGW distribution
Compile own GMP using MinGW/Cygwin
Use MPIR fork of GMP compilable using VisualStudio
Try to solve all the compilation problems yourself, some hints for older GMP versions are here:
https://cs.nyu.edu/exact/core/gmp/
http://www.blizzhackers.cc/viewtopic.php?t=393933
I faced the same problem in Windows 11 when I needed both gmp and gmpxx for which only the first option works, thanks to #Arty.
The only thing to add is that vcpkg install gmp --triplet=x64-windows-static command should be run in a terminal with admin privilege, otherwise the following error will occur:
file RENAME failed to rename
C:/Users/Desktop/polycut/vcpkg/packages/gmp_x64-windows-static
to
C:/Users/Desktop/polycut/vcpkg/packages/gmp_x64-windows-static_tmp
because: Access is denied.

Importing a CMake project into CodeLite

I was wondering if anyone knew of a way to import an existing cmake project into the CodeLite IDE?
This is a C++ project and I have all of the .c and .h files. I have the CMake lists and what not for the project too.
I am running on Ubuntu 16.04 with CodeLite 11.0.4.
If CodeLite is not able to do this, then is there an IDE that can import a CMake project?
You can generate a CodeLite workspace with cmake by using the -G option. First, look up all available CodeLite generators by doing
cmake --help
Keep in mind that not all might work for you, depending on your system configuration. Then use one of them as you like. For example, using Ninja you can do:
cmake -G "CodeLite - Ninja" /path
where /path is the directory where your CMakeLists.txt is located.
You can generate Codelite workspace with cmake by:
cmake -G "Codelite - Unix MakeFiles" /path (where 'path' your CMakeFiles.txt is present)
For instance:
Generate Codelite workspace
cmake -G "CodeLite - Unix Makefiles" **./**
Codelite workspace is generated
Open CodeLite and build project (P.S. do not forget to set up project appropriately (e.g. compiler / workspace settings)
According to Some programmer dude, CMAKE is able to make a codeLite project. I have tested this with the version of CMAKE that you can install with sudo apt-get install in ubuntu 16.04. This works.

Is there an example project in c++ that uses opencv and travis ci?

I'm using Github as the source control tool, and I'd like to use the travis-ci plugin for CI. I didn't find any project that does that. Since travis-ci provides ubuntu 12.04 without the openCV libraries I'm installing those but then I'm having troubles using CMake to compile my code with the installed libraries.
I'd very much like to see an example project and it's .travis.yml if you know of one, preferably with a set-up that would work on both the travis ubuntu and windows for dev machines.
Here is a sample .travis.yml to build a project with CMake:
language: cpp
compiler:
- gcc
before_script:
- mkdir build
- cd build
- cmake ..
script: make
The complete project is available from https://github.com/leutloff/diff-match-patch-cpp-stl. Another example is available from Need hosted CI server with Qt4, sqlite3, cmake, git, gcc for project on GitHub.