Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python Linker
#1
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

.py   GCC.py (Size: 1.24 KB / Downloads: 52)
Reply
#2
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)
« We can solve any problem by introducing an extra level of indirection »
Reply
#3
(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
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020