Information on how to get ECW working with GDAL is all over the place. This resource aims to provide you with concise instructions to get ECW going through a simple GDAL plugin rather than compiling the entire GDAL library from source --with-ecw.
This approach is tested on Manjaro using the repo-maintained GDAL package (Official Repository, extra); works like a charm in QGIS (also installed from Official Repository, extra).
- Install a repo-maintained GDAL. The next steps outlined below worked well with GDAL 3.1.3 installed from UbuntuGIS-unstable PPA (
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable
) as well as with GDAL 3.7.0 under Manjaro installed from their Official Repository, extra. - Download the ERDAS ECW SDK; this guide is based on 5.4 update 1 (http://download.hexagongeospatial.com/downloads/ecw/erdas-ecw-jp2-sdk-v54-update-1-for-linux)
- Unzip and make the .bin executatble:
chmod +x ERDAS_ECWJP2_SDK-5.4.0.bin
./ERDAS_ECWJP2_SDK-5.4.0.bin
sudo cp -r hexagon/ERDAS-ECW_JPEG_2000_SDK-5.4.0 /usr/local
sudo ln -s /usr/local/ERDAS-ECW_JPEG_2000_SDK-5.4.0/Desktop_Read-Only/lib/newabi/x64/release/libNCSEcw.so /usr/local/lib/libNCSEcw.so
sudo ln -s /usr/local/ERDAS-ECW_JPEG_2000_SDK-5.4.0/Desktop_Read-Only/lib/newabi/x64/release/libNCSEcw.so.5.4.0 /usr/local/lib/libNCSEcw.so.5.4.0
sudo ldconfig
- Make sure the GDAL plugins directory exists; e.g.
/usr/lib/gdalplugins
(used below) or/usr/local/lib/gdalplugins
- clone this git repository
- Create a sibling directory to build the plugin:
mkdir libgdal-ecw-build
cp libgdal-ecw/src/* libgdal-ecw-build
cd libgdal-ecw-build
autoreconf --force --install -v
sh ./configure --with-ecw=/usr/local/ERDAS-ECW_JPEG_2000_SDK-5.4.0/Desktop_Read-Only --with-autoload=/usr/lib/gdalplugins
make
make plugin
sudo make install
sudo ldconfig
- Now test:
gdalinfo --formats | grep -i ECW
With slight adaptation, SDK 5.5 should work fine too. Be aware the you will need to re-do steps 10-20 as you update the GDAL package you have installed in your system.
- You may need to to tell GDAL where your plugins live:
export GDAL_DRIVER_PATH=/usr/lib/gdalplugins
- For use in python you may need to preload libgdal, e.g.:
export LD_PRELOAD=/usr/lib/libgdal.so.27.0.3
Files in src/ were taken from the .DEB: https://launchpad.net/~ubuntugis/+archive/ubuntugis-unstable/+files/libgdal-ecw-src_1.10.0-1~precise4_all.deb (uploaded by Jerome Villeneuve Larouche, 2013-08-21)
Then, the following .cpp and .h files were updated from the official GDAL Github, release/3.7 (2023-07-30; https://github.com/OSGeo/gdal/tree/release/3.7/frmts/ecw):
- ecwasyncreader.cpp
- ecwcreatecopy.cpp
- ecwdataset.cpp
- jp2userbox.cpp
- ecwsdk_headers.h
- gdal_ecw.h
These got me in the right direction:
- https://github.com/OSGeo/gdal/blob/master/MIGRATION_GUIDE.TXT
- http://giswerk.org/doku.php?id=tutorials:softgis:xubuntu:technotes:ecwgdal
- https://adamogrady.id.au/ops/ecw-gdal-ubuntu/
- https://gis.stackexchange.com/questions/94870/unable-to-install-ecw-support-on-lubuntu-14-04
Also, be informed about the new ABI:
- https://trac.osgeo.org/gdal/wiki/ECW#BinaryECWSDKandGCC5.1
- Even Rouault helpful response in [gdal-dev]: https://lists.osgeo.org/pipermail/gdal-dev/2018-May/048478.html
Apparently, since version 4.5 (update 1?) the SDK includes binaries follwing the new C++11 ABI convention
Would rather like to build GDAL from source? Check this post (SDK 5.5, minding the C++11 ABI): https://blog.geomaster.pt/compiling-gdal-with-geopdf-support/