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.
Related
I am trying to compile GDCM 2.8.4 for Windows. Can anybody describe how to compile it with Visual Studio 2013 Professional? The GDCM wiki is out of date. Thanks a lot.
First of all, you will have to install CMake. Then
Start CMake GUI.
I guess you already have the gdcm-2.8.4 directory (in a directory X:\XXXXX\ ) containing
Applications
Source
Testing
Utilities
and other subdirs. So set the in the CMake GUI "source dir" to X:\XXXXX\gdcm-2.8.4 . (NOT to its Source subdir!).
Then you create a new directory, where CMake will create the VS projects, let's call it X:\XXXXXX\GDCM-VSProjects. In the CMake GUI set "Where to build the binaries" to X:\XXXXXX\GDCM-VSProjects.
Then, in the CMake GUI press "Configure".
After configuring CMake offers you some options; choose at least GDCM_BUILD_APPLICATIONS, GDCM_BUILD_EXAMPLES, GDCM_BUILD_SHARED_LIBS. For documentation you will need doxygen, latex and possibly more.
Then, in the CMake GUI press "Generate". Now a lengthy calculation is performed and finally VS solution and VS subprojects are generated into your new X:\XXXXXX\GDCM-VSProjects subdirectory.
Now you can open GDCM.sln in VisualStudio and BuildAll in 64 bit Release mode.
After the build, you will find libs, dlls and exes in the bin/Release subdirectory of your X:\XXXXXX\GDCM-VSProjects.
Thats it.
i'm new in geotiff processing. now, i need to read my geotiff data by using gdal Api. I want to integrate gdal to visual studio so that i can working on c++. I have generated gdal to VS project by commend makegdal_gen 10.00 64 > gdal10.vcproj and successfully. However, i get missing several header which does not exist in gdal directory or folder such as hdf.h and etc. I want to ask, anyone know where i can find full gdal or is there any way to import gdal to visual studio C++ easily? Thank you
Once you have generated gdal10.vcproj, you need to build it.
You should follow the official documentation.
Main steps (slightly modified from doc, assuming you have a recent version of VS):
Check the basic options in nmake.opt, especially the settings for the VC variant to use and for the installation directory.
Open "Visual Studio Command Prompt" in the start menu. If you plan to compile for the 64bit platform be sure to choose the correct bat / command prompt.
Go to the GDAL root directory and do the following:
C:\GDAL> nmake /f makefile.vc
Once the build has completed successfully, you can also install the required GDAL files for using GDAL utilities using the install makefile target. Ensure that BINDIR, and DATADIR are set appropriately in the nmake.opt file before doing this.
C:\GDAL> nmake /f makefile.vc install
If you wish to build your own applications using GDAL you can use the following command to install all the required libraries, and include files as well. Ensure that LIBDIR and INCDIR are properly set in the nmake.opt file.
C:\GDAL> nmake /f makefile.vc devinstall
Projects linking against GDAL should include the directory specified in INCDIR in the include path, and the directory specified in LIBDIR in their /LIBPATH. To use gdal link against the gdal_i.lib stub library.
i am using qt 5.5.0 for which I am trying to build qtsvg submodule
i am using the following steps.
PROCESS:-
1.Download Reqirements
Qt source code http://www.qt.io/download-open-source/#section- (here i am using Qt 5.5.0)
Visual Studio 2012 express
ActivePerl-5.20.2.2002-MSWin32-x64
Python 3.5.0 (for x64) through the installer
Jom
Rubyinstaller-2.2.3-x64 or later
Extract the source code in a directory( I’ve done it in “C:\Qt\5.5.0”)
Extract jom in a directory.(i’ve extract in “c:\”)
Set the environment variables(set them from properties of Computer->advanced System Settings->Advanced tabs->Environment Variables-> User Variables)
QTDIR=C:\Qt\qt-5.5.0\vs2011
QMAKESPEC=win32-msvc2012
Add below in PATH
%QTDIR%\bin;
C:\Qt\5.0.0\gnuwin32\bin;
C:\icu\bin64;
C:\Python27\DLLs;
C:\Python27
C:\Perl64\site\bin
C:\Perl64\bin
Restart or log off/on your computer in order to let environment variables changes take place.
Open VS2012 x64 Cross Tools Win64 Command Prompt (2012) (In case of 64 bit build) or Visual Studio x86 Native Tools Command Prompt (2012) (In case of 32 bit build) in Administrator mode for msvc 2011 compiler.
[You will find command prompt here - ( C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Microsoft Visual Studio 2012\Visual Studio Tools )]
On visual studio command prompt run the following commands
cd C:\Qt\build\
C:\Qt\5.5.0\configure -debug-and-release -shared -opensource -platform win32-msvc2012
C:\jom_1_1_0\jom.exe
After following all the above Steps, I found that qtsvg DIR is present in build, but as I am trying to use it in CMake, it is generating an Error, at Qtsvg is not found.
On Manually Coppying the Dir. The error is still Generate as:
CMake Error at C:/Qt/build/lib/cmake/Qt5Core/Qt5CoreMacros.cmake:327 (message):
Can not use "Svg" module which has not yet been found.
Call Stack (most recent call first):
CMakeLists.txt:50 (qt5_use_modules)
Can someone Help me or guide me what I am doing wrong?????
while Building Qt using the above mentioned method, I skipped to notice that for building all the modules of QT the build is obtained at Qbase directory any in CMake I was using the outer Directory which does not exist in this case
the build is in C:\Qt\5.5.0\build-5.5.0\qtbase\lib\cmake\Qt5
however I was checking in C:\Qt\5.5.0\build-5.5.0\lib\cmake\Qt5 hence Cmake was not able to find the correct path
I like to build boost 1.58.0 using the (new) Visual Studio 2015 (Enterprise). In the past I proceeded in the following way:
Download boost 1.58.0 from www.boost.org
Extract files (e.g. C:\thirdparty\vs2013\x64\boost_1_58_0)
Start Visual Studio 2013 x64 command prompt (VS2013 x64 Native Tools Command Prompt)
Change to boost directory (e.g. cd C:\thirdparty\vs2013\x64\boost_1_58_0)
Execute .\bootstrap.bat
Execute .\b2 -j8 --toolset=msvc-14.0 address-model=64 --build-type=complete stage
b2 -j8 --toolset=msvc-12.0 address-model=64 --build-type=complete stage --with-python
But in VS2015 there is not VS2015 command prompt.
Also the vcvarsall.bat is missing that I used sometimes to setup a VS2013 command prompt.
How can I compile the source code of boost using VS2015?
Unfortunately Boost documentation is quite verbose because it tries to take care of all OS and environments. Also, it skips over some time saving details. Here's quick steps specifically for VS2015 with Boost 1.61.
First, let's understand that Boost is huge library with lots of contributors. Consequently, all of the Boost code is divided in to two parts: headers only libraries and header+cpp libraries. The former doesn't require compilation. You just include them and you are done. Later does require building. You typically don't need to worry about extra steps of building, although its good idea to just set everything up once.
Using Boost Header Only Libraries
Download the Boost archive in 7z format and extract using 7Zip. The zip file is much bigger than 7z file and can take over 20 minutes to extract by Windows Explorer vs 5 minutes by 7Zip.
Create folder c:\Program Files\boost. Copy extracted boost_1_61_0 folder in this folder. This exact path is not a requirement but we will use that here.
In whatever VC++ project you want to use Boost, go to that project's right click Properties > C/C++ > General > Additional Include Directories and add path C:\Program Files\boost\boost_1_61_0 without quotes.
Now you should be able to use most of the Boost libraries by using statement like #include <boost/thread/mutex.hpp>.
Using Boost Header+CPP Libraries
Examples of these are Boost.Chrono, Boost.Filesystem, Boost.GraphParallel, Boost.IOStreams, Boost.Locale, Boost.Regex, Boost.Thread, Boost.System etc. Unless you are using these libraries, following steps are not needed.
First make sure you don't have Windows Driver Kit installed. If you have, uninstall it for now because most likely it has messed up include paths that will cause Boost's build script to fail.
Invoke VS2015 x64 Native Tools Command Prompt as Administrator.
CD to C:\Program Files\boost\boost_1_61_0 and then run bootstrap.bat.
Run .\b2
Run .\b2 variant=debug,release link=static runtime-link=static address-model=64
Cut folder C:\Program Files\boost\boost_1_61_0\stage\lib and copy it to C:\Program Files\boost\boost_1_61_0\lib.
For the VC++ Console project you want to use these libraries, right click Properties > Linker > General > Additional Library Directories and add path C:\Program Files\boost\boost_1_61_0\lib. For VC++ library projects you will find same setting in Properties > Librarian.
Now you are all set!
Note: Original question about not finding command prompt is addressed by answer from #Arnaud. Above are more clarified steps for Boost installation also step #5 below for more detail on command prompt.
I Tried to install Qt and I had the same issue: vcvarsall.bat was missing.
In my case the problem was that I unchecked The Visual C++ Common Tools.
I modified my VS 2015 installation and added the missing feature Common Tools for Visual C++ 2015:
After the modification, the File is in C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC
below are the steps
1) Download library from below this site http://www.boost.org/
2) Unzip it.[I have extracted files at "F:\Internet-Downloads\boost_1_65_1" path]
3) Open "Developer Command Prompt for VS2015" as shown in the below snapshot.
4) Go to the directory in which you have extracted your files.
5) run bootstrap.bat file as shown in the below snapshot
6) you will get installation information as shown in below snapshot
7) start VS2015, and create a test application as shown in below snapshot
8) include boost directory in your project[Project Propertry->C/C++->General->Additional Include Directories]as shown in below snapshot
9) Run the application, add "_SCL_SECURE_NO_WARNINGS" in the preprocessor directory if you encounter with "error C4996: 'std::_Copy_impl': Function call with parameters that may be unsafe ......" error.[Priject Property->C/C++->Preprocessor->Processor Definitions]
10 output:
Use https://github.com/Microsoft/vcpkg from the VS Command Prompt.
To find and invoke VS2015 x64 Native Tools Command Prompt, just start typing "native" in Windows Start->Search programs and files text box. System should find command prompt
Is there anyone who succeed to include libjpeg in some compiler? I tried everything: Dev C++, VS10, CodeBlocks, copy the headers and the lib by hand, add with the linker but nothing. Right now I am really confisued as there is not an official guide on how to compile it in any compiler. I would be really happy if someone could provide a tutorial on how the library can be compiled in any compiler.
Thank you in advance.
To compile libjpeg 9 in Visual Studio 2012, here are the steps (after unzipping the archive file):
Download the file WIN32.MAK (for example, from http://www.bvbcode.com/code/f2kivdrh-395674-down), and place a copy in the root source code directory (possibly C:\jpeg-9, but it depends where you unzipped it). I will refer to this directory as %jpegsrc% from now on. Having this file is important; otherwise step 3 will produce an error.
In the Visual Studio command prompt, open to %jpegsrc%:
cd %jpegsrc%
At the same command prompt, execute the following:
NMAKE /f makefile.vc setup-v10
This will create two Visual Studio 2010 solutions in %jpegsrc%: jpeg.sln and apps.sln.
Open each solution in Visual Studio 2012. Each one will prompt you to update all the projects to 2012 format. Click on “Update.” One time I did it, the prompt did not appear. In case that happens, right-click on the jpeg solution in the Solution Explorer, and choose “Update VC++ projects...,” which will produce the same prompt.
Save and build each solution as normal. (You have to build the jpeg.sln solution before apps.sln, since the latter depends on the former.)
Note: this process should work correctly in Visual Studio 2010, without the updating, but I have not tested it.
Update: This method still works in Visual Studio 2015 for libjpeg-9a.
Here is how I've built libjpeg using MinGW on Windows :
1. Get MinGW with MSYS
I've got a copy from http://sourceforge.net/projects/mingw/.
Quoting from www.mingw.org :
MSYS is a collection of GNU utilities such as bash, make, gawk and grep to allow building of applications and programs which depend on traditionally UNIX tools to be present.
We will need it to run the configure script that comes with libjpeg sources.
2. Get libjpeg sources
From http://www.ijg.org/, take the Unix format package (the Windows one won't work with this procedure). I took the jpeg_8d version.
3. Prepare a building directory
I've made a temporary directory named tmp in D:\, but you could choose whatever suits your needs. The thing that matters is the name of paths in MSYS. As it brings some * Unixity * to Windows, paths cannot be used in their original form.
In a nutshell:
C:\path\to\file becomes /c/path/to/file in MSYS land, an so
D:\tmp becomes /d/tmp.
Decompress the libjpeg sources in D:\tmp, so you have a jpeg-8d directory in there.
Create a jpeg-build directory inside D:\tmp, it will hold the built library.
Now everything is ready for the build.
4. ./configure, make, make install
That is the mantra of building in Unix land. An option should be added to redirect the install process to D:\tmp\jpeg-build.
Run the following commands in an MSYS shell (also named MinGW shell in Windows start menu):
cd /d/tmp/jpeg-8d
./configure --prefix=/d/tmp/jpeg-build
make
make install
As an additional step, you can run make test for safety.
These commands will build both static and shared versions of libjpeg.
5. Take the goods, delete the temporaries
If everything runs fine, you can delete the D:\tmp\jpeg-8d directory, but keep the jpeg-build one. It contains:
an include directory, containing libjpeg headers. You can move them to your compiler's headers directory.
a lib directory, with .a file to pass to the linker. You can move them to your compiler's library directory.
a bin directory, holding the libjpeg shared library libjpeg-8.dll and jpeg tools.
a share directory, containing man pages for the jpeg tools.
You can now build your program and link it against libjpeg by indicating the right include and library paths.
You can find many details about the libjpeg building and installation process in install.txt inside the source package.
I hope this will be useful.
It is really simple to build jpeg.lib with VS10.
First, download the libjpeg source code in zip format. At the time I'm writing this you can find it here.
Then extract the contents of the zip file to your disk.
Then open a VS2010 command prompt shell (or call vcvarsall.bat on any command prompt window), cd to the jpeg source directory (jpeg-8d in the download referenced above) and type the following:
nmake -f makefile.win setup-v10
This will generate two VS2010 solutions, and a bunch of project files. The solutions are:
jpeg.sln, which builds jpeg.lib
apps.sln, which builds the sample applications.
Good luck!
If you don't happen to have Visual Studio 2010 installed, here is what works on Visual Studio 2017:
Basic / Common steps:
Download the latest version of libjpeg from: http://www.ijg.org/ (zip version) and extract it to a folder
Open the "Developer Command Prompt for VS2017"
Change directory (cd) to where you extracted the library source
VS 2017 Approach:
Include the Windows SDK v7.1A directory (required for Win32.Mak by nmake later on) by running: set INCLUDE=%INCLUDE%;c:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Include
Run nmake /f makefile.win setup-v15 (note the v15 for VS2017 here)
From here on follow what #AthanasiusOfAlex explained to upgrade the Visual Studio 2010 solution to the Visual Studio version you are running. If you want the Debug configuration, follow what #SteveEng explained.
Errors you might stumble across:
If nmake fails and tells you it doesn't know how to make
jconfig.h, manually rename the file jconfig.vc to jconfig.h
If nmake fails and tells you Win32.Mak cannot be found, manually copy it from the SDK dir mentioned in step #4 to the libjpeg source directory. If you don't happen to have that SDK version installed, download the file from a trustworthy resource.
If nmake fails and tells you it doesn't know how to make setup-v15, trial and error your way through starting with setup-v10, setup-v11, etc... These are VS versions and one of them should work as long as you have any VS version later than VS 2008 installed.
Hope this helps people going through similar pain with this.
If you want debug mode as well in MSVC. Follow AthanasiusOfAlex's method, build the release, then:
Right-click on the project and select properties at the very
bottom
Click on configuration manager and on the active solution
configuration drop-down select -new-
Set the name to debug and on
the drop-down select copy configuration settings from release and
click OK
Close the dialog, go to general settings and under Target
Name add a d to the end so it looks like this: $(ProjectName)d
On Whole Program Optimization drop-down select: No Whole Program Optimization
Then click on the C/C++ under configuration properties on the left and on the Debug Information Format drop-down select C7 compatible (/Z7)
Under optimization select disabled and select NO for both Enable Fiber-Safe Optimizations and Whole Program Optimizations
Under preprocessor, preprocessor definitions, click on edit and use the following:
WIN32
_DEBUG
DEBUG
_LIB
_CRT_SECURE_NO_WARNINGS
Under code generation, under runtime library select Multi-threaded Debug DLL (/MDd)
Build and you're done!
This is for VS2019 with version number 16.0
Consider the Visual Studio Version name correctly like this for creating the .sln file.
Product name Code name Version number
Visual Studio 2019 Dev16 16.0
Visual Studio 2017 Dev15 15.0
Visual Studio 2015 Dev14 14.0
Visual Studio 2013 Dev12 12.0