This week, we'll be talking about the Geany IDE. This IDE is one of the tools pre-installed on Raspberry Pi and, among other things, it allows you to write Python and C/C++ code. We'll be looking at how to use our libraries in this IDE and whether it's a good idea to do so.
Let's face it, Geany is very limited. This IDE is closer to a text editor than a true IDE, like Visual Studio, xcode or InteliJ. But, as it comes pre-installed on Raspberry Pi, it enjoys a certain notoriety.
Programming in C++
Geany lets you program in C or C++, but support is very limited. Geany's documentation explains how to write and compile a "Hello world" program, but writing a more complex C++ program isn't truly realistic.
The problem is that Geany has no real build system, merely providing three commands to compile/build and run the program.
Compilation parameters are very limited
This is sufficient to compile a program with just two source files, but if you need to include external libraries or compile dozens of files, it becomes unmanageable. For example, to compile our C++ library, we'd have to include over 100 file names in the compile command, making it unreadable.
To overcome this limitation, the solution is to use an external build system like GNU Make. In this case, Geany launches Make instead of the compiler. Make then generates the compilation and manages dependencies between the various source files. It's a very powerful tool, but can be rather difficult to get to grips with if you're not used to it.
For example, here's a GNU makefile that compiles the main.cpp file with our library. All you need to do is modify the first few lines with the correct path.
# update with the path of the Yoctopuce lib YOCTOPUCE_DIR = /home/yocto/tmp/yoctolib_cpp # update with the name of your app APP_BIN = main #detect the correct version of the Yoctopuce lib ARCH := $(shell uname -m| sed -e s/i.86/i386/ -e s/arm.*/arm/) ifeq ($(ARCH), x86_64) YOCTOPUCE_LIB = ${YOCTOPUCE_DIR}/Binaries/linux/x86_64/libyocto-static.a else ifeq ($(ARCH),i386) YOCTOPUCE_LIB = ${YOCTOPUCE_DIR}/Binaries/linux/i386/libyocto-static.a else ifeq ($(ARCH),aarch64) YOCTOPUCE_LIB = ${YOCTOPUCE_DIR}/Binaries/linux/aarch64/libyocto-static.a else YOCTOPUCE_LIB = ${YOCTOPUCE_DIR}/Binaries/linux/armhf/libyocto-static.a endif YOCTO_API_SRC = ${YOCTOPUCE_DIR}/Sources OPTS_LINK = -lm -lpthread -lusb-1.0 all: $(APP_BIN) $(APP_BIN) : main.cpp $(YOCTOPUCE_LIB) @g++ -o $@ main.cpp -I$(YOCTO_API_SRC) ${YOCTOPUCE_LIB} $(OPTS_LINK) $(YOCTOPUCE_LIB): @echo recompiling Yoctopuce C++ lib $@ @make -C ${YOCTOPUCE_DIR}/Binaries clean: @rm -rf $(APP_BIN) *.o
Once this file has been saved in the same directory as main.cpp, you can compile the application directly from Geany using the "Build"->"Make" command or the keyboard shortcut Shift-F9.
This solution looks more like a hack than a true integration. Geany is therefore not recommended for novice programmers.
If you're looking for a C++ IDE that works under Linux, you'd be better off with Code::Blocks, a real IDE. Incidentally, the C++ examples supplied with the Yoctopuce library include a Code::Blocks project. This allows you to easily recompile and debug our sample programs.
Programming in Python
For Python, Geany is much more interesting because there's no need to compile source files. As indicated in our Python tutorial, you simply need to install the Yoctopuce library manually or using pip. Once you've done this, you can use Geany just like any other Python IDE.
Geany isn't as complete or advanced as PyCharm or Visual Studio Code, but for building a small application on the Raspberry Pi, it's more than enough.
Geany makes more sense for Python projects
Conclusion
Geany is a nice IDE, but very limited. We don't recommend it for C or C++ development, as it lacks a real build system.
However, for Python development, Geany is quite viable. While not on a par with the better-known IDEs, it has the advantage of being preinstalled on Raspberry Pi.