“链接器输入文件”尝试编译 C++ 时出现未使用的错误使用 R 的 g++ 的代码编译器

发布于 2024-10-24 20:00:23 字数 2719 浏览 3 评论 0原文

我正在尝试在 R 包中使用 OpenCV 中的一些代码,并使用 Rcpp 来构建包。当我在我的机器上编译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`

R 执行以下

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 像我本地的 g++ 编译器一样编译 C++ 代码?我不确定“-c”标志是否是问题所在......不幸的是我无法通过谷歌或编写 R 扩展手册找到答案。谢谢!

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.cpp -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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

迷雾森÷林ヴ 2024-10-31 20:00:23

几点:

  • 这些是来自编译步骤的警告,告诉您编译步骤不需要库(因为那些在链接时出现)

  • 您正在尝试融合两个中等复杂的系统。

  • 我建议退后一步——您知道如何编译示例文件,现在使用 Makevars 设置对更简单的相关 R 包执行相同的操作。有一些软件包使用 Rcpp 和 GSL 作为一种通用外部库。您可以尝试看看它们是如何工作的,以及它们如何理解模式。

  • 一旦您掌握了该模式,请将其应用到 OpenCV 中。

抱歉,但我没有看到明显的捷径。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文