Dear list,
I am working on a project in C++ where I have to use Bayesian Statistics
quite extensively. I coded my own Metropolis Hasting Sampler but since it
is not working that well, I wanted to call rstan from within C++ via
RInside. I already wrote the appropriate RInside/Rcpp code but I don't know
how to rewrite my CMakeLists.txt file to make it work.
I looked at the CMakelists.txt file in the standard/examples folder but I
don't know enough about cmake to rewrite it for my own project.
My project consists of 3 source files and 2 header files and I am working
with Eclipse Mars. Here is my current file:
*cmake_minimum_required(VERSION 2.6)project(XX)# use
C++11set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}
-std=c++11")add_executable(${PROJECT_NAME} global.h model.h model.cpp
run.cpp mcmc.h mcmc.cpp )*
What do I have to change (in the file or in Eclipse itself) to make it work?
Thanks in advance for your help
Ulf
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20150723/a4506930/attachment.html>
[Rcpp-devel] Embedding RInside in C++ project
9 messages · Dirk Eddelbuettel, Ulf Mertens
Hi Ulf,
On 23 July 2015 at 15:53, Ulf Mertens wrote:
| I am working on a project in C++ where I have to use Bayesian Statistics quite
| extensively. I coded my own Metropolis Hasting Sampler but since it is not
| working that well, I wanted to call rstan from within C++ via RInside. I
| already wrote the appropriate RInside/Rcpp code but I don't know how to rewrite
| my CMakeLists.txt file to make it work.
Sounds nice. Will you release this?
| I looked at the CMakelists.txt file in the standard/examples folder but I don't
| know enough about cmake to rewrite it for my own project.
|
| My project consists of 3 source files and 2 header files and I am working with
| Eclipse Mars. Here is my current file:
|
| cmake_minimum_required(VERSION 2.6)
|
| project(XX)
|
| # use C++11
| set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
|
| add_executable(${PROJECT_NAME}
| ? global.h
| ? model.h
| ? model.cpp
| ? run.cpp
| ? mcmc.h
| ? mcmc.cpp
| ? )
|
| What do I have to change (in the file or in Eclipse itself) to make it work?
I wrote and support the 'plain old Makefile(s)' and can help with this.
CMake support was added by Peter (CC'ed) who may be able to help you with this.
My usual approach for 'non-Make' builds is to make it work with make, and
then carry the changes over.
Dirk
http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org
Hi, thanks for your mail. I don't have to use cmake for my project. It's totally fine to use plain Makefiles for me. Sure, I can release this. But first, I want to optimize the code a bit. For instance, I am working with Eigen matrices and vectors in my c++ program but I don't know how to convert a Rcpp::NumericVector to say Eigen::VectorXd. Right now, I first convert to std::vector with Rcpp::as<> and then to Eigen::VectorXd with Eigen::Map. There is certainly a better way but I didn't figure it out yet. Ulf
On Thu, Jul 23, 2015 at 4:15 PM, Dirk Eddelbuettel <edd at debian.org> wrote:
Hi Ulf,
On 23 July 2015 at 15:53, Ulf Mertens wrote:
| I am working on a project in C++ where I have to use Bayesian Statistics
quite
| extensively. I coded my own Metropolis Hasting Sampler but since it is
not
| working that well, I wanted to call rstan from within C++ via RInside. I
| already wrote the appropriate RInside/Rcpp code but I don't know how to
rewrite
| my CMakeLists.txt file to make it work.
Sounds nice. Will you release this?
| I looked at the CMakelists.txt file in the standard/examples folder but
I don't
| know enough about cmake to rewrite it for my own project.
|
| My project consists of 3 source files and 2 header files and I am
working with
| Eclipse Mars. Here is my current file:
|
| cmake_minimum_required(VERSION 2.6)
|
| project(XX)
|
| # use C++11
| set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
|
| add_executable(${PROJECT_NAME}
| global.h
| model.h
| model.cpp
| run.cpp
| mcmc.h
| mcmc.cpp
| )
|
| What do I have to change (in the file or in Eclipse itself) to make it
work?
I wrote and support the 'plain old Makefile(s)' and can help with this.
CMake support was added by Peter (CC'ed) who may be able to help you with
this.
My usual approach for 'non-Make' builds is to make it work with make, and
then carry the changes over.
Dirk
--
http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org
-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20150723/dfd1dfd3/attachment.html>
Hi, I just looked into the GNUMakefile. I think I just have to only change those two lines, right? sources := $(wildcard *.cpp) programs := $(sources:.cpp=) If I understand it correctly, it only works for .cpp files. So it has be changed to something like this? sources := $(wildcard *.cpp) header := $(wildcard *.h) programs := $(sources:.cpp= header:.h=) Thanks Ulf
On Thu, Jul 23, 2015 at 5:14 PM, Ulf Mertens <mertens.ulf at gmail.com> wrote:
Hi, thanks for your mail. I don't have to use cmake for my project. It's totally fine to use plain Makefiles for me. Sure, I can release this. But first, I want to optimize the code a bit. For instance, I am working with Eigen matrices and vectors in my c++ program but I don't know how to convert a Rcpp::NumericVector to say Eigen::VectorXd. Right now, I first convert to std::vector with Rcpp::as<> and then to Eigen::VectorXd with Eigen::Map. There is certainly a better way but I didn't figure it out yet. Ulf On Thu, Jul 23, 2015 at 4:15 PM, Dirk Eddelbuettel <edd at debian.org> wrote:
Hi Ulf,
On 23 July 2015 at 15:53, Ulf Mertens wrote:
| I am working on a project in C++ where I have to use Bayesian
Statistics quite
| extensively. I coded my own Metropolis Hasting Sampler but since it is
not
| working that well, I wanted to call rstan from within C++ via RInside. I
| already wrote the appropriate RInside/Rcpp code but I don't know how to
rewrite
| my CMakeLists.txt file to make it work.
Sounds nice. Will you release this?
| I looked at the CMakelists.txt file in the standard/examples folder but
I don't
| know enough about cmake to rewrite it for my own project.
|
| My project consists of 3 source files and 2 header files and I am
working with
| Eclipse Mars. Here is my current file:
|
| cmake_minimum_required(VERSION 2.6)
|
| project(XX)
|
| # use C++11
| set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
|
| add_executable(${PROJECT_NAME}
| global.h
| model.h
| model.cpp
| run.cpp
| mcmc.h
| mcmc.cpp
| )
|
| What do I have to change (in the file or in Eclipse itself) to make it
work?
I wrote and support the 'plain old Makefile(s)' and can help with this.
CMake support was added by Peter (CC'ed) who may be able to help you with
this.
My usual approach for 'non-Make' builds is to make it work with make, and
then carry the changes over.
Dirk
--
http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org
-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20150724/7068d963/attachment-0001.html>
On 24 July 2015 at 10:18, Ulf Mertens wrote:
| Hi, | | I just looked into the GNUMakefile. I think I just have to only change those | two lines, right? | | sources := ??? ??? $(wildcard *.cpp) | programs := ??? ? $(sources:.cpp=) The idea here is that each .cpp leads to one executable, and its build is triggered by a change in it. ( | If I understand it correctly, it only works for .cpp files. So it has be | changed to something like this? | | sources := ??? ?? $(wildcard *.cpp) | header :=??? ????? $(wildcard *.h) | programs := ???? $(sources:.cpp= header:.h=) The header files are implicit. You could just enumerate the files by hand.: Or, as eg in examples/threads/GNUmakefile, just write the rule: all: boostEx boostEx: boostEx.cpp $(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $@ $^ $(LDLIBS) strip $@ where strip of course optional too. 'boostEx' could depend on more than one .cpp; just list additonal ones. Dirk
http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org
Alright, I left the GNUMakefile as it is and copied it into my program directory. It gives the following error: make: Circular run <- run dependency dropped. Running model: Running run: /bin/sh: ./run: No such file or directory make: *** [run] Error 127 Can you help me here? Thanks again for your help Ulf
On Fri, Jul 24, 2015 at 1:13 PM, Dirk Eddelbuettel <edd at debian.org> wrote:
On 24 July 2015 at 10:18, Ulf Mertens wrote:
| Hi,
|
| I just looked into the GNUMakefile. I think I just have to only change
those
| two lines, right?
|
| sources := $(wildcard *.cpp)
| programs := $(sources:.cpp=)
The idea here is that each .cpp leads to one executable, and its build is
triggered by a change in it. (
| If I understand it correctly, it only works for .cpp files. So it has be
| changed to something like this?
|
| sources := $(wildcard *.cpp)
| header := $(wildcard *.h)
| programs := $(sources:.cpp= header:.h=)
The header files are implicit. You could just enumerate the files by
hand.:
Or, as eg in examples/threads/GNUmakefile, just write the rule:
all: boostEx
boostEx: boostEx.cpp
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $@ $^ $(LDLIBS)
strip $@
where strip of course optional too. 'boostEx' could depend on more than
one
.cpp; just list additonal ones.
Dirk
--
http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org
-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20150724/fd86d7db/attachment.html>
Ulf,
On 24 July 2015 at 13:47, Ulf Mertens wrote:
| Alright, I left the GNUMakefile as it is and copied it into my program Err, "the GNUmakefile"? Which one? There are seven different ones below examples/. | directory. It gives the following error: | | make: Circular run <- run dependency dropped. | | Running model: | | Running run: | /bin/sh: ./run: No such file or directory | make: *** [run] Error 127 | | Can you help me here? Honestly, I can't, given the information provided by you. If I may: If make is not your cup of tea, don't use it. Build your project with a shell script, or manually, or WHATEVER WORKS. Your project. And: _Generic questions about CRAN packages_ are now handled on the (still pretty new) list r-package-devel. This list here is meant for Rcpp (and RInside) questions. I think we have strayed too far off. Dirk
http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org
The question is still the same. I embedded RInside into my project but don't know how to compile it. The problem is that I don't know any way to make it work. I don't hold out for the usage of make. I just want to make it work somehow. I am referring to the makefile in examples/standard. Ulf
On Fri, Jul 24, 2015 at 2:00 PM, Dirk Eddelbuettel <edd at debian.org> wrote:
Ulf, On 24 July 2015 at 13:47, Ulf Mertens wrote: | Alright, I left the GNUMakefile as it is and copied it into my program Err, "the GNUmakefile"? Which one? There are seven different ones below examples/. | directory. It gives the following error: | | make: Circular run <- run dependency dropped. | | Running model: | | Running run: | /bin/sh: ./run: No such file or directory | make: *** [run] Error 127 | | Can you help me here? Honestly, I can't, given the information provided by you. If I may: If make is not your cup of tea, don't use it. Build your project with a shell script, or manually, or WHATEVER WORKS. Your project. And: _Generic questions about CRAN packages_ are now handled on the (still pretty new) list r-package-devel. This list here is meant for Rcpp (and RInside) questions. I think we have strayed too far off. Dirk -- http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org
-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20150724/870a5da7/attachment.html>
Ok, I figured it out: The error stems from the fact that one of my source files was named run.cpp. I renamed it and now (at least) this error is gone. Ulf
On Fri, Jul 24, 2015 at 2:11 PM, Ulf Mertens <mertens.ulf at gmail.com> wrote:
The question is still the same. I embedded RInside into my project but don't know how to compile it. The problem is that I don't know any way to make it work. I don't hold out for the usage of make. I just want to make it work somehow. I am referring to the makefile in examples/standard. Ulf On Fri, Jul 24, 2015 at 2:00 PM, Dirk Eddelbuettel <edd at debian.org> wrote:
Ulf, On 24 July 2015 at 13:47, Ulf Mertens wrote: | Alright, I left the GNUMakefile as it is and copied it into my program Err, "the GNUmakefile"? Which one? There are seven different ones below examples/. | directory. It gives the following error: | | make: Circular run <- run dependency dropped. | | Running model: | | Running run: | /bin/sh: ./run: No such file or directory | make: *** [run] Error 127 | | Can you help me here? Honestly, I can't, given the information provided by you. If I may: If make is not your cup of tea, don't use it. Build your project with a shell script, or manually, or WHATEVER WORKS. Your project. And: _Generic questions about CRAN packages_ are now handled on the (still pretty new) list r-package-devel. This list here is meant for Rcpp (and RInside) questions. I think we have strayed too far off. Dirk -- http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org
-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20150724/a9d17225/attachment.html>