我想在R包中使用OpenCV中的一些代碼,使用Rcpp構建包。當我在我的機器上編譯c代碼時,它工作正常。「鏈接器輸入文件」嘗試使用R的g ++編譯器編譯C++代碼時出現未使用的錯誤
例如,我現在用的是下面的語法本地編譯facedetect.cpp代碼:
g++ `pkg-config --cflags opencv` facedetect.cpp -o facedetect `pkg-config --libs opencv`
然而,當我嘗試使用以下命令把它列入我的包:
R CMD SHLIB facedetect.cpp -o facedetect
具有以下在我makevars文件中定義:
PKG_CPPFLAGS= `$(R_HOME)/bin/Rscript -e 'Rcpp:::CxxFlags()'`
PKG_LIBS = `$(R_HOME)/bin/Rscript -e "Rcpp:::LdFlags()"`
PKG_CXXFLAGS= `pkg-config --cflags opencv` `pkg-config --libs opencv`
ř執行第E採用:
g++ -arch x86_64 -I/Library/Frameworks/R.framework/Resources/include -I/Library/Frameworks/R.framework/Resources/include/x86_64 `pkg-config --cflags opencv` `pkg-config --libs opencv` `/Library/Frameworks/R.framework/Resources/bin/Rscript -e 'Rcpp:::CxxFlags()'` -I/usr/local/include -fPIC -g -O2 -c facedetect.cpp -o facedetect.o
這給了我以下錯誤消息:
i686-apple-darwin10-g++-4.2.1: -lopencv_core: linker input file unused because linking not done
i686-apple-darwin10-g++-4.2.1: -lopencv_imgproc: linker input file unused because linking not done
i686-apple-darwin10-g++-4.2.1: -lopencv_highgui: linker input file unused because linking not done
i686-apple-darwin10-g++-4.2.1: -lopencv_ml: linker input file unused because linking not done
i686-apple-darwin10-g++-4.2.1: -lopencv_video: linker input file unused because linking not done
i686-apple-darwin10-g++-4.2.1: -lopencv_features2d: linker input file unused because linking not done
i686-apple-darwin10-g++-4.2.1: -lopencv_calib3d: linker input file unused because linking not done
i686-apple-darwin10-g++-4.2.1: -lopencv_objdetect: linker input file unused because linking not done
i686-apple-darwin10-g++-4.2.1: -lopencv_contrib: linker input file unused because linking not done
i686-apple-darwin10-g++-4.2.1: -lopencv_legacy: linker input file unused because linking not done
i686-apple-darwin10-g++-4.2.1: -lopencv_flann: linker input file unused because linking not done
g++ -arch x86_64 -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/usr/local/lib -o facedetect facedetect.o -I/opt/local/include/opencv -I/opt/local/include -L/opt/local/lib -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
我不明白這些錯誤消息,因爲我沒有足夠的經驗與C++。有誰知道如何讓R編譯C++代碼,就像我的本地g ++編譯器一樣?我不確定是否「-c」標誌是問題...不幸的是,我無法通過google或Writing R Extensions手冊找到答案。謝謝!