fix: revert to C++11 for binary symbol compatibility and implement custom make_unique for ofxPiMapper
This commit is contained in:
@ -260,31 +260,42 @@ EOF_PATCH
|
||||
fi
|
||||
|
||||
# 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
|
||||
find src -type f \( -name "*.h" -o -name "*.cpp" \) -exec sed -i 's/std::std::/std::/g' {} +
|
||||
|
||||
# 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]\)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
|
||||
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
|
||||
for f in $(find src -type f -name "*.cpp"); do
|
||||
grep -q "<algorithm>" "$f" || sed -i '1i #include <algorithm>' "$f"
|
||||
done
|
||||
rm -f /tmp/make_unique.patch
|
||||
|
||||
# Build Example
|
||||
# Build Example (Force C++11 for binary symbol compatibility with OF core)
|
||||
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
|
||||
|
||||
echo "Starting compilation (Global Flags)..."
|
||||
# Using PLATFORM_CFLAGS ensures these flags propagate to the addon source as well
|
||||
GLOBAL_FLAGS="-Wno-error -Wno-reorder -Wno-sign-compare -Wno-delete-non-virtual-dtor -std=c++17"
|
||||
sudo -u "$REAL_USER" make -j1 PLATFORM_CFLAGS="$GLOBAL_FLAGS" USER_CFLAGS="$GLOBAL_FLAGS" USER_CPPFLAGS="-std=c++17"
|
||||
echo "Starting compilation (Forcing C++11 for Symbol Compatibility)..."
|
||||
# Revert to C++11 to match the pre-compiled OF core library symbols
|
||||
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++11"
|
||||
cp bin/example_basic /usr/local/bin/ofxPiMapper
|
||||
chmod +x /usr/local/bin/ofxPiMapper
|
||||
|
||||
|
||||
Reference in New Issue
Block a user