Opened 10 years ago

Last modified 9 years ago

#5699 closed defect

No drivers found — at Version 1

Reported by: nadams Owned by: warmerdam
Priority: normal Milestone:
Component: Docs Version: 1.11.1
Severity: normal Keywords:
Cc:

Description (last modified by Kyle Shannon)

After building from source on Windows 7 with MS Visual Studio 2008, no drivers are found by GDAL.

In the following application, all of the cerr statements get hit:

#include <iostream>
#include "gdal.h"
#include "gdal_priv.h"
#include "ogr_api.h"

int main(int argc, char *argv[])
{
    GDALAllRegister();

    GDALDriverManager dm;
    dm.AutoLoadDrivers();
    int count = dm.GetDriverCount();
    if( count == 0 )
        std::cerr << "Exactly " << count << " drivers found by GDALDriverManager.\n" << std::endl;

    GDALDriver *poDriver = (GDALDriver*) GDALGetDriverByName("ESRI Shapefile");
    if( poDriver == NULL )
        std::cerr << "ESRI Shapefile driver not available.\n" << std::endl;

    GDALDataset* poDS = (GDALDataset*) GDALOpen( "Political_VotingPrecincts.shp", GA_ReadOnly );
    if( poDS == NULL )
        std::cerr << "Open failed.\n" << std::endl;

    return 0;
}

Change History (2)

by nadams, 10 years ago

Attachment: nmake.opt added

comment:1 by Kyle Shannon, 10 years ago

Description: modified (diff)

nadams,

You don't need to instantiate a driver manager. Also you are using the 2.0 unified driver model for GDAL and OGR, but you stated verson 1.11.1 in the ticket.

See the docs here for 1.x:

http://gdal.org/1.11/index.html

If you are using the trunk (2.0dev), then this should work:

#include "gdal.h"
#include "gdal_priv.h"

int main(int argc, char *argv[])
{
    GDALAllRegister();

    GDALDriver *poDriver = (GDALDriver*) GDALGetDriverByName("ESRI Shapefile");
    if( poDriver == NULL )
        std::cerr << "ESRI Shapefile driver not available.\n" << std::endl;

    GDALDataset* poDS = (GDALDataset*) GDALOpen( "Political_VotingPrecincts.shp", GA_ReadOnly );
    if( poDS == NULL )
        std::cerr << "Open failed.\n" << std::endl;

    return 0;
}

If you are using 1.x, you need to use the OGR API for vector datasources (cut from the ogr tutorial):

#include "ogr_api.h"
int main()
{
    OGRRegisterAll();
    OGRDataSourceH hDS;

    hDS = OGROpen( "point.shp", FALSE, NULL );
    if( hDS == NULL )
    {
        printf( "Open failed.\n" );
        exit( 1 );
    }
    /* ... */
    return 0;
}
Note: See TracTickets for help on using tickets.