[Rcpp-devel] Using CMakeLists.txt

Richard Downe richard-downe at uiowa.edu
Tue Mar 5 23:13:46 CET 2013


One other detail:
cmake by default names all library outputs "lib[TARGET]". (e.g., there 
*is* no my_package.so, but possibly a libmy_package.so)

If you add the line

SET_TARGET_PROPERTIES(fusionIndices PROPERTIES PREFIX "")

you'll have better luck as well.
-rd

On 03/05/2013 04:00 PM, Richard Downe wrote:
> Also, you're failing to tell CMake to build a shared library.
> You need
> SET(CMAKE_C++_CREATE_SHARED_LIBRARY 1)
>
> And if you're using Rcpp, also need to explicitly add Rcpp link flags 
> (Rscript -e Rcpp:::LdFlags())
> -rd
>
> On 03/05/2013 03:44 PM, Richard Downe wrote:
>> What I've been doing the past couple years, which has worked 
>> extremely well, is to use a configure script (I've used perl because 
>> it allows me to do a bunch of other build-time processing that's 
>> specific to my package, but bash would work fine as well).
>>
>> All you need (for perl) is:
>>
>> #!/usr/bin/perl
>> chdir "src/";
>> system("cmake .");
>> chdir "..";
>> exit(0);
>>
>> The end result is that R CMD INSTALL [your package] finds an up to 
>> date makefile in src, but otherwise runs conventionally, and your 
>> package gets built and installed properly.
>>
>> -rd
>>
>>
>> On 03/05/2013 02:09 PM, Dirk Eddelbuettel wrote:
>>> On 5 March 2013 at 12:21, Etienne B. Racine wrote:
>>> | I'd like to use a PCL algorithm inside R and they provide a 
>>> CMakeLists.txt for
>>> | configuration. I haven't found how to directly use the 
>>> CMakeLists.txt in
>>> | building R package, however when I run `make .` form src, I can 
>>> generate a
>>> | Makefile  that nearly works with `R CMD INSTALL --no-multiarch`.
>>>
>>> Read up a little on CMake. It is at the end of the "just another" 
>>> frontend /
>>> make replacement.  If you turn on verbose mode, you should be able 
>>> to see all
>>> g++ invocations.
>>>
>>> Which is all you need to mimic in Makevars.
>>>
>>> | It does compile correctly my .cpp, however I get
>>> | `Error in library.dynam(lib, package, package.lib) :  shared object
>>> | ‘my_package.so’ not found`
>>> |
>>> | Here's the CMakeFileLists.txt :
>>> | ```
>>> | cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
>>> |
>>> | find_package(PCL 1.6 REQUIRED)
>>> |
>>> | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} 
>>> -Wno-deprecated-declarations")
>>> |
>>> | include_directories(${PCL_INCLUDE_DIRS})
>>> | link_directories(${PCL_LIBRARY_DIRS})
>>> | add_definitions(${PCL_DEFINITIONS})
>>> |
>>> | add_executable (segmentation segmentation.cpp)
>>> | target_link_libraries (segmentation ${PCL_LIBRARIES})
>>> | ```
>>> | I've seen that using a makefile wasn't the best practice [1] (I 
>>> should move it
>>> | to makevars). Since my CMakeFileLists is apparently simple (e.g. 
>>> compared to
>>> | RInside examples), I guess I could move it to makevars however I'm 
>>> not familiar
>>> | with cmake nor makevars, so I was wondering if there was 
>>> documentation about
>>> | translating from one to the other. However I'm absolutely not sure 
>>> this is the
>>> | real problem (using the CMakeLists.txt).
>>>
>>> Writing Makefile code is yet another little skill one has to acquire 
>>> on the
>>> side once projects get larger.  There is a lot of support though, as 
>>> there
>>> are plenty of examples.
>>>
>>> Nothing really Rcpp-specific here.
>>>
>>> Dirk
>>>
>>> |
>>> | (I'm using R version 2.15.2 (2012-10-26) on x86_64-pc-linux-gnu 
>>> (64-bit),
>>> | building from RStudio.)
>>> |
>>> | Etienne
>>> |
>>> | [1]: http://stackoverflow.com/questions/12976036/
>>> | how-to-use-usedynlib-correctly-in-an-r-package-namespace-file
>>> |
>>> |
>>> |
>>> | 
>>> ----------------------------------------------------------------------
>>> | _______________________________________________
>>> | Rcpp-devel mailing list
>>> | Rcpp-devel at lists.r-forge.r-project.org
>>> | 
>>> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
>>
>> _______________________________________________
>> Rcpp-devel mailing list
>> Rcpp-devel at lists.r-forge.r-project.org
>> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
>
> _______________________________________________
> Rcpp-devel mailing list
> Rcpp-devel at lists.r-forge.r-project.org
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel



More information about the Rcpp-devel mailing list