[gdal-dev] How to Use Gdal in Microsoft Visual Studio C++

classic Classic list List threaded Threaded
16 messages Options
Reply | Threaded
Open this post in threaded view
|

[gdal-dev] How to Use Gdal in Microsoft Visual Studio C++

Athin
Hai All,

I am still new in this GIS subject. May someone guide me how can i use gdal
on Visual Studio 2012 c++. I try to follow from the website Gdal.org but i
dont understand about it. How to generating visual studio project? How to
generate_vcxproj.bat? I try and the solution fail when i open on Visual
Studio.  My windows in 64 bit system.

Thank you and best regards,



--
Sent from: http://osgeo-org.1560.x6.nabble.com/GDAL-Dev-f3742093.html
_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|

Re: How to Use Gdal in Microsoft Visual Studio C++

Mateusz Loskot
On Wed, 31 Oct 2018 at 02:41, Athin <[hidden email]> wrote:
>
> I am still new in this GIS subject. May someone guide me how can i use gdal
> on Visual Studio 2012 c++.

In order to build and use current GDAL, you need Visual Studio 2015 or later.
GDAL requires C++11 compiler
https://trac.osgeo.org/gdal/wiki/rfc68_cplusplus11

You may try VS2013, which offers some C++11 support,
but it is not guaranteed to work at all.

> I try to follow from the website Gdal.org but i
> dont understand about it. How to generating visual studio project? How to
> generate_vcxproj.bat?

For example,

D:\gdal\gdal\> generate_vcxproj.bat 15.0 64 gdal_vs2017
Generating:
  "D:\gdal\gdal\gdal_vs2017.vcxproj"
  "D:\gdal\gdal\gdal_vs2017.vcxproj.user"
  "D:\gdal\gdal\gdal_vs2017.vcxproj.filters"
  "D:\gdal\autotest\cpp\gdal_vs2017_test.vcxproj"
  "D:\gdal\autotest\cpp\gdal_vs2017_test.vcxproj.user"
  "D:\gdal\autotest\cpp\gdal_vs2017_test.vcxproj.filters"
This might take a little while...
Projects done!
Launch Visual Studio IDE
* Open project "D:\gdal\gdal\gdal_vs2017.vcxproj"
* Add  project "D:\gdal\autotest\cpp\gdal_vs2017_test.vcxproj"
* Configure Build Dependencies to build the main project before the
test project.
* Save solution in .sln file
Done!

Finally, since you asked " guide me how can i use gdal",
you do not need VS project to build or use GDAL.
You can build GDAL library from command line using NMAKE and Makefiles provided
See https://trac.osgeo.org/gdal/wiki/BuildingOnWindows
(Note, the page has not been updated regarding minimum VS version
required, so assume it is VS2015).
Then, create your own application project in VS and configure it
setting include directories,
library directories, libraries for linker input.
If you don't know how to use VS, you will need to learn it from the
Microsoft docs, eg.
https://docs.microsoft.com/en-us/cpp/build/vscpp-step-1-create

Best regards,
--
Mateusz Loskot, http://mateusz.loskot.net
_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|

Re: How to Use Gdal in Microsoft Visual Studio C++

Ivan Lucena-5
Hi Athin,

Just to complement what Mateusz wrote, the project files generated automatically are not a *real* Visual Studio C++ project that you can change parameters on the project's property dialogbox. The generated project is what Microsoft calls a Makefile project. It is just a shell around the existing makefile.vc files. When you click on build all it does is to run "name -f makefile.vc" with some parameters.

So it might not be a good idea if you need to integrate with a VS Solution that need to share settings with other *normal* VC projects. The other options for that would be 'GDAL cmake' [https://trac.osgeo.org/gdal/wiki/CMake] but I never use it.

If all you want to do is to compile GDAL I think you would be better off by using command line tools (edit nmake.local based on nmake.opt and run nmake -f makefile.vc, make, make install). Just like Mateusz said.

The automaticly generated projects would give you a complete code scan with autocompletion, go to declaration, go to definition and refactoring tools, just like in a *normal* Visual Studio project but you still need to edit nmake.local to change setting like debugging mode, for example. And more importantly, I haven't use it for a long time so I almost forgot that you can use it for debugging too.

Good luck!

Ivan



On 10/31/18, 4:57 AM, "gdal-dev on behalf of Mateusz Loskot" <[hidden email] on behalf of [hidden email]> wrote:

    On Wed, 31 Oct 2018 at 02:41, Athin <[hidden email]> wrote:
    >
    > I am still new in this GIS subject. May someone guide me how can i use gdal
    > on Visual Studio 2012 c++.
   
    In order to build and use current GDAL, you need Visual Studio 2015 or later.
    GDAL requires C++11 compiler
    https://trac.osgeo.org/gdal/wiki/rfc68_cplusplus11
   
    You may try VS2013, which offers some C++11 support,
    but it is not guaranteed to work at all.
   
    > I try to follow from the website Gdal.org but i
    > dont understand about it. How to generating visual studio project? How to
    > generate_vcxproj.bat?
   
    For example,
   
    D:\gdal\gdal\> generate_vcxproj.bat 15.0 64 gdal_vs2017
    Generating:
      "D:\gdal\gdal\gdal_vs2017.vcxproj"
      "D:\gdal\gdal\gdal_vs2017.vcxproj.user"
      "D:\gdal\gdal\gdal_vs2017.vcxproj.filters"
      "D:\gdal\autotest\cpp\gdal_vs2017_test.vcxproj"
      "D:\gdal\autotest\cpp\gdal_vs2017_test.vcxproj.user"
      "D:\gdal\autotest\cpp\gdal_vs2017_test.vcxproj.filters"
    This might take a little while...
    Projects done!
    Launch Visual Studio IDE
    * Open project "D:\gdal\gdal\gdal_vs2017.vcxproj"
    * Add  project "D:\gdal\autotest\cpp\gdal_vs2017_test.vcxproj"
    * Configure Build Dependencies to build the main project before the
    test project.
    * Save solution in .sln file
    Done!
   
    Finally, since you asked " guide me how can i use gdal",
    you do not need VS project to build or use GDAL.
    You can build GDAL library from command line using NMAKE and Makefiles provided
    See https://trac.osgeo.org/gdal/wiki/BuildingOnWindows
    (Note, the page has not been updated regarding minimum VS version
    required, so assume it is VS2015).
    Then, create your own application project in VS and configure it
    setting include directories,
    library directories, libraries for linker input.
    If you don't know how to use VS, you will need to learn it from the
    Microsoft docs, eg.
    https://docs.microsoft.com/en-us/cpp/build/vscpp-step-1-create
   
    Best regards,
    --
    Mateusz Loskot, http://mateusz.loskot.net
    _______________________________________________
    gdal-dev mailing list
    [hidden email]
    https://lists.osgeo.org/mailman/listinfo/gdal-dev

_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|

Re: How to Use Gdal in Microsoft Visual Studio C++

Athin
Hi all,

Thank for the reply. I think I don't need to start from scratch for gdal. I
can just add the binaries to visual studio right? but may i know how to
install the GDALALLRegister(), from the tutorial it need to be called at the
first of the code.

Thank you and best regards



--
Sent from: http://osgeo-org.1560.x6.nabble.com/GDAL-Dev-f3742093.html
_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|

Re: How to Use Gdal in Microsoft Visual Studio C++

Athin
In reply to this post by Athin
Hai All,

My target just know want to try to display raster map, but i still stuck in
this starting point. The code I run below will display an error

error c4700 uninitialized local variable 'pszFilename' used

can someone help me regarding this and what i need to with the file i
download from this link:https://trac.osgeo.org/gdal/wiki/DownloadSource

where i need to add on VS2012?

Thank you and best regards

#include "gdal_priv.h"
#include "cpl_conv.h" // for CPLMalloc()
#include "stdafx.h"
#include "gdal.h"


int main()
{
        class GDALDataset;
        const char *pszFilename;
       

    GDALDataset *poDataset;
        void CPL_DLL CPL_STDCALL GDALAllRegister(void);

    poDataset = (GDALDataset *) GDALOpen(pszFilename, GA_ReadOnly );
    if( poDataset == NULL )
        {}

}



--
Sent from: http://osgeo-org.1560.x6.nabble.com/GDAL-Dev-f3742093.html
_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|

Re: How to Use Gdal in Microsoft Visual Studio C++

bradh
The problem below is nothing to do with GDAL, you just need to initialise the variable (probably by some kind of command line argument - argv[1] if nothing else). If that doesn't make sense, is there another programming language that you are more comfortable with?

Brad

-----Original Message-----
From: gdal-dev <[hidden email]> On Behalf Of Athin
Sent: Thursday, 1 November 2018 8:32 PM
To: [hidden email]
Subject: Re: [gdal-dev] How to Use Gdal in Microsoft Visual Studio C++

Hai All,

My target just know want to try to display raster map, but i still stuck in this starting point. The code I run below will display an error

error c4700 uninitialized local variable 'pszFilename' used

can someone help me regarding this and what i need to with the file i download from this link:https://trac.osgeo.org/gdal/wiki/DownloadSource

where i need to add on VS2012?

Thank you and best regards

#include "gdal_priv.h"
#include "cpl_conv.h" // for CPLMalloc() #include "stdafx.h"
#include "gdal.h"


int main()
{
        class GDALDataset;
        const char *pszFilename;
       

    GDALDataset *poDataset;
        void CPL_DLL CPL_STDCALL GDALAllRegister(void);

    poDataset = (GDALDataset *) GDALOpen(pszFilename, GA_ReadOnly );
    if( poDataset == NULL )
        {}

}



--
Sent from: http://osgeo-org.1560.x6.nabble.com/GDAL-Dev-f3742093.html
_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev

_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|

Re: How to Use Gdal in Microsoft Visual Studio C++

Ivan Lucena-5
In reply to this post by Athin
Athin,

If this is your target, GDAL might not be the right choice for you.
   
    My target just know want to try to display raster map, but i still stuck in
    this starting point. The code I run below will display an error

The GDAL API doesn't support display capabilities. If you go ahead and solve the problems that you are facing you will end up with a buffer of pixels in memory, in order to get that as an image/map into a desktop window you need to write your own code (against Microsoft APIs probably) or call some other library that have that capability.
   
    can someone help me regarding this and what i need to with the file i
    download from this link:https://trac.osgeo.org/gdal/wiki/DownloadSource

You don't need to download the GDAL source code and compile it to follow the GDAL tutorial. You can get the binary distribution from GISInternals [https://trac.osgeo.org/gdal/wiki/DownloadingGdalBinaries]
   
    where i need to add on VS2012?
    error c4700 uninitialized local variable 'pszFilename' used

I would advise you to take some VS and C++ tutorials/exercises to get familiar with the language itself, error messages and the programming environment.

Good luck,

Ivan

_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|

Re: How to Use Gdal in Microsoft Visual Studio C++

Athin
In reply to this post by bradh
Hai Bradh,

Sorry I not use to C++, I only familiar with C#. I need to use C++ because
Gdal support it and i need to combine it to the Visual Studio C# (Wpf).

Thank you and best regards.



--
Sent from: http://osgeo-org.1560.x6.nabble.com/GDAL-Dev-f3742093.html
_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|

Re: How to Use Gdal in Microsoft Visual Studio C++

Athin
In reply to this post by Ivan Lucena-5
Hai Ivan,

Yeah I will take the C++ tutorials/exercise. But I need to try a bit the
Gdal capability. I just want to try it first hand by follow the tutorial,
but it seem there is not many example that allow to see the running of
complete code. Did you have any GDAL sample that can share with me?

Thank you and best regards





--
Sent from: http://osgeo-org.1560.x6.nabble.com/GDAL-Dev-f3742093.html
_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|

Re: How to Use Gdal in Microsoft Visual Studio C++

bradh
In reply to this post by Athin
There are C# bindings for GDAL: https://trac.osgeo.org/gdal/wiki/GdalOgrInCsharp
Examples are at https://trac.osgeo.org/gdal/browser/trunk/gdal/swig/csharp/apps

You may also find Nuget packages, however I haven' tried that.

Brad

-----Original Message-----
From: gdal-dev <[hidden email]> On Behalf Of Athin
Sent: Friday, 2 November 2018 11:44 AM
To: [hidden email]
Subject: Re: [gdal-dev] How to Use Gdal in Microsoft Visual Studio C++

Hai Bradh,

Sorry I not use to C++, I only familiar with C#. I need to use C++ because Gdal support it and i need to combine it to the Visual Studio C# (Wpf).

Thank you and best regards.



--
Sent from: http://osgeo-org.1560.x6.nabble.com/GDAL-Dev-f3742093.html
_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev

_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|

Re: How to Use Gdal in Microsoft Visual Studio C++

Ivan Lucena-5
In reply to this post by Athin
Hi Athin,

I think we have some problem with the GDAL tutorials. The first example in C and C++ have the same error as your code, pszFilename is not initialized [https://www.gdal.org/gdal_tutorial.html]. It is not supposed to be a full source code sample, but anyway...

    Yeah I will take the C++ tutorials/exercise. But I need to try a bit the
    Gdal capability. I just want to try it first hand by follow the tutorial,
    but it seem there is not many example that allow to see the running of
    complete code. Did you have any GDAL sample that can share with me?

The code that I wrote for GDAL is for format-drivers (BYN, RST, GEORASTER, INGR) and GDAL driver code are usually too complex and not good example, if what you want is to developer application based on the GDAL public API.

But we do have some good code sample in other programming language that might be of you interest:

https://github.com/OSGeo/gdal/tree/master/gdal/swig/csharp/apps

https://github.com/OSGeo/gdal/tree/master/gdal/swig/java/apps

https://github.com/OSGeo/gdal/tree/master/gdal/swig/python/samples

Best regards,

Ivan







_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|

Re: How to Use Gdal in Microsoft Visual Studio C++

Athin
Hai Ivan,

May i know the function of the swig(c#) that you share to me?

Thank you and best regards



--
Sent from: http://osgeo-org.1560.x6.nabble.com/GDAL-Dev-f3742093.html
_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|

Re: How to Use Gdal in Microsoft Visual Studio C++

Ivan Lucena-5
Hi Athin,

Here it goes again:

https://github.com/OSGeo/gdal/tree/master/gdal/swig/csharp/apps

For more information on GDAL's C# API:

https://trac.osgeo.org/gdal/wiki/GdalOgrInCsharp

Regards,

Ivan

On 11/6/18, 8:34 PM, "gdal-dev on behalf of Athin" <[hidden email] on behalf of [hidden email]> wrote:

    Hai Ivan,
   
    May i know the function of the swig(c#) that you share to me?
   
    Thank you and best regards
   
   
   
    --
    Sent from: http://osgeo-org.1560.x6.nabble.com/GDAL-Dev-f3742093.html
    _______________________________________________
    gdal-dev mailing list
    [hidden email]
    https://lists.osgeo.org/mailman/listinfo/gdal-dev

_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|

Re: How to Use Gdal in Microsoft Visual Studio C++

Tamas Szekeres
Packages for GDAL have also been submitted to nuget.org  (GDAL, GDAL.Native and GDAL.Plugins) which could be referenced in your Visual Studio project easily.


Best regards,

Tamas

Ivan Lucena <[hidden email]> ezt írta (időpont: 2018. nov. 7., Sze, 14:44):
Hi Athin,

Here it goes again:

https://github.com/OSGeo/gdal/tree/master/gdal/swig/csharp/apps

For more information on GDAL's C# API:

https://trac.osgeo.org/gdal/wiki/GdalOgrInCsharp

Regards,

Ivan

On 11/6/18, 8:34 PM, "gdal-dev on behalf of Athin" <[hidden email] on behalf of [hidden email]> wrote:

    Hai Ivan,

    May i know the function of the swig(c#) that you share to me?

    Thank you and best regards



    --
    Sent from: http://osgeo-org.1560.x6.nabble.com/GDAL-Dev-f3742093.html
    _______________________________________________
    gdal-dev mailing list
    [hidden email]
    https://lists.osgeo.org/mailman/listinfo/gdal-dev

_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev

_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|

Re: How to Use Gdal in Microsoft Visual Studio C++

Athin
Hai Tamas,

May i know what the package for GDAL at nuget.org (GDAL, GDAL.Native and
GDAL.Plugins) cover? It can fully C# or  i still need ti use C++ then make
extension to C# so that it can use VS Wpf.

Thank you and best regards.



--
Sent from: http://osgeo-org.1560.x6.nabble.com/GDAL-Dev-f3742093.html
_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|

Re: How to Use Gdal in Microsoft Visual Studio C++

Gigas002
Hi Athin,
Not exactly an answer to your question, but there is a good nuget package
for using in c#, called GDAL.NET:
https://www.nuget.org/packages/GDAL.NET/
It contains bindings, automatically added to your project after build gdal's
binary files and GdalConfiguration class that will automatically setup
GDAL/OGR environment variables and paths after you call ConfigureGdal().
About covering of .net gdal, I suppose bindings have been a bit forgotten in
community, and there some really outdated classes, that have only pre-2.0
funcs (take a look at this issue for example):
https://github.com/OSGeo/gdal/issues/918
As for me, I personally use GDAL.NET bindings as a replacement for gdal
utilities (gdal_translate, gdalwarp, gdalbuildvrt etc.), I just prefer to
call them as methods from code, not as process.



--
Sent from: http://osgeo-org.1560.x6.nabble.com/GDAL-Dev-f3742093.html
_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev