3
3
# We make sure that the R and Armadillo bindings are compatible (i.e., messages)
4
4
# this is why we add the R and cpp11 path
5
5
CXX=` ${R_HOME} /bin/R CMD config CXX`
6
- R_INCLUDE_PATH=` ${R_HOME} /bin/R CMD config --cflags`
6
+ R_INCLUDE_PATH=` ${R_HOME} /bin/R CMD config --cppflags`
7
+ R_LDFLAGS=` ${R_HOME} /bin/R CMD config --ldflags`
7
8
CPP11_INCLUDE_PATH=` ${R_HOME} /bin/Rscript -e " cat(system.file('include', package = 'cpp11'))" `
8
9
9
10
# Check if CPP11_INCLUDE_PATH is empty
@@ -12,18 +13,23 @@ if [ -z "$CPP11_INCLUDE_PATH" ]; then
12
13
exit 1
13
14
fi
14
15
15
- # Manually specify the R include path if --cflags does not provide it
16
- if [ " $R_INCLUDE_PATH " = " ERROR: no information for variable '--cflags'" ]; then
17
- R_INCLUDE_PATH=" -I/usr/share/R/include"
18
- fi
16
+ # Get the absolute path to the inst/include directory
17
+ INST_INCLUDE_PATH=$( cd " $( dirname " $0 " ) /inst/include" && pwd)
19
18
20
- PKG_CFLAGS=" -I./inst/include ${R_INCLUDE_PATH} -I${CPP11_INCLUDE_PATH} "
19
+ PKG_CFLAGS=" ${R_INCLUDE_PATH} -I${CPP11_INCLUDE_PATH} -I${INST_INCLUDE_PATH} "
20
+ PKG_LDFLAGS=" ${R_LDFLAGS} "
21
21
22
22
# Debugging: Print the values of the variables
23
+ echo " =================================="
24
+ echo " Compiler Configuration Variables "
25
+ echo " "
23
26
echo " CXX: ${CXX} "
24
27
echo " R_INCLUDE_PATH: ${R_INCLUDE_PATH} "
28
+ echo " R_LDFLAGS: ${R_LDFLAGS} "
25
29
echo " CPP11_INCLUDE_PATH: ${CPP11_INCLUDE_PATH} "
30
+ echo " INST_INCLUDE_PATH: ${INST_INCLUDE_PATH} "
26
31
echo " PKG_CFLAGS: ${PKG_CFLAGS} "
32
+ echo " PKG_LDFLAGS: ${PKG_LDFLAGS} "
27
33
28
34
# Create a temporary C++ file to test the compatibility with Armadillo
29
35
cat << EOF> conftest.cpp
@@ -35,13 +41,16 @@ int main() {
35
41
}
36
42
EOF
37
43
38
- # Test Armadillo using R CMD SHLIB
39
- if ! ${R_HOME} /bin/R CMD SHLIB conftest.cpp ${PKG_CFLAGS}
44
+ # Test Armadillo using g++
45
+ echo "==================================="
46
+ echo " Testing minimal Armadillo example "
47
+ echo " "
48
+ if ! ${CXX} ${PKG_CFLAGS} conftest.cpp ${PKG_LDFLAGS} -o conftest
40
49
then
41
50
echo "Armadillo is not compatible with the C++ compiler used by R."
42
- rm -f conftest.cpp conftest.o conftest.so
51
+ rm -f conftest.cpp conftest.o conftest
43
52
exit 1
44
53
else
45
54
echo "Armadillo is compatible with the C++ compiler used by R."
46
- rm -f conftest.cpp conftest.o conftest.so
55
+ rm -f conftest.cpp conftest.o conftest
47
56
fi
0 commit comments