OTB development on Windows With Eclipse
- 1 Things you need to download
- 2 Installing Tools
- 3 Generate an Eclipse Project with CMake
- 4 Import OTB project into Eclipse IDE
- 5 Some tips on building inside Eclipse
- 6 Build running inside Eclipse
- 7 Build finished, Launch an OTB application
- 8 What about...
- 9 Any other issues or questions ?
Things you need to download
In this wiki article I use 32bit version of MinGW and OTB xdk archive. If you are want to build OTB 64bit, please download the correct files from the below table.
|Name||Version||Download Link||Notes||Last Retrieved On|
|32 bit||64 bit|
|Ninja||1.6.0||ninja-win.zip||Same for Windows 32bit and 64bit||27-February-2017 06:54|
|CMake||3.5.2||cmake-3.4.0-rc1-win32-x86.zip||Same for Windows 32bit and 64bit||27-February-2017 06:54|
|7Zip Tool||15.09 beta||7-zip.org||Same for Windows 32bit and 64bit||27-February-2017 06:54|
|OTB Source||5.4.0||OTB-5.4.0.zip||Same for Windows 32bit and 64bit||27-February-2017 06:54|
|Eclipse IDE (C++)||4.5 (Mars)||eclipse.org/downloads||Must be higher than 3.5 (Helios)||27-February-2017 06:54|
|MinGW||GCC 4.9.3||i686-4.9.3-release-win32-sjlj-rt_v4-rev1.7z||x86_64-4.9.3-release-win32-seh-rt_v4-rev1.7z||sjlj win32-threads||27-February-2017 06:54|
|OTB XDK||5.4.0||OTB-5.4.0-xdk-win32.zip||OTB-5.4.0-xdk-win64.zip||This archive contains development files for all external dependencies used by OTB. (updated on every release)||27-February-2017 06:54|
Save 7z1509.exe, eclipse-inst-win64.exe, x86_64-4.9.3-release-win32-seh-rt_v4-rev1.7z, cmake-3.5.2-win32-x86.zip ninja-win.zip, OTB-5.4.0-xdk-win64.zip and OTB-5.4.0.zip to C:\Download\
So there can be a day where the download links in the above table gives 404 error or something bizzare. Even though the chances are very less, it happens like always. So I will update the Last Retrieved On column from time to time. If you find it before us, Please let us know through otb-developers list.
First install 7zip, Eclipse and comeback. I won't be giving any detail on how to install these two tools. Because of two reasons:
A) It is a straightforward installation and will be boring to include them here.
B) There is more chance that you are having 7zip and maybe eclipse before you land on this page.
C) The version of these tools have no or little effect on the build steps listed below.
I know that second point can be true in case of other such as mingw, cmake, ninja. But I thought to include them because I referring to their path and all below.
Tools are downloaded?
Here is a snapshot of my C:\Download directory
Some useful directories
Create below listed directories where you are going to install and extract tools and sources.
I prefer to have MinGW tool chain rather than Visual Studio 2012 or higher. It is not because that MSVC compilers are bad. They are so bad that I don't bother writing this wiki page in the first place. This is a personal opinion by the author. If you are a fan of visual studio, Please don't write a lengthy mail to me. The mail will not be worth the effort.
- Extract x86_64-4.9.3-release-win32-seh-rt_v4-rev1.7z with 7zip to C:\mingw64
Right Click -> Extract files...
- Add C:\mingw64\bin to Path environment variable.
Note: Adding environment variables in windows are same every time. I safely assume you know the drill.
Right click System -> Properties -> Advanced Parameters (Tab) --> Click on Environment Variables.
- Extract cmake-3.5.2-win32-x86.zip to C:\DevTools\CMake
- Add C:\DevTools\CMake\bin to Path environment variable
We prefer ninja instead of existing nmake, mingw32-make, msys make etc.. The github description of ninja says "a small build system with a focus on speed". This description along with our own experience with ninja was convincing enough.
- Extract ninja-win.zip to C:\DevTools\
This contains development files for all libraries used by OTB, Ice and Monteverdi. The XDK stands for external dependencies kit. I called it SDK (Software Development Kit) at first and changed it to XDK!.
The files in XDK are generated by cross compilation process on a Fedora Linux 21. All hail mxe(M cross environment)!. It provides a nice cross compiling environment for various target platforms which is designed to run on any Unix system. We won't be able to make this without them.
XDK is generated for each release. You can get latest version from packages/xdk.
- Extract OTB-5.4.0-xdk-win64.zip to C:\DevTools\OTB-xdk-win64
Below is a snapshot of C:\DevTools\OTB\OTB-xdk-win64 directory.
When extracting XDK archive, Windows unzip tool has a tendency to save it to C:\DevTools\OTB-5.4.0-xdk-win64\OTB-5.4.0-xdk-win64. Such case should not happen.
So after extracting archive, C:\DevTools\OTB-xdk-win64 should look similar to the below snapshot.
- Add C:\DevTools\OTB-xdk-win64\bin to Path environment variable
The below table shows list of libraries in the XDK. You can see the full mxe sources on my github fork https://github.com/rashadkm/mxe/. I keep this fork so that every single change in MXE upstream won't break my build and also yours. But I also sync with upstream, provide some PRs back once I confirm the changes in package versions and all does not break OTB build. So I would say that safety assured.
|GDAL||2.0.1||with openjpeg driver, external tiff, geotiff|
- Extract OTB-5.4.0.zip to C:\projects\OTB.
It is important to put a snapshot showing the contents of this directory to avoid any confusion.
Generate an Eclipse Project with CMake
open the cmake-gui.exe program. If you have followed the cmake installation given in this wiki page. You can find this executable in C:\DevTools\CMake\bin\ directory.
This is why I mentioned the installation of the cmake in the above step!. If you already had one installed. Please feel free to use that
Fill in the values for source and binaries directory
Where is the source code: C:/projects/OTB Where to build the binaries: C:/projects/OTB.build
Click on Configure
Choose cmake generator and compiler
- Select Eclipse CDT4 - Ninja for generator and click on Specify native compilers
- Fill in the location of C and C++ compiler. It will be C:/mingw64/bin/gcc.exe and C:/mingw64/bin/g++.exe respectively.
First error occurred!
Now you might have got an error as shown in the below snapshot. This is bound to happen but luckily we have a fix!.
The reason behind this is cmake needs to know the where the ninja.exe as we selected the Eclipse CDT4 - Ninja generator in the previous step.
To fix it simply fill in the location of ninja.exe for CMAKE_MAKE_PROGRAM.
Next step is to add a cmake variable (CMAKE_PREFIX_PATH) that helps us to automatically detect the all external dependencies.
This the part where xdk comes in play. See the below snapshot in action.
Now cmake will check your for all libraries (GDAL, ITK, OSSIM, MuParser ..) and configure your project.
After this is finished, your cmake-gui will looks like the below snapshot.
Now you will be very much tempted to click on Generate if you are used to cmake. But don't do it right away.
There is two more step to be done. But If you had clicked on generate already, that is not a problem. You need to do it again.
By default, all OTB_USE_* variables in OTB are unchecked except for 6S and SiftFast. This is discussed in otb-developers thread in May 2015.
You can check/activate them in your cmake-gui. See below snapshot for reference. I had activated all possible options now.
Below cmake options must be deactivated!
OTB_WRAP_PYTHON (untested. If you have python installed on your system. You can test this. But let us know if that works!) OTB_WRAP_JAVA (same reason as python) OTB_USE_OPENJPEG (must be OFF. openjpeg is processed via gdal openjpeg driver. The XDK version of gdal has this driver enabled) OTB_USE_LIBKML (development files not distributed with XDK) OTB_USE_MAPNIK (development files not distributed with XDK)
After this you click on Generate to create your OTB Eclipse project!
Import OTB project into Eclipse IDE
Importing the OTB project from C:\projects\OTB.build to Eclipse IDE is straightforward. Below are the snapshots in right order. Follow my lead..
Disable Indexer tool in Eclipse (optional)
Open up Eclipse IDE. Before importing the project, you might want to turn off C++ Indexer tool in Eclipse.
I find running Eclipse C++ Indexer on every source file in the project as a time consuming process. You can enable it later if you find the need.
Eclipse Menu: Window -> Preferences From the left panel, Select C/C++ -> Indexer and Uncheck Enable Indexer
Import project into Workspace
Eclipse Menu: File -> Import -> Existing Projects into Workspace
Fill in C:\projects\OTB.build for Select root directory option
Click on finish and you are ready to start building OTB!
Some tips on building inside Eclipse
Under the Project Explorer panel in Eclipse IDE you can find all available targets.
To kick-off OTB build, you can use keyboard shortcut Ctrl+B Or using menu Projects -> Build Project
To build a specific target, say otbApplicationLauncherCommandLine
Right Click on: [Targets] -> [exe] otbApplicationLauncherCommandLine -> Make Targets and select Build
From here onwards everything is on Eclipse IDE. You can make changes to cmakefiles, source code and eclipse will re-run cmake automatically if required.
Build running inside Eclipse
It won't be fun, If I didn't add a snapshot of OTB build running inside Eclipse.
Build finished, Launch an OTB application
Here is the ortho rectification application in OTB launched from Eclipse.
Writing my <awesome> application/remote module on Windows
Steps are more or less the same.
Please do so and let us know your feedback/comments/suggestions via otb-developers group!
Another IDE ?
Okay. Eclipse is not the only possible IDE on Windows. CMake support other such as CodeBlocks, KDevelop, Emacs, Vim and several others.
OTB is not at all strict on your selected IDE. Infact, like any other projects OTB does not care if you choose another.
There is however a limitation on the list of IDEs supported by CMake. So if you prefer some other IDE there is no stopping you...
If you do so, certainly not forgot to share your experience with us via otb-developers
Any other issues or questions ?
Please write a mail describing your problem to otb-developers