Python Forum

Full Version: Python Linker
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello everyone,

I'm currently writing a Python script that can read C files from a directory and use GCC to compile them, placing the resulting file in a specified directory. I have attached a .py file showcasing my implementation. However, I am encountering an issue where the header files are not being automatically included, resulting in repeated errors throughout the C files.

For example: D:..\Core\Src\system_stm32f1xx.c:58:10: fatal error: stm32f1xx.h: No such file or directory
58 | #include "stm32f1xx.h"
| ^~~~~~~~~~~~~
Could anyone please help me resolve this issue?

Thank you in advance!


here is the code
[attachment=3214]
You could perhaps compile each C file with its own directory as working directory, for example
# Compile each C file into an object file
object_files = []
for source_file in source_files:
    source_dir, name = os.path.split(source_file)
    object_file = os.path.join(output_dir, name.replace('.c', '.o'))
    subprocess.run(["gcc", "-c", name, "-o", object_file], cwd=source_dir)
    object_files.append(object_file)
(Feb-15-2025, 03:12 PM)Gribouillis Wrote: [ -> ]You could perhaps compile each C file with its own directory as working directory, for example
# Compile each C file into an object file
object_files = []
for source_file in source_files:
    source_dir, name = os.path.split(source_file)
    object_file = os.path.join(output_dir, name.replace('.c', '.o'))
    subprocess.run(["gcc", "-c", name, "-o", object_file], cwd=source_dir)
    object_files.append(object_file)

oh thanks but i did it , i will share the code on git hub ,thank for help