diff --git a/scripts/setup.sh b/scripts/setup.sh index 13dfe70..c698be4 100644 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -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 + unique_ptr make_unique(Args&&... args) { + return unique_ptr(new T(std::forward(args)...)); + } +} +#endif +EOF_MAKE_UNIQUE + for f in $(find src -type f -name "*.h"); do grep -q "" "$f" || sed -i '1i #include ' "$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 "" "$f" || sed -i '1i #include ' "$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