我正在从名为myCode
的多线程C ++包创建一个R包myCode
。 (正如您在下面的Makevars中看到的,它需要链接到两个现有的C ++库library1
和library2
。)
使用Rcpp骨架,我在/src
中添加了所有C ++代码并创建了这个Makevars文件以输出共享库myCode.so
,其中包含了{{1}标志}和-fPIC
:
-shared
这似乎可以在LIBRARY1_DIR := ./library1/
LIBRARY2_DIR := ./library2/
ABS_LIBRARY1_DIR := $(realpath $(LIBRARY1_DIR))
ABS_LIBRARY2_DIR := $(realpath $(LIBRARY2_DIR))
CXX := g++
CXXFLAGS := -Wno-deprecated -Wall -O3 -fexceptions -g -Wl,-rpath,$(ABS_LIBRARY1_DIR)/lib/
LDLIBS := -I$(ABS_LIBRARY1_DIR)/include/ -I$(ABS_LIBRARY2_DIR)/ -L$(ABS_LIBRARY1_DIR)/lib/ -L$(ABS_LIBRARY2_DIR)/
all: library1 library2 myCode
.PHONY : myCode
myCode: file1.cpp file2.cpp file3.hh file3.cpp file4.hh file4.cpp file5.cpp file5.hh file6.hh file6.hh file7.cpp file7.hh
$(CXX) $(CXXFLAGS) $(INCLUDES) file1.cpp file2.cpp -o myCode.so $(ABS_LIBRARY2_DIR)/importfile1.a -lz -ldl -llibrary1 -lpthread -fPIC -shared
.PHONY : library1
library1:
mkdir $(ABS_LIBRARY1_DIR)/build; cd $(ABS_LIBRARY1_DIR)/build; cmake ..; make; cd ../
.PHONY : library2
library2:
cd $(ABS_LIBRARY2_DIR); ./configure; make; cd ../
#.PHONY : clean
clean:
rm myCode.so; rm -rf $(ABS_LIBRARY1_DIR)/build; rm -rf $(ABS_LIBRARY1_DIR)/include; rm -rf $(ABS_LIBRARY1_DIR)/lib; rm -rf $(ABS_LIBRARY1_DIR)/bin; cd $(ABS_LIBRARY2_DIR); make clean;
和library(devtools)
上正确编译...直到它开始输出这些行,这些行会发出多个install_github("handle/myCode")
警告,直到它出现故障:
'linker' input unused [-Wunused-command-line-argument]
clang++ -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I/usr/local/include -I/usr/local/include/freetype2 -I/opt/X11/include -I"/Library/Frameworks/R.framework/Versions/3.3/Resources/library/Rcpp/include" -std=c++11 -Wno-deprecated -Wall -O3 -fexceptions -g -Wl,-rpath,/private/var/folders/1d/_h9qdvds6l5d7x78b21pn1_45n_16x/T/RtmpabyubP/devtools56576bf4fa65/username-myCode-368aaf6/src/library1/lib/ -fPIC -Wall -mtune=core2 -g -O2 -c file2.cpp -o file2.o
clang: warning: -Wl,-rpath,/private/var/folders/1d/_h9qdvds6l5d7x78b21pn1_45n_16x/T/RtmpabyubP/devtools56576bf4fa65/username-myCode-368aaf6/src/library/lib/: 'linker' input unused [-Wunused-command-line-argument]
clang++ -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I/usr/local/include -I/usr/local/include/freetype2 -I/opt/X11/include -I"/Library/Frameworks/R.framework/Versions/3.3/Resources/library/Rcpp/include" -std=c++11 -Wno-deprecated -Wall -O3 -fexceptions -g -Wl,-rpath,/private/var/folders/1d/_h9qdvds6l5d7x78b21pn1_45n_16x/T/RtmpabyubP/devtools56576bf4fa65/username-myCode-368aaf6/src/library1/lib/ -fPIC -Wall -mtune=core2 -g -O2 -c file3.cpp -o file3.o
clang: warning: -Wl,-rpath,/private/var/folders/1d/_h9qdvds6l5d7x78b21pn1_45n_16x/T/RtmpabyubP/devtools56576bf4fa65/username-myCode-368aaf6/src/library1/lib/: 'linker' input unused [-Wunused-command-line-argument]
clang++ -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I/usr/local/include -I/usr/local/include/freetype2 -I/opt/X11/include -I"/Library/Frameworks/R.framework/Versions/3.3/Resources/library/Rcpp/include" -std=c++11 -Wno-deprecated -Wall -O3 -fexceptions -g -Wl,-rpath,/private/var/folders/1d/_h9qdvds6l5d7x78b21pn1_45n_16x/T/RtmpabyubP/devtools56576bf4fa65/username-myCode-368aaf6/src/library1/lib/ -fPIC -Wall -mtune=core2 -g -O2 -c file4.cpp -o file4.o
clang: warning: -Wl,-rpath,/private/var/folders/1d/_h9qdvds6l5d7x78b21pn1_45n_16x/T/RtmpabyubP/devtools56576bf4fa65/username-myCode-368aaf6/src/library1/lib/: 'linker' input unused [-Wunused-command-line-argument]
clang++ -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I/usr/local/include -I/usr/local/include/freetype2 -I/opt/X11/include -I"/Library/Frameworks/R.framework/Versions/3.3/Resources/library/Rcpp/include" -std=c++11 -Wno-deprecated -Wall -O3 -fexceptions -g -Wl,-rpath,/private/var/folders/1d/_h9qdvds6l5d7x78b21pn1_45n_16x/T/RtmpabyubP/devtools56576bf4fa65/username-myCode-368aaf6/src/library1/lib/ -fPIC -Wall -mtune=core2 -g -O2 -c file5.cpp -o file5.o
clang: warning: -Wl,-rpath,/private/var/folders/1d/_h9qdvds6l5d7x78b21pn1_45n_16x/T/RtmpabyubP/devtools56576bf4fa65/username-myCode-368aaf6/src/library1/lib/: 'linker' input unused [-Wunused-command-line-argument]
In file included from file6.cpp:1:
In file included from ./file6.hh:27:
./file7.hh:43:10: fatal error: 'lib/library1_header.h' file not found
#include "lib/library1_header.h"
^~~~~~~~~~~~~~~~~
1 error generated.
make: *** [file6.o] Error 1
引发'linker' input unused [-Wunused-command-line-argument]
的原因似乎是-c
。选项-c
表示只编译,不链接",因此忽略任何与链接器相关的命令行参数。代码似乎正确编译,直到这些行。
作为检查上述Makevars
工作的独立测试,如果我将上述内容重命名为myCode.so
并运行Makefile
,则会创建共享对象make
。这个功能正常,dyn.load("myCode.so")
在R中起作用。
安装R包时为什么运行clang++ -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG
?我可以禁用-c
标志,还是应该重写Makevars?