开发者

"linker input file" unused error when trying to compile C++ code using R's g++ compiler

I am trying to use some code from OpenCV in an R package, using Rcpp to build the package. When I compile the c code on my machine, it works fine.

For example, I am using the the following syntax locally to compile the facedetect.cpp code:

g++ `pkg-config --cflags opencv` facedetect.cpp -o facedetect `pkg-config --libs opencv` 

However, when I try to include it in my package using the following command:

R CMD SHLIB  facedetect.c开发者_运维百科pp -o facedetect

with the following defined in my makevars file:

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`

R executes the following:

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

which gives me the following error messages:

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

I do not understand these error messages, because I do not have enough experience with C++. Does anyone know how to get R to compile the C++ code as my local g++ compiler does? I'm not sure if the "-c" flag is the problem... Unfortunately I could not find the answer via google or the Writing R Extensions manual. Thanks!


A few points:

  • Those are warnings from the compile steps telling you that the compile step does not need libraries (as those come in when linking)

  • You are trying to meld two moderately complicated systems.

  • I would recommend stepping back -- you know how to compile your example file, now do the same for a simpler related R package using a Makevars setup. There are a few packages using Rcpp with the GSL as one common external library. You could try to see how they work and they to understand the pattern.

  • Once you have that pattern down, apply it to your use with OpenCV.

Sorry, but I see no obvious shortcuts.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜