ShadowApex / godot-go

Go language bindings for the Godot Engine's GDNative API.
MIT License
363 stars 31 forks source link

libgodot.so: undefined symbol: godot_rect3_get_shortest_axis_size #28

Closed lstep closed 6 years ago

lstep commented 6 years ago

Using the example (pong.go), made a shorter version, but when trying to run it from Godot, gives the error:

> ERROR: open_dynamic_library: Can't open dynamic library: /Apps/GODOT/3.0/PRJS/grad1/libgodot.so. 
> Error: /Apps/GODOT/3.0/PRJS/grad1/libgodot.so: undefined symbol: godot_rect3_get_shortest_axis_size
>    At: drivers/unix/os_unix.cpp:407.
> ERROR: get_symbol: No valid library handle, can't get symbol from GDNative object
>    At: modules/gdnative/gdnative.cpp:346.
> ERROR: init_library: No godot_nativescript_init in "res://libgodot.so" found
>    At: modules/gdnative/nativescript/nativescript.cpp:1016.

The only difference from the configuration process is that I didn't put the library as a global (as it doesn't seem to exist anymore; see #27 ) The code is used is the following:

package main

import (
    "log"

    "github.com/shadowapex/godot-go/godot"
)

type FooClass struct {
    godot.Node2D
    direction *godot.Vector2
}

func NewFooClass() godot.Class {
    fooClass := &FooClass{
        direction: godot.NewVector2(1.0, 0.0),
    }

    return fooClass
}

func (p *FooClass) X_ready() {
    screenSize := p.GetViewportRect()
    godot.Log.Warning("***Screen size***")
    godot.Log.Warning(screenSize.AsString())
    godot.Log.Warning(p)
    godot.Log.Warning(p.GetOwner())
    godot.Log.Warning(p.GetName())
    godot.Log.Warning(p.GetClass())
}

func init() {
    godot.SetGodotGDNativeInit(func(options *godot.GodotGDNativeInitOptions) {
        log.Println("This is being called from foo.go!")
    })

    godot.Register(NewFooClass)
}

func main() {
}

If I check the library I generated (using latest headers from github) with objdump, I see UND for godot_rect3_get_shortest_axis_size:

$ objdump -x libgodot.so |grep godot_rect3_get_shortest_axis_size
0000000001a01cd0 l     O .data  0000000000000008              github.com/shadowapex/godot-go/godot._cgo_1a4ce146d54f_Cfunc_godot_rect3_get_shortest_axis_size
0000000000754c20 l     F .text  0000000000000087              github.com/shadowapex/godot-go/godot._Cfunc_godot_rect3_get_shortest_axis_size
0000000000000000         *UND*  0000000000000000              godot_rect3_get_shortest_axis_size
0000000000bf3f90 g     F .text  000000000000003a              _cgo_1a4ce146d54f_Cfunc_godot_rect3_get_shortest_axis_size
ShadowApex commented 6 years ago

I just recently regenerated the classes using the latest Godot 3 release and pushed the change, so you might try again.

The godot_rect3_get_shortest_axis_size function should have an implementation in the latest version of Godot. Are you using the master branch of Godot and compiling it yourself with scons?

lstep commented 6 years ago

No, I took the "alpha2" version that was released a few days ago. I will try with the latest version.

lstep commented 6 years ago

Independently from the Godot version, if I do what is written in the README.md file (go build -v -buildmode=c-shared -o libgodot.so example.go), and check with objdump -x, I still get a lot of UNDefined functions (including the one Godot is complaining about):

$ objdump -x libgodot.so |grep godot|grep rect3_get_shortest_axis_size
0000000001a53cd0 l     O .data  0000000000000008              github.com/shadowapex/godot-go/godot._cgo_af8ff18d68cd_Cfunc_godot_rect3_get_shortest_axis_size
0000000000763bd0 l     F .text  0000000000000087              github.com/shadowapex/godot-go/godot._Cfunc_godot_rect3_get_shortest_axis_size
0000000000000000         *UND*  0000000000000000              godot_rect3_get_shortest_axis_size
0000000000c234e0 g     F .text  000000000000003a              _cgo_af8ff18d68cd_Cfunc_godot_rect3_get_shortest_axis_size

All this using the latest versions of Godot (2017-11-02) and your code : I redid a go get -u github.com/shadowapex/godot-go/godot (just to be sure :-), I also took/updated the headers from https://github.com/GodotNativeTools/godot_headers.git in my /usr/local/include directory. I still get Error: Apps/GODOT/projects/grad1/libgodot.so: undefined symbol: godot_rect3_get_shortest_axis_size

ShadowApex commented 6 years ago

Hi @lstep

Those functions will always show as undefined if inspected by itself. The way godot-go works is it includes the Godot headers which just define the function signatures of all the native functions available in Godot, such as godot_rect3_get_shortest_axis_size. When Godot loads the libgodot.so library, it dynamically links the function signatures in godot-go to the actual implementation of the function which exists in the Godot Engine. The reason objdump shows those methods as undefined is because you are inspecting it alone, without being loaded by Godot.

If you inspect libgodot.so by itself, you'll see that pretty much all of the godot functions are undefined:

$ objdump -x libgodot.so | grep godot | grep -v cgo
...
0000000000000000         *UND*  0000000000000000              godot_print
0000000000000000         *UND*  0000000000000000              godot_basis_set_axis
0000000000000000         *UND*  0000000000000000              godot_array_new
0000000000000000         *UND*  0000000000000000              godot_quat_operator_neg
0000000000000000         *UND*  0000000000000000              godot_vector2_angle_to
0000000000000000         *UND*  0000000000000000              godot_variant_new_node_path
0000000000000000         *UND*  0000000000000000              godot_nativescript_register_method
0000000000000000         *UND*  0000000000000000              godot_vector2_normalized
0000000000000000         *UND*  0000000000000000              godot_basis_new_with_axis_and_angle
...

You're getting that error because the version of Godot that you're using doesn't have a definition for godot_rect3_get_shortest_axis_size. If you use the latest version of Godot from Godot's GitHub, and compile it, it should have a definition for rect3 functions.

lstep commented 6 years ago

OK, I recompiled everything from scratch, and it works fine. I get godot.go:51: Initializing Go library. and the debug info I put :+1: Using even the latest nightly from http://godot3builds.digitecnology.com/index.php doesn't work.