I converted some Audio C++ libraries into Arduino Libraries and used symlinks which point to the original file locations to make sure that Arduino can find all relevant files. This approach was working fine in OSX and Linux. Unfortunately this seems to create problems in Windows, so I decided to change the approach a little bit and replace the symlinks just with regular files that contain a regular #include.

To convert all files manually would have been too tedious, so I used the following simple Python program.

import os
from pathlib import Path

def prefix(path):
    n = path.count("/")
    if n==1:
        return "../"
    if n==2:
        return "../../"
    if n==3:
        return "../../../"
    if n==4:
        return "../../../../"

def replace(path, newPath):
    # delete file
    os.unlink(path)
    # create new file
    content = "#pragma once\n// link to original location\n#include \""+prefix(path)+newPath+"\"\n\n"
    with open(path, "w") as text_file:
        text_file.write(content)

working_dir = os.getcwd()+"/"
for path, currentDirectory, files in os.walk("src"):
    for file in files:
        p = os.path.join(path, file);
        if (Path(p).is_symlink()):
            linkedPath = str(os.path.realpath(p)).replace(working_dir,"")
            print(p + " ->" + linkedPath);
            replace(p, linkedPath)
Categories: Arduino

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *