Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

godot-cpp SConstruct cpp/linker visibility flags should be default 'hidden' + dynlib #7284

Open
jpedrick opened this issue May 5, 2023 · 0 comments
Labels
area:manual Issues and PRs related to the Manual/Tutorials section of the documentation bug

Comments

@jpedrick
Copy link

jpedrick commented May 5, 2023

Your Godot version:
N/A issue is with current tutorial

godot-cpp % git show
commit feaba551b5a5b2d13ad1c3fdd8c90e67c67ff37c (HEAD -> master, origin/master, origin/HEAD)
Merge: e9942db 517db66
Author: Rémi Verschelde <rverschelde@gmail.com>
Date:   Tue Apr 4 11:30:08 2023 +0200

    Merge pull request #1045 from zhehangd/fix_ref_crash
    
    Fix crash using Ref<T> as parameter

Issue description:

The library should have everything except the entry_symbol hidden. See Apple's guidelines: https://developer.apple.com/library/archive/documentation/DeveloperTools/Conceptual/DynamicLibraries/100-Articles/DynamicLibraryDesignGuidelines.html

This became an issue for me while working on a fix for godotengine/godot#66231 , as the library reload would immediately cause a crash. After setting the visibility, the library could load, though it seems there is still much work to be done for dynamic reloading of dynamic gdextension libraries within godot itself.

This can be fixed in a platform independent way by default in godot-cpp/SConstruct, since that is used to initialize env

On my build I view the exported symbols: nm -gm demo/bin/libgdexample.macos.editor.framework/libgdexample.macos.editor

provided SConstruct:

#!/usr/bin/env python
import os
import sys

env = SConscript("godot-cpp/SConstruct")

# For reference:
# - CCFLAGS are compilation flags shared between C and C++
# - CFLAGS are for C-specific compilation flags
# - CXXFLAGS are for C++-specific compilation flags
# - CPPFLAGS are for pre-processor flags
# - CPPDEFINES are for pre-processor defines
# - LINKFLAGS are for linking flags

# tweak this if you want to use different folders, or more folders, to store your source code in.
env.Append(CPPPATH=["src/"])
sources = Glob("src/*.cpp")

if env["platform"] == "macos":
    library = env.SharedLibrary(
        "demo/bin/libgdexample.{}.{}.framework/libgdexample.{}.{}".format(
            env["platform"], env["target"], env["platform"], env["target"]
        ),
        source=sources,
    )
else:
    library = env.SharedLibrary(
        "demo/bin/libgdexample{}{}".format(env["suffix"], env["SHLIBSUFFIX"]),
        source=sources,
    )

Default(library)

Good Sconstruct(macos+clang):

#!/usr/bin/env python
import os
import sys

env = SConscript("godot-cpp/SConstruct")

# For reference:
# - CCFLAGS are compilation flags shared between C and C++
# - CFLAGS are for C-specific compilation flags
# - CXXFLAGS are for C++-specific compilation flags
# - CPPFLAGS are for pre-processor flags
# - CPPDEFINES are for pre-processor defines
# - LINKFLAGS are for linking flags

# tweak this if you want to use different folders, or more folders, to store your source code in.
env.Append(CPPPATH=["src/"])
env.Append(CXXFLAGS=["-fvisibility=hidden"])
env.Append(LINKFLAGS=["-dynamiclib","-fvisibility=hidden"])

sources = Glob("src/*.cpp")

if env["platform"] == "macos":
    library = env.SharedLibrary(
        "demo/bin/libgdexample.{}.{}.framework/libgdexample.{}.{}".format(
            env["platform"], env["target"], env["platform"], env["target"]
        ),
        source=sources,
    )
else:
    library = env.SharedLibrary(
        "demo/bin/libgdexample{}{}".format(env["suffix"], env["SHLIBSUFFIX"]),
        source=sources,
    )

Default(library)

URL to the documentation page:

https://docs.godotengine.org/en/stable/tutorials/scripting/gdextension/gdextension_cpp_example.html

@jpedrick jpedrick added the bug label May 5, 2023
@jpedrick jpedrick changed the title godot-cpp SConstruct linker visibility flags godot-cpp SConstruct cpp/linker visibility flags should be default 'hidden' + dynlib May 5, 2023
@Piralein Piralein added the area:manual Issues and PRs related to the Manual/Tutorials section of the documentation label May 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:manual Issues and PRs related to the Manual/Tutorials section of the documentation bug
Projects
None yet
Development

No branches or pull requests

2 participants