Skip to content

Commit

Permalink
Inject a dummy source file with a reference to main
Browse files Browse the repository at this point in the history
This fixes possible "Slink-Warning-No definition of area SSEG" error.
  • Loading branch information
valeros committed Mar 23, 2021
1 parent 39453a6 commit acb8a45
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions builder/frameworks/arduino.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,19 @@
FRAMEWORK_DIR = platform.get_package_dir("framework-arduinoststm8")
assert os.path.isdir(FRAMEWORK_DIR)


def inject_dummy_reference_to_main():
build_dir = env.subst("$BUILD_DIR")
dummy_file = os.path.join(build_dir, "_pio_main_ref.c")
if not os.path.isfile(dummy_file):
if not os.path.isdir(build_dir):
os.makedirs(build_dir)
with open(dummy_file, "w") as fp:
fp.write("void main(void);void (*dummy_variable) () = main;")

env.Append(PIOBUILDFILES=dummy_file)


env.Append(
CCFLAGS=[
"--less-pedantic"
Expand Down Expand Up @@ -63,6 +76,11 @@
]
)

# Fixes possible issue with "ASlink-Warning-No definition of area SSEG" error.
# This message means that main.c is not pulled in by the linker because there was no
# reference to main() anywhere. Details: https://tenbaht.github.io/sduino/usage/faq/
inject_dummy_reference_to_main()

# By default PlatformIO generates "main.cpp" for the Arduino framework.
# But Sduino doesn't support C++ sources. Exit if a file with a C++
# extension is detected.
Expand Down

0 comments on commit acb8a45

Please sign in to comment.