Skip to content

Instantly share code, notes, and snippets.

@minlexx
Created January 7, 2019 15:16
Show Gist options
  • Save minlexx/c8e2d1cfea69da0799ca763550c0ed17 to your computer and use it in GitHub Desktop.
Save minlexx/c8e2d1cfea69da0799ca763550c0ed17 to your computer and use it in GitHub Desktop.
#!/usr/bin/python3
# First, find what real compiler is called, symlink destination: ls -l /usr/bin/armv7hl-unknown-linux-gnueabi-gcc
# /usr/bin/armv7hl-unknown-linux-gnueabi-gcc: symbolic link to \
# /usr/x86_64-pc-linux-gnu/armv7hl-unknown-linux-gnueabi/gcc-bin/7.3.0/armv7hl-unknown-linux-gnueabi-gcc
# So, we go and replace "/usr/bin/armv7hl-unknown-linux-gnueabi-gcc" with this script and make it executable.
# Then when this script is called instead of a real compiler, it would replace all parameters '-L/usr/lib64'
# to correct ones: '-L/usr/armv7hl-unknown-linux-gnueabi-gcc/lib' to prevent linking to wrong libs from host.
import sys
import os
import subprocess
orig_gcc = '/usr/x86_64-pc-linux-gnu/armv7hl-unknown-linux-gnueabi/gcc-bin/7.3.0/armv7hl-unknown-linux-gnueabi-gcc'
new_argv = []
# Go through all commandl-line arguments and copy them to new array, replacing incorrect ones
for arg in sys.argv:
if arg == '-L/usr/lib64':
arg = '-L/usr/armv7hl-unknown-linux-gnueabi-gcc/lib'
new_argv.append(arg)
# First item in argv is always a name of an executable, so replace it with real executable name
new_argv[0] = orig_gcc
# Call original compiler with new set of parameters
sys.exit(subprocess.call(new_argv))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment