I am beginner with building c++ applications and RInside (A library that provides embedded R interpreter access from C++ program) and need some help. I want to keep all code using RInside separated in a class/module and provide just a function (take some input, do some task using RInside and return the output) to other programs who need these data. I am experimenting if i can use this functionality in another project/module (Omnet++ veins if anyone wants specifically) which has so many other source files and separate makefiles. if possible i would like to not touch that modules and their compilation process. So i tried a simple example and have a doubt regarding building. I have RInside code in Test1 class and want to use it in Test2 class. As far as i understand i am using RInside as a shared library. So i need to build a shared library using Test1 and include or reference it in Test2.
Directory Shared_1:Test1.h , Test1.cc : class Test1
Directory shared_2: Test2.h , Test2.cc : class Test2
Test1.h -> Includes “Rinside.h”
Test1.cc -> includes “Test1.h”
-> main(): Create a Test1 object and call test1Function1()
->test1Function1() : Creates an embedded R instance and does some functionality
Test2.h -> Includes “Test1.h”
Test2.cc -> includes “Test2.h”
-> main() : Create a Test2 object and call test2Function1()
-> test2Function1() : Create a Test1 object and call test1Function1()
I Have created libTest1_1.so from Test1.cc like this.
g++ -I/usr/share/R/include -I/home/aelab/R/x86_64-pc-linux-gnu-library/3.4/Rcpp/include -I/home/aelab/R/x86_64-pc-linux-gnu-library/3.4/RInside/include -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -g -Wall ./shared_1/Test1.cc -Wl,--export-dynamic -fopenmp -Wl,-Bsymbolic-functions -Wl,-z,relro -L/usr/lib/R/lib -lR -lpcre -llzma -lbz2 -lz -lrt -ldl -lm -lblas -llapack -L/home/aelab/R/x86_64-pc-linux-gnu-library/3.4/RInside/lib -lRInside -Wl,-rpath,/home/aelab/R/x86_64-pc-linux-gnu-library/3.4/RInside/lib -fPIC -shared -o ./shared_1/libTest1_1.so
I want to use test1Function1() from Test1.cc in Test2.cc and if possible compile Test2.cc with different options to g++. When i compile Test2.cc using All libraries(Libraries used for building Test1.cc and also libTest1_1.so), it works well.
g++ -I ./shared_1/ -I/usr/share/R/include -I/home/aelab/R/x86_64-pc-linux-gnu-library/3.4/Rcpp/include -I/home/aelab/R/x86_64-pc-linux-gnu-library/3.4/RInside/include -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -g -Wall ./shared_2/Test2.cc -Wl,--export-dynamic -fopenmp -Wl,-Bsymbolic-functions -Wl,-z,relro -L/usr/lib/R/lib -lR -lpcre -llzma -lbz2 -lz -lrt -ldl -lm -lblas -llapack -L/home/aelab/R/x86_64-pc-linux-gnu-library/3.4/RInside/lib -lRInside -Wl,-rpath,/home/aelab/R/x86_64-pc-linux-gnu-library/3.4/RInside/lib -L./shared_1/ -lTest1_1 -fPIC -o ./shared_2/Test2.o
But when i compile it by just compiling it by providing include dir of Test1.h and the libTest1.so, it gives me error. If i understand correctly, g++ is trying to compile Test1 when i am building Test2. So it says it can not find RInside.h even though i am not including it directly in Test2.
g++ -I ./shared_1/ ./shared_2/Test2.cc -L./shared_1/ -lTest1_1 -fPIC -shared -o ./shared_2/Test2_3.o
In file included from ./shared_2/Test2.h:11:0,
from ./shared_2/Test2.cc:8:
./shared_1/Test1.h:12:74: fatal error: RInside.h: No such file or directory
#include
^
compilation terminated.
What i want to understand: 1) how to separate the code using RInside from another project/ module. 2) What i am doing wrong here.
I Have included some file here in google drive.
I tried searching online but could not understand. I am definitely missing to understand something. Can anyone please help.