当我在 C++ 程序中包含 RInside header 时,如何让链接器工作?
How can I get the linkers to work when I include the RInside header in a C++ program?
我正在尝试编译 RInside 包的标准示例存储库中的示例。我已经尝试 运行ning 存储库中已有的 Makefile,但没有用。到目前为止,我已经 运行 犯了几个错误,其中一些已经解决了。问题是,每次我解决一个错误时,都会发生以下两种情况之一,它会出现一个新错误或一个旧错误再次出现。这是具有相应错误的不同 makefile 的代码:
1) 没有 -L
的 Makefile
all:
g++ -I/usr/share/R/include -I/home/manuel/R/x86_64-pc-linux-gnu-library/3.4/Rcpp/include -I/home/manuel/R/x86_64-pc-linux-gnu-library/3.4/RInside/include rinsidetest.cpp
正如预期的那样,将 make 应用于此文件 returns 关于对 RInside::'s 的未定义引用的错误
undefined reference to `RInside::RInside(int, char const* const*, bool, bool, bool)'
2) 带有 -L 链接的 Makefile
all:
g++ -I/usr/share/R/include -I/home/manuel/R/x86_64-pc-linux-gnu-library/3.4/Rcpp/include -I/home/manuel/R/x86_64-pc-linux-gnu-library/3.4/RInside/include -L/usr/lib/R/site-library/RInside/lib -L/home/manuel/R/x86_64-pc-linux-gnu-library/3.4/Rcpp/libs -lRInside -lRcpp -L/usr/lib/R/lib -lR -Wl,-rpath,/home/manuel/R/x86_64-pc-linux-gnu-library/3.4/Rcpp/libs -lRInside -Wl,-rpath,/home/manuel/R/x86_64-pc-linux-gnu-library/3.4/RInside/lib rinsidetest.cpp
错误是这样的:
/usr/bin/ld: cannot find -lRcpp
原来libs仓库中的.so文件名为Rcpp.so,所以我将其重命名为libRcpp.so
,错误消失了。
3) 将 Rcpp.so
重命名为 libRcpp.so
后,我将 make 应用到第 2 点的同一个 makefile 中,错误再次与 RInside:::
的未定义引用有关
rinsidetest.cpp:(.text+0x100): undefined reference to `RInside::RInside(int, char const* const*, bool, bool, bool)
4) 将 make 应用到文件夹中已有的 makefile
make -f Makefile
错误(将 R_LIBS_USER
更改为
后
R_LIBS_USER := "/home/manuel/R/x86_64-pc-linux-gnu-library/3.4"
是:
fatal error: RInside.h: No such file or directory
compilation terminated.
到目前为止,我已经阅读了更多有关在 C++ 中包含 headers 的一般性问题,以及一些专门针对 RInside 的问题,其中一些由编写程序包的 Dirk Eddelbuettel 回答,但所有答案与链接器的使用有关 -L<path>/include
我几乎可以肯定我使用正确。
这是我到目前为止读过的一些问题:
Compiling RInside program with g++ on LinuxCompiling RInside program with g++ on Linux
Compiling the Rcpp package
http://lists.r-forge.r-project.org/pipermail/rcpp-devel/2012-May/003829.html
http://rcpp-devel.r-forge.r-project.narkive.com/A70U2nVw/problem-with-rinside-hello-world-example
我正在使用 Ubuntu 16.04 和 R 版本 3.4.4。
任何帮助将不胜感激!
我不确定你在哪里迷路了,但基本的想法就是这样说:
- 进入目录。
make clean
以防万一
make
(即 make all
)或只有一个。
这仍然有效---我自己使用 Debian/Ubuntu。
这里做make rinside_sample0
来证明这一点,然后运行它:
edd@rob:~$ cd git/rinside/inst/examples/standard/
edd@rob:~/git/rinside/inst/examples/standard$ make -f GNUmakefile clean
rm -vf rinside_sample9 [....stuff remove to keep it shorter...] rinside_sample16
rm -vrf *.dSYM
edd@rob:~/git/rinside/inst/examples/standard$ make -f GNUmakefile rinside_sample0
ccache g++ -I/usr/share/R/include -I/usr/local/lib/R/site-library/Rcpp/include \
-I/usr/local/lib/R/site-library/RInside/include -g -O3 -Wall -pipe \
-Wno-misleading-indentation -Wno-unused \
-Wno-ignored-attributes -Wno-deprecated-declarations \
-march=native -Wall rinside_sample0.cpp -Wl,--export-dynamic \
-fopenmp -Wl,-Bsymbolic-functions -Wl,-z,relro -L/usr/lib/R/lib -lR \
-lpcre -llzma -lbz2 -lz -lrt -ldl -lm -licuuc -licui18n \
-lblas -llapack -L/usr/local/lib/R/site-library/RInside/lib \
-lRInside -Wl,-rpath,/usr/local/lib/R/site-library/RInside/lib \
-o rinside_sample0
edd@rob:~/git/rinside/inst/examples/standard$ ./rinside_sample0 s
Hello, world!
edd@rob:~/git/rinside/inst/examples/standard(master)$
我手动缩进了这个,我可能在 ~/.R/Makevars
中有一些本地设置显示在这里 -- 这无关紧要。
重要的是它开箱即用,如果您不理会它。如果您更改了设置,但它坏了,您就可以解决一个原本不必创建的问题。
我正在尝试编译 RInside 包的标准示例存储库中的示例。我已经尝试 运行ning 存储库中已有的 Makefile,但没有用。到目前为止,我已经 运行 犯了几个错误,其中一些已经解决了。问题是,每次我解决一个错误时,都会发生以下两种情况之一,它会出现一个新错误或一个旧错误再次出现。这是具有相应错误的不同 makefile 的代码:
1) 没有 -L
的 Makefile all:
g++ -I/usr/share/R/include -I/home/manuel/R/x86_64-pc-linux-gnu-library/3.4/Rcpp/include -I/home/manuel/R/x86_64-pc-linux-gnu-library/3.4/RInside/include rinsidetest.cpp
正如预期的那样,将 make 应用于此文件 returns 关于对 RInside::'s 的未定义引用的错误
undefined reference to `RInside::RInside(int, char const* const*, bool, bool, bool)'
2) 带有 -L 链接的 Makefile
all:
g++ -I/usr/share/R/include -I/home/manuel/R/x86_64-pc-linux-gnu-library/3.4/Rcpp/include -I/home/manuel/R/x86_64-pc-linux-gnu-library/3.4/RInside/include -L/usr/lib/R/site-library/RInside/lib -L/home/manuel/R/x86_64-pc-linux-gnu-library/3.4/Rcpp/libs -lRInside -lRcpp -L/usr/lib/R/lib -lR -Wl,-rpath,/home/manuel/R/x86_64-pc-linux-gnu-library/3.4/Rcpp/libs -lRInside -Wl,-rpath,/home/manuel/R/x86_64-pc-linux-gnu-library/3.4/RInside/lib rinsidetest.cpp
错误是这样的:
/usr/bin/ld: cannot find -lRcpp
原来libs仓库中的.so文件名为Rcpp.so,所以我将其重命名为libRcpp.so
,错误消失了。
3) 将 Rcpp.so
重命名为 libRcpp.so
后,我将 make 应用到第 2 点的同一个 makefile 中,错误再次与 RInside:::
rinsidetest.cpp:(.text+0x100): undefined reference to `RInside::RInside(int, char const* const*, bool, bool, bool)
4) 将 make 应用到文件夹中已有的 makefile
make -f Makefile
错误(将 R_LIBS_USER
更改为
R_LIBS_USER := "/home/manuel/R/x86_64-pc-linux-gnu-library/3.4"
是:
fatal error: RInside.h: No such file or directory
compilation terminated.
到目前为止,我已经阅读了更多有关在 C++ 中包含 headers 的一般性问题,以及一些专门针对 RInside 的问题,其中一些由编写程序包的 Dirk Eddelbuettel 回答,但所有答案与链接器的使用有关 -L<path>/include
我几乎可以肯定我使用正确。
这是我到目前为止读过的一些问题:
Compiling RInside program with g++ on LinuxCompiling RInside program with g++ on Linux
Compiling the Rcpp package
http://lists.r-forge.r-project.org/pipermail/rcpp-devel/2012-May/003829.html
http://rcpp-devel.r-forge.r-project.narkive.com/A70U2nVw/problem-with-rinside-hello-world-example
我正在使用 Ubuntu 16.04 和 R 版本 3.4.4。 任何帮助将不胜感激!
我不确定你在哪里迷路了,但基本的想法就是这样说:
- 进入目录。
make clean
以防万一make
(即make all
)或只有一个。
这仍然有效---我自己使用 Debian/Ubuntu。
这里做make rinside_sample0
来证明这一点,然后运行它:
edd@rob:~$ cd git/rinside/inst/examples/standard/
edd@rob:~/git/rinside/inst/examples/standard$ make -f GNUmakefile clean
rm -vf rinside_sample9 [....stuff remove to keep it shorter...] rinside_sample16
rm -vrf *.dSYM
edd@rob:~/git/rinside/inst/examples/standard$ make -f GNUmakefile rinside_sample0
ccache g++ -I/usr/share/R/include -I/usr/local/lib/R/site-library/Rcpp/include \
-I/usr/local/lib/R/site-library/RInside/include -g -O3 -Wall -pipe \
-Wno-misleading-indentation -Wno-unused \
-Wno-ignored-attributes -Wno-deprecated-declarations \
-march=native -Wall rinside_sample0.cpp -Wl,--export-dynamic \
-fopenmp -Wl,-Bsymbolic-functions -Wl,-z,relro -L/usr/lib/R/lib -lR \
-lpcre -llzma -lbz2 -lz -lrt -ldl -lm -licuuc -licui18n \
-lblas -llapack -L/usr/local/lib/R/site-library/RInside/lib \
-lRInside -Wl,-rpath,/usr/local/lib/R/site-library/RInside/lib \
-o rinside_sample0
edd@rob:~/git/rinside/inst/examples/standard$ ./rinside_sample0 s
Hello, world!
edd@rob:~/git/rinside/inst/examples/standard(master)$
我手动缩进了这个,我可能在 ~/.R/Makevars
中有一些本地设置显示在这里 -- 这无关紧要。
重要的是它开箱即用,如果您不理会它。如果您更改了设置,但它坏了,您就可以解决一个原本不必创建的问题。