fix: use a single compatibility header for make_unique to prevent redefinition errors
This commit is contained in:
@ -261,31 +261,36 @@ 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 for C++11 compatibility..."
|
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' {} +
|
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]\)unique_ptr\b/\1std::unique_ptr/g' {} +
|
||||||
|
|
||||||
# Custom make_unique for C++11 compatibility
|
# Create a single compatibility header
|
||||||
cat <<'EOF_MAKE_UNIQUE' > /tmp/make_unique.patch
|
cat <<'EOF_COMPAT' > src/cpp11_compat.h
|
||||||
|
#ifndef OFXPIMAPPER_CPP11_COMPAT_H
|
||||||
|
#define OFXPIMAPPER_CPP11_COMPAT_H
|
||||||
|
#include <memory>
|
||||||
|
#include <utility>
|
||||||
#if __cplusplus < 201402L
|
#if __cplusplus < 201402L
|
||||||
namespace std {
|
namespace std {
|
||||||
template<typename T, typename... Args>
|
template<typename T, typename... Args>
|
||||||
unique_ptr<T> make_unique(Args&&... args) {
|
std::unique_ptr<T> make_unique(Args&&... args) {
|
||||||
return unique_ptr<T>(new T(std::forward<Args>(args)...));
|
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
EOF_MAKE_UNIQUE
|
#endif
|
||||||
|
EOF_COMPAT
|
||||||
|
|
||||||
|
# Include the compat header in the main addon header
|
||||||
|
grep -q "cpp11_compat.h" src/ofxPiMapper.h || sed -i '1i #include "cpp11_compat.h"' src/ofxPiMapper.h
|
||||||
|
|
||||||
|
# Also ensure make_unique is namespaced in the source
|
||||||
|
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 memory header only where missing
|
||||||
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
|
||||||
rm -f /tmp/make_unique.patch
|
|
||||||
|
|
||||||
# Build Example (Force C++11 for binary symbol compatibility with OF core)
|
# 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"
|
||||||
|
|||||||
Reference in New Issue
Block a user