我正在使用Eigen库在MacOS上使用Xcode并且在编译第二个语句时遇到一些困难:
#include <Eigen/Geometry>
int main(int argc, const char * argv[]) {
// compiles fine
Eigen::Quaternionf q;
// does not compile
Eigen::Quaternionf* pq = new Eigen::Quaternionf();
}
编译器输出:
/Users/john/Library/Mobile Documents/com~apple~CloudDocs/xcode/ReconstructionRefinement/ReconstructionRefinement/main.cpp:8:24: warning: unused variable 'pq' [-Wunused-variable]
Eigen::Quaternionf* pq = new Eigen::Quaternionf();
^
In file included from /Users/john/Library/Mobile Documents/com~apple~CloudDocs/xcode/ReconstructionRefinement/ReconstructionRefinement/main.cpp:1:
In file included from /usr/local/Cellar/eigen/3.2.6/include/eigen3/Eigen/Geometry:40:
/usr/local/Cellar/eigen/3.2.6/include/eigen3/Eigen/src/Geometry/Quaternion.h:279:3: error: no matching function for call to 'conditional_aligned_malloc'
EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF(IsAligned)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /Users/john/Library/Mobile Documents/com~apple~CloudDocs/xcode/ReconstructionRefinement/ReconstructionRefinement/main.cpp:1:
In file included from /usr/local/Cellar/eigen/3.2.6/include/eigen3/Eigen/Geometry:4:
In file included from /usr/local/Cellar/eigen/3.2.6/include/eigen3/Eigen/Core:256:
/usr/local/Cellar/eigen/3.2.6/include/eigen3/Eigen/src/Core/util/Memory.h:626:16: note: expanded from macro 'EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF'
return Eigen::internal::conditional_aligned_malloc<NeedsToAlign>(size); \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/john/Library/Mobile Documents/com~apple~CloudDocs/xcode/ReconstructionRefinement/ReconstructionRefinement/main.cpp:8:29: note: in instantiation of member function 'Eigen::Quaternion<float, 0>::operator new' requested here
Eigen::Quaternionf* pq = new Eigen::Quaternionf();
编译器版本:
$ cc -v
Apple LLVM version 7.0.0 (clang-700.1.76)
Target: x86_64-apple-darwin14.5.0
Thread model: posix
特征库版本:
$ brew ls eigen
/usr/local/Cellar/eigen/3.2.6/include/eigen3/ (364 files)
/usr/local/Cellar/eigen/3.2.6/lib/pkgconfig/eigen3.pc
/usr/local/Cellar/eigen/3.2.6/share/cmake/Modules/FindEigen3.cmake
它似乎与内存对齐有关但我在所有模板编程中都迷失了。
我的(详细)编译器标志:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -x c++ -arch x86_64 -fmessage-length=0 -fdiagnostics-show-note-include-stack -fmacro-backtrace-limit=0 -std=gnu++11 -stdlib=libc++ -fmodules -gmodules -fmodules-cache-path=/Users/johnschavemaker/Library/Developer/Xcode/DerivedData/ModuleCache -fmodules-prune-interval=86400 -fmodules-prune-after=345600 -fbuild-session-file=/Users/johnschavemaker/Library/Developer/Xcode/DerivedData/ModuleCache/Session.modulevalidation -fmodules-validate-once-per-build-session -Wnon-modular-include-in-framework-module -Werror=non-modular-include-in-framework-module -Wno-trigraphs -fpascal-strings -O0 -fno-common -Wno-missing-field-initializers -Wno-missing-prototypes -Werror=return-type -Wunreachable-code -Werror=deprecated-objc-isa-usage -Werror=objc-root-class -Wno-non-virtual-dtor -Wno-overloaded-virtual -Wno-exit-time-destructors -Wno-missing-braces -Wparentheses -Wswitch -Wunused-function -Wno-unused-label -Wno-unused-parameter -Wunused-variable -Wunused-value -Wempty-body -Wconditional-uninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-conversion -Wconstant-conversion -Wint-conversion -Wbool-conversion -Wenum-conversion -Wshorten-64-to-32 -Wno-newline-eof -Wno-c++11-extensions -DDEBUG=1 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -fasm-blocks -fstrict-aliasing -Wdeprecated-declarations -Winvalid-offsetof -mmacosx-version-min=10.10 -g -fvisibility-inlines-hidden -Wno-sign-conversion -D__clang_analyzer__ -Xclang -analyzer-output=plist-multi-file -Xclang -analyzer-config -Xclang path-diagnostics-alternate=true -Xclang -analyzer-config -Xclang report-in-main-source-file=true -Xclang -analyzer-checker -Xclang security.insecureAPI.UncheckedReturn -Xclang -analyzer-checker -Xclang security.insecureAPI.getpw -Xclang -analyzer-checker -Xclang security.insecureAPI.gets -Xclang -analyzer-checker -Xclang security.insecureAPI.mkstemp -Xclang -analyzer-checker -Xclang security.insecureAPI.mktemp -Xclang -analyzer-disable-checker -Xclang security.insecureAPI.rand -Xclang -analyzer-disable-checker -Xclang security.insecureAPI.strcpy -Xclang -analyzer-checker -Xclang security.insecureAPI.vfork -iquote /Users/johnschavemaker/Library/Developer/Xcode/DerivedData/ReconstructionRefinement-aulegxqhgigaeueetkigbqjyaqgx/Build/Intermediates/ReconstructionRefinement.build/Debug/ReconstructionRefinement.build/ReconstructionRefinement-generated-files.hmap -I/Users/johnschavemaker/Library/Developer/Xcode/DerivedData/ReconstructionRefinement-aulegxqhgigaeueetkigbqjyaqgx/Build/Intermediates/ReconstructionRefinement.build/Debug/ReconstructionRefinement.build/ReconstructionRefinement-own-target-headers.hmap -I/Users/johnschavemaker/Library/Developer/Xcode/DerivedData/ReconstructionRefinement-aulegxqhgigaeueetkigbqjyaqgx/Build/Intermediates/ReconstructionRefinement.build/Debug/ReconstructionRefinement.build/ReconstructionRefinement-all-target-headers.hmap -iquote /Users/johnschavemaker/Library/Developer/Xcode/DerivedData/ReconstructionRefinement-aulegxqhgigaeueetkigbqjyaqgx/Build/Intermediates/ReconstructionRefinement.build/Debug/ReconstructionRefinement.build/ReconstructionRefinement-project-headers.hmap -I/Users/johnschavemaker/Library/Developer/Xcode/DerivedData/ReconstructionRefinement-aulegxqhgigaeueetkigbqjyaqgx/Build/Products/Debug/include -I/usr/local/Cellar/eigen/3.2.6/include/eigen3 -I/Users/johnschavemaker/Library/Developer/Xcode/DerivedData/ReconstructionRefinement-aulegxqhgigaeueetkigbqjyaqgx/Build/Intermediates/ReconstructionRefinement.build/Debug/ReconstructionRefinement.build/DerivedSources/x86_64 -I/Users/johnschavemaker/Library/Developer/Xcode/DerivedData/ReconstructionRefinement-aulegxqhgigaeueetkigbqjyaqgx/Build/Intermediates/ReconstructionRefinement.build/Debug/ReconstructionRefinement.build/DerivedSources -F/Users/johnschavemaker/Library/Developer/Xcode/DerivedData/ReconstructionRefinement-aulegxqhgigaeueetkigbqjyaqgx/Build/Products/Debug -MMD -MT dependencies -MF /Users/johnschavemaker/Library/Developer/Xcode/DerivedData/ReconstructionRefinement-aulegxqhgigaeueetkigbqjyaqgx/Build/Intermediates/ReconstructionRefinement.build/Debug/ReconstructionRefinement.build/StaticAnalyzer/ReconstructionRefinement/ReconstructionRefinement/normal/x86_64/main.d --analyze /Users/johnschavemaker/Library/Mobile\ Documents/com~apple~CloudDocs/xcode/ReconstructionRefinement/ReconstructionRefinement/main.cpp -o /Users/johnschavemaker/Laulegxqhgigaeueetkigbqjyaqgx/Build/Intermediates/ReconstructionRefinement.build/Debug/ReconstructionRefinement.build/StaticAnalyzer/ReconstructionRefinement/ReconstructionRefinement/normal/x86_64/main.plistibrary/Developer/Xcode/DerivedData/ReconstructionRefinement-