visual studio build application from the source code - c++

I have an application to build using the code source but i have a problem with that because i didn't understand what they mean by:
On Windows, add -G "Visual Studio 14 Win64". Also, you will probably
need to add -C ../4dface/initial_cache.cmake as first argument -
copy the file from initial_cache.cmake.template and adjust the
paths.
Here is the third step which i can't realize it:
3.
Build the app:
Run from outside the source directory:
1. mkdir build && cd build
2. `cmake -DCMAKE_INSTALL_PREFIX=../install -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=gcc-5 -DCMAKE_CXX_COMPILER=g++-5 -DOpenCV_haarcascades_DIR=/usr/share/opencv/haarcascades/ ../4dface/`
On Windows, add `-G "Visual Studio 14 Win64"`. Also, you will probably need to add `-C ../4dface/initial_cache.cmake` as first
argument - copy the file from initial_cache.cmake.template and
adjust the paths.
If you get an error about OpenCV\_haarcascades\_DIR, adjust `-DOpenCV_haarcascades_DIR` to point to the directory of
haarcascade_frontalface_alt2.xml from OpenCV.
I am on windows 8 and i had the code source from this "https://github.com/patrikhuber/4dface"
and here is the link for the readme "https://github.com/patrikhuber/4dface/blob/master/README.md"
Thank you.

Looks like you need to use CMake. Install it.
From the Visual Studio "Tools" Menu, choose "Visual Studio Command Prompt".
In the window, change directories to the project.
Now enter the command "CMake -G "Visual Studio 14 2015 Win64".
Note: Cmake wants the "2015" in the phrase.

Related

Compiler out of heap space and MSBuild 32 bit

I'm trying to compile the library OpenGV and I get the error MSVC C1060 "compiler out of heap space".
I tried to go change to x64 architecture by adding
<PreferredToolArchitecture>x64</PreferredToolArchitecture>
<PlatformTarget>x64</PlatformTarget>
to the .vxcproj file, without success. I notice however that in the resource manager, MSBuild 32 bit is still being used. Could this be the problem, and if so, how can I change the build tool (i.e. the MSbuild version), through, say, GitBash?
If you're compiling the project through the Visual Studio IDE, the Visual Studio IDE silently uses a 32-bit compiler. To change this behavior, use the command:
msbuild {solution-name}.sln /property:Configuration=Release"
To find the path to the msbuild command on your system, use the command below:
where msbuild
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\MSBuild.exe
If the where msbuild command does not return a path like C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\MSBuild.exe, but your system has msbuild installed, go to the system variables and add the MSBuild.exe path to the system path in the file structure where Microsoft Visual Studio is installed. Remove other msbuild path variable from system variables (like C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe). Otherwise, this change may not work.
In another graphics library (solution, issue) it is reported how to solve a similar problem and its solution is reported as solved as above.
When installing OpenGV under Window it is stated in the documentation that the msbuild configuration should be changed as follows:
msbuild opengv.sln /p:Configuration=Release
In addition, if the cmake build tool will be used in the project, the following declaration should be made using the -G option to compile for x64 target machine:
cmake -G "Visual Studio 16 2019" -A x64 ../
# cmake -G "Visual Studio 16 2019" -A Win32 ../
# cmake -G "Visual Studio 16 2019" -A ARM ../
# cmake -G "Visual Studio 16 2019" -A ARM64 ../

Compile c++ project without makefile neither CMakeLists.txt

How can I easily compile a c++ project ( https://github.com/eduardovera/D-KHT ) that doesn't have any makefile neither CMakeLists.txt?
Projects that don't have a build script, and are not header-only libraries, are virtually useless. Building them manually requires issuance of dozens or hundreds of commands, and is not tractable. Build scripts are there for a reason. Use them! They make hard work easy. If you use them properly, that is.
There is some confusion in your project: Qt Creator is an IDE. You don't need it to build anything.
Building qmake-based Projects From Command Line
macOS/Linux
# assume the git checkout is in the wc folder in the current directory
# uses system default Qt installation
mkdir build
cd build
qmake ../src
make
Windows Command Prompt
:: Assume the git checkout is in the wc folder in the current directory
:: BuildTools can be also Community, Professional or Enterprise - based on what
:: Visual Studio variant you have installed
:: 2019 can be 2017 (again - depends on what you got)
C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Auxiliary\Build\vcvarsall x64
mkdir build
cd build
C:\Qt\5.15.0\msvc2019_64\bin\qmake ..\src
nmake
:: For faster builds, use jom instead of nmake:
C:\Qt\Tools\QtCreator\bin\jom
Note that the path to visual studio installation and the path to Qt installation effectively select the compiler and Qt version. Do not modify the global environment PATH! Instead, you could add a bin folder to your home directory, add that to the path, and add symlinks there to your chosen vcvarsall.bat and qmake.exe.
CMake
But in any case - don't use qmake and make. Use cmake and ninja instead. You'd replace all qmake calls with cmake, and all [n]make calls with ninja. To pass Qt installation path to cmake, use the following options: -DCMAKE_PREFIX_PATH=<path to your Qt install>
macOS/Linux
# assume the git checkout is in the wc folder in the current directory
mkdir build
cd build
cmake -GNinja ../src
ninja
Windows Command Prompt
:: Assume the git checkout is in the wc folder in the current directory
:: BuildTools can be also Community, Professional or Enterprise - based on what
:: Visual Studio variant you have installed
:: 2019 can be 2017 (again - depends on what you got)
C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Auxiliary\Build\vcvarsall x64
mkdir build
cd build
C:\Qt\Tools\CMake_64\bin\cmake -GNinja -DCMAKE_PREFIX_PATH=C:\Qt\5.15.0\msvc2019_64 ..\src
C:\Qt\Tools\Ninja\ninja
When to Run What
Once in a Given Command Prompt
On Windows, the vcvarsall script has to run only once in any given command prompt window. It sets up environment variables needed to find and run the compiler and related tools.
Once in a Given Build Folder
The build script generators qmake and cmake need to be run only once in a given build folder. But qmake is abysmal at dealing with changes that go too far, so in practice you often have to re-run it manually. cmake normally has no such problems - it will re-run itself as needed.
Once Per Build
The build tool itself: ninja, ideally. Or make (on Unix), or jom (on Windows), or nmake (on Windows, if you hate yourself - it's slow).
If a cmake support is missing for an open source project, you can add it.
I created one that let's you run main.cpp, which seemed to be what you wanted. But lacking Qt on my computer, I dropped the dependency to it. I tried with Visual Studio 2019 and it seems to work with the examples in the repo. (Note that you have to create a folder "output" before you run though.)
You should be able to clone https://github.com/eduardovera/D-KHT/pull/3 and run cmake like normal now.
The easiest way to compile a c++ program is to go to your terminal find where your file is stored cd into that path, and then use g++ filename.cpp. And when you run it use ./a.out.

How to build as an ia32 solution from visual studio using cmake

I have a module project using cmake with the following configuration:
cmake_minimum_required(VERSION 3.13)
project(app)
set(CMAKE_CXX_STANDARD 11)
add_library(app MODULE src/library.cpp src/library.h)
Once solution generated using cmake .. -G "Visual Studio 15 2017 Win64" -DCMAKE_BUILD_TYPE=Release, I can find an app.sln solution.
I open it with Visual Studio 2019 and click on the button Local Windows Debugger. I can see also a drop-down menu containing the value x64 and an item Configuration Manager.
Why isn't there an ia32 or x86 option by default? I just can't create a new configuration since the configuration is totally non user friendly.
Anyone has an idea for compile the library for target 32 bits programs?
EDIT
I now compile using cmake .. -G "Visual Studio 16 2019" -DCMAKE_GENERATOR_PLATFORM=x86 -DCMAKE_BUILD_TYPE=Release and the project couldn't be even loaded (cuz of some missing configuration on visual studio, that's what the IDE say)
It appears from the VS 2019 version of the cmake documentation that you should only need to specify:
cmake -G "Visual Studio 16 2019" -A Win32
and I would keep things as simple as possible and let cmake do its job.
Not sure what you mean by "nothing happens" in your last comment. Surely something happened however what happened is not what you expected or wanted.

How to install pbrt-v3 on windows10 with Visual Studio 2017?

I fork the repo and download it, then open it in the Visual Studio 2017 community and did as follows:
1:right-click the MakeLists.txt and click the Rebuild All. (x64 Debug)
2:Then, i found the build directory at here:C:\Users\SHIZU-NOTEBOOK\AppData\Local\CMakeBuild\233159a3-9dca-9735-91fc-be7911e3ef6d\build\x64-Debug\Debug
I can't find the directory like *\bin, also in cmd "pbrt" dosen't work.
Am I wrong with build?and solution!
Sincerely!
Use the cmake-gui or cmake command line tool to generate Visual Studio solution file, then build the solution.
If you choose the command line, here are steps:
Generate solution files
mkdir build && cd build
cmake .. -G "Visual Studio 15 Win64"
Now, open PBRT-V3.sln with Visual Studio 2017
Buile the solution
PS: from the readme in pbrt-v3 project, you need run git submodule update --init --recursive to fetch the dependencies.

libzip with Visual Studio 2010

How can I compile libzip for Visual Studio 2010?
Edit:
Before starting on the answer provided here, it appears that this may no longer be an issue going by #Thomas Klausner's answer below.
The following should get you a VS10 solution:
If you've not already done so, install CMake
Download and extract zlib to e.g. C:\devel. The download links are about halfway down the homepage. Currently this provides zlib version 1.2.7.
To work around this CMake bug which affects 64-bit Windows only, add
if(CMAKE_SIZEOF_VOID_P EQUAL 8 AND MSVC)
set_target_properties(zlibstatic PROPERTIES STATIC_LIBRARY_FLAGS "/machine:x64")
endif()
to the end of C:\devel\zlib-1.2.7\CMakeLists.txt
Download and extract libzip to e.g. C:\devel
In a VS10 command prompt, cd C:\devel\zlib-1.2.7
mkdir build && cd build
cmake .. -G"Visual Studio 10" -DCMAKE_INSTALL_PREFIX="C:\devel\installed\zlib" This sets the install path to C:\devel\installed\zlib rather than the default C:\Program Files\zlib. For 64-bit Windows, use "Visual Studio 10 Win64" as the -G parameter.
msbuild /P:Configuration=Debug INSTALL.vcxproj
msbuild /P:Configuration=Release INSTALL.vcxproj
cd C:\devel\libzip-0.10.1
mkdir build && cd build
cmake .. -G"Visual Studio 10" -DCMAKE_PREFIX_PATH="C:\devel\installed\zlib" Set the path to wherever you installed zlib so that CMake can find zlib's include files and libs. Again, for 64-bit Windows, use "Visual Studio 10 Win64" as the -G parameter.
This should result in C:\devel\libzip-0.10.1\build\libzip.sln. It looks like there are a few POSIX-specific problems in the code, but they should hopefully be fairly easy to resolve (e.g. in zipconf.h #include <inttypes.h> needs replaced with #include <stdint.h>; there are some snprintf calls needing replaced e.g. with _snprintf).
I can't comment, so just in addition to Fraser's answer: In the last days, libzip's latest repository version should compile on VS without additional patches. Please try it out and let the developers know if parts are still missing.
Can't comment on answer above but was trying to get this to work and in the end found that the Output directory under the configuration properties and the comand in debugging.
You can remove ALL_BUILD, ZERO_CHECK, INSTALL and PACKAGE and it will build fine without any of the linking errors or linux specific errors.
Using libzip-1.0.1, zlib-1.2.8, and VS Community 2013.
Added to path:
C:\Program Files (x86)\CMake\bin;C:\Windows\Microsoft.NET\Framework64\v4.0.30319
The cmake line became:
cmake .. -G"Visual Studio 12 Win64" -DCMAKE_INSTALL_PREFIX="C:\devel\installed\zlib"
devel\libzip-1.0.1\lib\zip_source_filep.c:189 changed:
mask = umask(S_IXUSR | S_IRWXG | S_IRWXO);
to:
mask = umask(_S_IREAD | _S_IWRITE);
Using
an environment variable %ZLIB_DIR% for the path to zlib-1.2.8,
%LIBZIP_DIR% for the path to libzip-1.0.1
VS 2015 Express Edition, and
the file %LIBZIP_DIR%/lib/zip_source_filep.c patched according to http://hg.nih.at/libzip/rev/80457805a1e7 ,
the process for building zlib and libzip becomes this:
Building zlib
> cd /d %ZLIB_DIR% && md build & cd build
> cmake .. -G"Visual Studio 14 2015 Win64"- DCMAKE_INSTALL_PREFIX="%ZLIB_DIR%"
> msbuild /P:Configuration=Debug INSTALL.vcxproj
> msbuild /P:Configuration=Release INSTALL.vcxproj
Building libzip
> cd /d %LIBZIP_DIR% && md build & cd build
> cmake .. -G"Visual Studio 14 2015 Win64" -DCMAKE_PREFIX_PATH="%ZLIB_DIR%"
> msbuild /P:Configuration=Debug ALL_BUILD.vcxproj
> msbuild /P:Configuration=Release ALL_BUILD.vcxproj
Done!
(So you see, #MikeLischke, CMake does indeed work out-of-the-box sometimes...)
In current zlib version, there is a contrib for this:
zlib-1.2.8\contrib\vstudio\vc10\zlibvc.sln
I got an error on load because one of the configurations wasn't valid on my machine, but a recompile took care of that. I also had to change the project properties>Configuration Properties>Linker>Input>Additional Dependencies for the Debug configuration to change zlibwapi.lib to zlibwapid.lib.
In Visual Studio 2015, Win64:
If building libzip failing with a message like this:
Could NOT find ZLIB (missing: ZLIB_LIBRARY) (found version "1.2.8").
All you have to do is copy the generated 'zlib.dll/zlibd.zll' and 'zlib.lib/zlibd.lib' to the top of the zlib directory (where the .h/.c files are).
The answer given by Christian Severin helped me a lot, but needed some updates for VS2019 and 32-bit:
When building with VS 2019, you must use the -A option, not use "Win64".
When building with VS 2019, the 32-bit archive is "Win32", not x86.
The "Building zlib" section has a typo, it must be Win64" -DCMAKE_..., with a space before the dash
Here is a working example with VS2019 and 32-bit build:
cd /d %ZLIB_DIR% && md build & cd build
cmake .. -G"Visual Studio 16 2019" -DCMAKE_INSTALL_PREFIX="%ZLIB_DIR%" -AWin32
msbuild /P:Configuration=Release INSTALL.vcxproj
cd /d %LIBZIP_DIR% && md build & cd build
cmake .. -G"Visual Studio 16 2019" -DCMAKE_INSTALL_PREFIX="%ZLIB_DIR%" -AWin32
msbuild /P:Configuration=Release ALL_BUILD.vcxproj