Compiling fails: BApplication lib?

OK, this is really a noob question.

I have written a very minimalistic C++ app (for learning how to write Haiku apps). But in the development docu (like the FAQ) I find no instruction how to compile and link a Haiku app. Obviously my g++ envokation is missing a library for BApplication.

In the makefile I envoke:

g++ -o myapp myapp.cpp

(Edit: I tried gcc instead of g++, same problem)

What is missing?

You need to add libbe.so:

g++ -lbe -o myapp myapp.cpp
1 Like

@PeterW : In addition to what @X512 already pointed out, I’d like to recommend using Haiku’s excellent Makefile engine instead of using g++ directly, especially once your programming adventures progress beyond the most simple examples. You’ll find the template Makefile under /boot/system/develop/etc. You can just copy that Makefile into your project, fill in some data about your project (including the libraries it will link against) and after that you can compile your project with a simple “make” command.

As an alternative to that, another build system widely used on Haiku is Jam. It is used to build the OS itself and many (or all?) of the bundled applications.

I prefer Meson:

project('MyApp', 'cpp')

cpp = meson.get_compiler('cpp')
dep_be = cpp.find_library('be')

executable('myapp',
	'myapp.cpp',
	dependencies: [
		dep_be,
	]
)

Makefile engine has a problem that it is suited well only for trivial configurations. It can’t handle well complex configurations with multiple output executables, shared libraries/add-ons, shared code between multiple components.

Jam require you to write a lot of boilerplate code and it is more fragile, so you can easily make mistake that will break multithreaded build.

Fair enough, I can’ t really comment on that. So far it has worked well for my own projects. And I think it is very easy to use for beginners.

Just out of curiosity: Can Meson also handle the Haiku specific stuff like handling rdef files and translation catalogs?

It can be done, but only with custom targets for now. Ideally it should be added as Meson module, but it is not done yet.

1 Like

@BlueSky Good information, I appreciate it. But I think I will stick to my self-made makefile. I’m really on a baby level yet, getting used to the Be/Haiku API.

@X512 I’ve not examined Meson before. Looks kind of interesting.

I’ve also had a look at Scons and CMake, but haven’t decided to use one of them yet.

That’s perfectly OK. It’s good to learn all the basics from ground up.

1 Like