godotengine / godotengine/godot-docs

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

Open
#7,284 0 comments 0 reactions 0 assignees View on GitHub
area:manual bug
Dominant language
reStructuredText
Stars
5.7k
Forks
3.8k
Avg merge
1d 20h
Merged PRs (30d)
25

Description

**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
Date: Tue Apr 4 11:30:08 2023 +0200

Merge pull request #1045 from zhehangd/fix_ref_crash

Fix crash using Ref 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

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.