Skip to content

Instantly share code, notes, and snippets.

@Karsten1987
Last active March 23, 2021 22:14
Show Gist options
  • Select an option

  • Save Karsten1987/577bb444062ec5a5870ce5ff8a3a5c34 to your computer and use it in GitHub Desktop.

Select an option

Save Karsten1987/577bb444062ec5a5870ce5ff8a3a5c34 to your computer and use it in GitHub Desktop.
setup ROS2 dev machine OSX

fix pyenv for python > 3.7

pyenv/pyenv#544 (comment)

compile VIM from source

run autoconf in src folder

./configure --with-features=huge --prefix=`pwd`/build --enable-python3interp=yes --with-python3-config-dir=/Users/karsten/.pyenv/versions/3.7.4/lib/python3.7/config-3.7m-darwin/

compile QT with from source

taken from ros2/ros2#623 (comment)

wget https://sourceforge.net/projects/pyqt/files/sip/sip-4.19.13/sip-4.19.13.tar.gz
wget https://sourceforge.net/projects/pyqt/files/PyQt5/PyQt-5.11.3/PyQt5_gpl-5.11.3.tar.gz

install SIP first

tar xzf sip-4.19.13.tar.gz
cd sip-4.19.13
python ./configure.py
make
make install

install pyqt

tar xzf PyQt5_gpl-5.11.3.tar.gz
cd PyQt5_gpl-5.11.3
python ./configure.py --sip /Users/karsten/.pyenv/versions/3.7.0/Python.framework/Versions/3.7/bin/sip  # <-- This has to point to your sip install location
make -j4
make install

fix ubuntu machine in Parallels

kernel 4.15 (default in ubuntu 18.04) not suppported in v12. downgrade to kernel 4.14 and fix long booting sequence by installing rng-tools debug with dmesg and check the jump in time

install llvm/clang from homebrew with ccache

set llvm-clang as default

export PATH="/usr/local/opt/llvm/bin:$PATH"
export CC="clang"
export CXX="$CC++"
#export AR="llvm-ar"
#export LD="llvm-ld"
#export LDFLAGS="-L/usr/local/opt/llvm/lib -Wl,-rpath,/usr/local/opt/llvm/lib"
#export CPPFLAGS="-I/usr/local/opt/llvm/include"
# CMAKE_CXX_FLAGS can then be enhanced with `-fsanitize=address` to detect leaks
=================================================================
==48264==ERROR: AddressSanitizer: heap-use-after-free on address 0x602000000130 at pc 0x00010dec1045 bp 0x7ffee1d40510 sp 0x7ffee1d40508
READ of size 4 at 0x602000000130 thread T0
    #0 0x10dec1044 in main+0x754 (foo:x86_64+0x100002044)
    #1 0x7fff73fe53d4 in start+0x0 (libdyld.dylib:x86_64+0x163d4)

0x602000000130 is located 0 bytes inside of 4-byte region [0x602000000130,0x602000000134)
freed by thread T0 here:
    #0 0x10dfddf06 in wrap_free+0xa6 (libclang_rt.asan_osx_dynamic.dylib:x86_64+0x43f06)
    #1 0x10dec0ff0 in main+0x700 (foo:x86_64+0x100001ff0)
    #2 0x7fff73fe53d4 in start+0x0 (libdyld.dylib:x86_64+0x163d4)

previously allocated by thread T0 here:
    #0 0x10dfdddbd in wrap_malloc+0x9d (libclang_rt.asan_osx_dynamic.dylib:x86_64+0x43dbd)
    #1 0x10df24679 in operator new(unsigned long)+0x19 (libc++.1.dylib:x86_64+0x54679)
    #2 0x10dec0f6f in main+0x67f (foo:x86_64+0x100001f6f)
    #3 0x7fff73fe53d4 in start+0x0 (libdyld.dylib:x86_64+0x163d4)

SUMMARY: AddressSanitizer: heap-use-after-free (foo:x86_64+0x100002044) in main+0x754
Shadow bytes around the buggy address:
  0x1c03ffffffd0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x1c03ffffffe0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x1c03fffffff0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x1c0400000000: fa fa fd fd fa fa fd fd fa fa 00 00 fa fa 00 07
  0x1c0400000010: fa fa 00 06 fa fa 00 04 fa fa 00 00 fa fa 00 06
=>0x1c0400000020: fa fa 04 fa fa fa[fd]fa fa fa fa fa fa fa fa fa
  0x1c0400000030: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x1c0400000040: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x1c0400000050: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x1c0400000060: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x1c0400000070: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
  Shadow gap:              cc
==48264==ABORTING
Abort trap: 6

set ccache to search for llvm-lang

export PATH="/usr/local/opt/ccache/libexec:$PATH"

install Intel Hypervisor kernel module

https://github.com/intel/haxm/blob/master/docs/manual-macos.md

compile crosstool-ng

there's a problem with having ncurses installed via homebrew. Add the libs and include paths to LDFLAGS/CXXFLAGS before the configure step For python problems on gdb, see https://stackoverflow.com/a/11600411/4583130

Once the configuration is built correctly (use samples and modify them for the correct version), the folder layout looks as follows:

 ➭ ll ~/workspace/toolchains/x86_64/gcc-7.5/x86_64-unknown-linux-gnu
total 4096
dr-xr-xr-x   9 karsten  staff      288 Oct 16 00:54 ./
drwxr-xr-x   5 karsten  staff      160 Oct 19 11:49 ../
dr-xr-xr-x  37 karsten  staff     1184 Oct 16 00:53 bin/
-r--r--r--   1 karsten  staff  2095985 Oct 16 00:53 build.log.bz2
dr-xr-xr-x   2 karsten  staff       64 Oct 16 00:49 include/
dr-xr-xr-x   7 karsten  staff      224 Oct 16 00:49 lib/
dr-xr-xr-x   3 karsten  staff       96 Oct 16 00:49 libexec/
dr-xr-xr-x   5 karsten  staff      160 Oct 16 00:53 share/
dr-xr-xr-x   8 karsten  staff      256 Oct 16 00:49 x86_64-unknown-linux-gnu/

cross compile with clang

one does not have to cross-compile with a special created gcc compiler. Clang itself (the one on the host platoform) is by defualt a cross compiler. once the toolchain is created with clang, it requires two arguments set, i.e. sysroot and gcc-toolchain.

[ 50%] Building CXX object CMakeFiles/karsten_hello_world.dir/main.cpp.o
/usr/local/opt/ccache/libexec/clang++ --target=x86_64-unknown-linux-gnu --sysroot=/Users/karsten/workspace/toolchains/x86_64/gcc-7.5/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/sysroot   --gcc-toolchain=/Users/karsten/workspace/toolchains/x86_64/gcc-7.5/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/sysroot/../.. -o CMakeFiles/karsten_hello_world.dir/main.cpp.o -c /Users/karsten/workspace/ctrlx/snap_ws/ctrlx_hello_world/main.cpp
[100%] Linking CXX executable karsten_hello_world
/usr/local/Cellar/cmake/3.18.4/bin/cmake -E cmake_link_script CMakeFiles/karsten_hello_world.dir/link.txt --verbose=1
/usr/local/opt/ccache/libexec/clang++ --target=x86_64-unknown-linux-gnu --sysroot=/Users/karsten/workspace/toolchains/x86_64/gcc-7.5/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/sysroot --gcc-toolchain=/Users/karsten/workspace/toolchains/x86_64/gcc-7.5/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/sysroot/../.. -L/usr/local/opt/llvm/lib -Wl,-rpath,/usr/local/opt/llvm/lib -fuse-ld=lld CMakeFiles/karsten_hello_world.dir/main.cpp.o -o karsten_hello_world
[100%] Built target karsten_hello_world
/usr/local/Cellar/cmake/3.18.4/bin/cmake -E cmake_progress_start /Users/karsten/workspace/ctrlx/snap_ws/ctrlx_hello_world/build/CMakeFiles 0

The equivalent cmake toolchain file:

set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR x86_64)

set(CMAKE_SYSROOT /Users/karsten/workspace/toolchains/x86_64/gcc-7.5/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/sysroot)
set(CMAKE_CXX_FLAGS_INIT "--gcc-toolchain=${CMAKE_SYSROOT}/../..")
set(CMAKE_C_FLAGS_INIT "--gcc-toolchain=${CMAKE_SYSROOT}/../..")

set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

set(triple x86_64-unknown-linux-gnu)

set(CMAKE_C_COMPILER clang)
set(CMAKE_C_COMPILER_TARGET ${triple})
set(CMAKE_CXX_COMPILER clang++)
set(CMAKE_CXX_COMPILER_TARGET ${triple})

Use Docker with Tap device

Follow install instructions here: https://github.com/AlmirKadric-Published/docker-tuntap-osx

brew tap caskroom/cask
brew cask install tuntap

in case tap1 device does not exist: AlmirKadric-Published/docker-tuntap-osx#25 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment