fix: revert to C++11 for binary symbol compatibility and implement custom make_unique for ofxPiMapper

This commit is contained in:
Timothy Hofland
2026-03-13 20:13:41 +01:00
parent 1c034f1e89
commit 5770be2b8b

View File

@ -260,31 +260,42 @@ EOF_PATCH
fi fi
# 2. Fix unique_ptr and missing memory headers globally (Idempotent) # 2. Fix unique_ptr and missing memory headers globally (Idempotent)
echo "Fixing namespaces and missing headers..." echo "Fixing namespaces and missing headers for C++11 compatibility..."
# First, clean up any previous double-patching bugs # First, clean up any previous double-patching bugs
find src -type f \( -name "*.h" -o -name "*.cpp" \) -exec sed -i 's/std::std::/std::/g' {} + find src -type f \( -name "*.h" -o -name "*.cpp" \) -exec sed -i 's/std::std::/std::/g' {} +
# Apply patch only if not already namespaced # Apply patch only if not already namespaced
find src -type f \( -name "*.h" -o -name "*.cpp" \) -exec sed -i 's/\([^:a-zA-Z0-9]\)unique_ptr\b/\1std::unique_ptr/g' {} + find src -type f \( -name "*.h" -o -name "*.cpp" \) -exec sed -i 's/\([^:a-zA-Z0-9]\)unique_ptr\b/\1std::unique_ptr/g' {} +
find src -type f \( -name "*.h" -o -name "*.cpp" \) -exec sed -i 's/\([^:a-zA-Z0-9]\)make_unique\b/\1std::make_unique/g' {} +
# Add headers only if not present # Custom make_unique for C++11 compatibility
cat <<'EOF_MAKE_UNIQUE' > /tmp/make_unique.patch
#if __cplusplus < 201402L
namespace std {
template<typename T, typename... Args>
unique_ptr<T> make_unique(Args&&... args) {
return unique_ptr<T>(new T(std::forward<Args>(args)...));
}
}
#endif
EOF_MAKE_UNIQUE
for f in $(find src -type f -name "*.h"); do for f in $(find src -type f -name "*.h"); do
grep -q "<memory>" "$f" || sed -i '1i #include <memory>' "$f" grep -q "<memory>" "$f" || sed -i '1i #include <memory>' "$f"
if ! grep -q "make_unique" "$f"; then
cat /tmp/make_unique.patch >> "$f"
fi
done done
for f in $(find src -type f -name "*.cpp"); do rm -f /tmp/make_unique.patch
grep -q "<algorithm>" "$f" || sed -i '1i #include <algorithm>' "$f"
done
# Build Example # Build Example (Force C++11 for binary symbol compatibility with OF core)
cd "$REAL_HOME/openFrameworks/addons/ofxPiMapper/example_basic" cd "$REAL_HOME/openFrameworks/addons/ofxPiMapper/example_basic"
echo "Cleaning old objects to ensure consistent symbol generation..." echo "Cleaning old objects..."
sudo -u "$REAL_USER" make clean sudo -u "$REAL_USER" make clean
echo "Starting compilation (Global Flags)..." echo "Starting compilation (Forcing C++11 for Symbol Compatibility)..."
# Using PLATFORM_CFLAGS ensures these flags propagate to the addon source as well # Revert to C++11 to match the pre-compiled OF core library symbols
GLOBAL_FLAGS="-Wno-error -Wno-reorder -Wno-sign-compare -Wno-delete-non-virtual-dtor -std=c++17" GLOBAL_FLAGS="-Wno-error -std=c++11"
sudo -u "$REAL_USER" make -j1 PLATFORM_CFLAGS="$GLOBAL_FLAGS" USER_CFLAGS="$GLOBAL_FLAGS" USER_CPPFLAGS="-std=c++17" sudo -u "$REAL_USER" make -j1 PLATFORM_CFLAGS="$GLOBAL_FLAGS" USER_CFLAGS="$GLOBAL_FLAGS" USER_CPPFLAGS="-std=c++11"
cp bin/example_basic /usr/local/bin/ofxPiMapper cp bin/example_basic /usr/local/bin/ofxPiMapper
chmod +x /usr/local/bin/ofxPiMapper chmod +x /usr/local/bin/ofxPiMapper