Using a C++ library in Godot

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Not_a_Robot
:warning: Old Version Published before Godot 3 was released.

Hello everyone!

I need to use an extensive C++ library in my project and I would like if there is a way to use this library directly in GDScript or how can I approach this easily.

I already checked the modules page in the documentation but I would like to find an easier work around since doing that would be overkill, literally.

I tried to find how to use C++ for the entire application if the previous approach was not possible, but I didn’t find a way to accomplish this without GDScript.

Thanks!

:bust_in_silhouette: Reply From: vnen

If you want to use a C++ library you need to make a C++ module to make a bridge with the engine (create new nodes, expose API to GDScript, etc.). I can’t see how that’s overkill.

Making a module is quite easy. You’ll likely have more trouble compiling the library with SCons for multiple platforms.

Well, the library is huge, it will be a lot of hardwork.

Thank you four your answer :slight_smile:

Not_a_Robot | 2016-08-15 12:02

If it’s huge, you should ask yourself if you really need it. Also, the bridge doesn’t need to have all of the interface if you’re not using everything. Maybe a couple of nodes might be all that is needed to encompass a lot of the lib’s functionality.

(I wonder why my answer got downvoted. It’d be nice to leave a comment saying why this answer is not good, so I can improve it).

vnen | 2016-08-15 14:42

Is there an (prototypical) example in the sources or some good place to look into for this?

Martin Eigel | 2016-08-15 19:58

Besides the documentation on making modules you can check some other modules as references such as the ones listed here or here.

vnen | 2016-08-15 20:14

vnen, I don’t know why but I expected a «ask yourself if you really need it.» comment haha :slight_smile:

Yeah, I really need that library. I wish I could use C++ without GDScript because that would make my life easier I think.

I’ll try to make that library as a module then, although you scared me talking about SCons (never heard of this before), because the game is going to be published for Android phones.

I’ll take a look at those examples you share, thank you very much!

(btw, I have no idea about the downvote, I selected your answer as the best, so…)

Not_a_Robot | 2016-08-15 20:25