VS2017 configuration GDAL+qt (win10)

Table of contents

1. Download vs2017

Install .Net Framework 4.6

Install VS 2017

2. Configure GDAL

1. Download GDAL

2. Modify the source code

3. Run the Native Tools Command Prompt for X64 for VS2017 as administrator

4. Compile GDAL

5. Install GDAL

6. Configure GDAL in the VS2017 project

7. Set environment variables

3. Download Qt

1. Download Qt 5.12

2. Installation

4. Download qt-vsaddin-msvc2017

1. Download qt-vsaddin-msvc2017-2.5.2

2. Installation

Five, VS2017 configuration Qt


1. Download vs2017

VS 2017 Community Edition (Community) download address:
Baidu Netdisk download link:  Baidu Netdisk Please enter the extraction code  Password: ub6c

The downloaded file is less than 1 MB in size, and it is just an installation guide for the Simplified Chinese version of VS 2017 Community. After starting, check the required components to download and install online.

It is also available for download from the official Microsoft website: Visual Studio Older Downloads - 2019, 2017, 2015 and previous versions

You need to log in with your own Microsoft account 

After downloading the VS 2017 installation bootloader, double-click to run it. If the following Visual Studio prompt appears (if this prompt does not appear, you can directly omit this link):

Before installing VS 2017, you need to install a higher version of .Net Framework first. It is recommended to directly download the . Net Framework 4.6 installation package for installation, which is faster.

Install .Net Framework 4.6

Download address of .Net Framework version 4.6:

  • Thunder download (faster):

ed2k://|file|mu_.net_fx_4_6_2_for_win_7sp1_8dot1_10_win_server_2008sp2_2008r2sp1_2012_2012r2_x86_x64_9058211.exe|62008080|D36FDF083FF2970FD8B0080664AD32C6|

 After the download is complete, you will get a .net framework installation package, double-click to open it, and the following installation progress bar will appear:
 

After the progress bar reaches 100%, it will automatically jump to the following page:

Check "I have read and accept the license terms", and then click the "Install" button to install:

When the "File Security Verification" progress bar and the "Installation Progress" progress bar both reach 100%, the program will prompt you that the installation is complete, just click Close (you may need to restart the computer at this time, it doesn't matter, just restart).

Install VS 2017

After the download of VS 2017 is complete, you will get an executable file to guide the user to install. Double-click the file, and if there is no problem with the .Net Framework version, you will enter the installation page:


 

Click the "Continue" button directly, and a progress bar will pop up:


 

After Visual Studio is ready, it will jump directly to the following page:

In addition to supporting C/C++ development, VS 2017 also supports development languages ​​such as C#, F#, and Visual Basic. We don't need to install all the components, just install "Desktop Development Using C++".

If the visual studio installer does not have a progress bar after opening, and all data is zero, you need to set up the computer network.

[Settings] - [Change Adapter Options] - [Internet Protocol Version 4 (TCP/Ipv4)] - [Properties]

 Set to the following interface

Re-opening vs installer successfully started the download.
At the same time, on this page, you can also choose the storage location of VS 2017. It is recommended not to install it on the C drive, and you can choose other drives. Then click Install directly, the installation process may take a while, please wait patiently.
 

After the installation is complete, VS 2017 will ask to restart the computer, and the saved ones can be restarted as required.

After the restart is complete, open the "Start Menu", and you will find an icon called "Visual Studio 2017", which proves that your installation is successful.

2. Configure GDAL

1. Download GDAL


The official download address is https://trac.osgeo.org/gdal/wiki/DownloadSource, the version I downloaded is gdal-2.3.1. It is recommended to decompress it in the root directory of a certain disk. For example, my decompression address is D:\gdal-2.3.1. For the convenience of use, change the decompression file name to gdal (must be changed!).

2. Modify the source code


Find the nmake.opt file in the decompression directory, for example, the file path in this article is: D:\gdal\nmake.opt. Then open it with VS2017, other text editors are not recommended. I modified a total of three locations in the file:

The code on line 41 is modified to: MSVC_VER=1910 (determined according to the compiler. 1400 means the VS version is 2010, 1800 means the VS version is 2013, 1900 means the VS version is 2015, 1910 means the VS version is 2017, 1921 means the VS version is 2019)

[View and use in the editor] The code is as follows:

#if (_MSC_VER >= 1500 && _MSC_VER <= 1600)

#else

#endif


The code on line 57 is modified to: GDAL_HOME = "D:\gdal"


Modify the code on line 184: it was originally # WIN64=YES and changed to WIN64=YES

3. Run the Native Tools Command Prompt for X64 for VS2017 as administrator

The native tools command prompt for X64 for VS2017 can be found in the start menu, be sure to run it as administrator. If your VS2017 is an English version, please run x64 Native Tools Command Prompt for VS 2017 as an administrator.

4. Compile GDAL

Enter the following three lines of code in sequence on the command line:

cd D:\gdal
d:
nmake /f makefile.vc
starts to compile, and the compilation process takes a few minutes.

5. Install GDAL

After the compilation is completed, continue to execute the following two commands:

nmake /f makefile.vc install
nmake /f makefile.vc devinstall

6. Configure GDAL in the VS2017 project

Open vs2017 and create a new c++ empty project. Then open the Property Manager via View->Other Windows->Property Manager.

In the red box as shown below, right click and select Properties.

Add the include directory and library directory in turn in the VC++ directory

Then add additional dependencies in Linker -> Input, and manually enter gdal_i.lib as shown below:

Click Apply -> OK. So far, gdal has been successfully configured in VS2017.

7. Set environment variables

Click Computer->Properties->Advanced System Settings->Environment Variables->path in System Variables 

Click Edit and add: D:\gdal\bin 

Click the OK button. To be on the safe side, the computer should be restarted at this time to ensure that the environment variables take effect.

8. Test whether the configuration is successful.
The following is a test code I found on the Internet. It only needs an image in jpg format, and then modify the code pszFile = "D:/2.jpg"; to your own image path and name. Can. Note: The program needs to run under X64!

#include "gdal_priv.h"
#include<iostream>  
using namespace std;
int main()
{
    const char* pszFile;
    GDALAllRegister();
    pszFile = "D:/2.jpg";
    GDALDataset *poDataset = (GDALDataset*)GDALOpen(pszFile, GA_ReadOnly);
    GDALRasterBand *poBand = poDataset->GetRasterBand(1);
    int xsize = poBand->GetXSize();
    int ysize = poBand->GetYSize();
    cout << xsize << endl;
    cout << ysize << endl;
    system("pause");
 
    return 0;
}


If you can successfully output the size of the image, congratulations, you're done!
 

3. Download Qt

1. Download Qt 5.12

http://download.qt.io/archive/

2. Installation

When selecting components, you can choose according to your needs. The following are recommendations, and others directly choose the next step

 After installing vsaddin, you can import the qt project into vs 

4. Download qt-vsaddin-msvc2017

1. Download qt-vsaddin-msvc2017-2.5.2

​​http://download.qt.io/archive/vsaddin/

2. Installation

The installation is very simple, just follow the next step along the way.

Five, VS2017 configuration Qt

Open VS2017, if vsaddiin is installed correctly, there will be an extra menu in the menu bar of 2017: Qt Vs Tools

Click Qt Versions to add Qt

 Click the folder, find the Qt installation path, and find qmake.exe under msvc2017\bin

 Click OK.

Create a qt project in vs2017

 execution succeed!

 Reference blog: VS2017 compile and configure GDAL - super detailed, suitable for beginners! ! ! _Zou Siyuan's blog-CSDN blog_gdal compilation

VS2017+Qt5.12 environment to build a perfect tutorial sharing-Knowledge

How to check the version of Visual Studio and the corresponding relationship with the version number of MSVC

VS2017 download address and installation tutorial (graphic)

Guess you like

Origin blog.csdn.net/qq_45929977/article/details/120518262