2017-09-29 50 views
0

我正在使用Rcpp,我試圖讓我的Makevars文件被寫入爲可移植的。最初,這是我的文件:Rcpp Makevars:portable -mpopcnt flag

PKG_CXXFLAGS = -std=c++11 -mpopcnt 
PKG_CXX1XFLAGS = $(PKG_CXXFLAGS) 

然後我修改了它,所以我可以做C++ 11標誌便攜:

CXX_STD = CXX11 
PKG_CXXFLAGS = -mpopcnt 
PKG_CXX1XFLAGS = $(PKG_CXXFLAGS) 

然而,-mpopcnt不是便攜式標誌。有沒有解決這個問題?

回答

1

您可以通過configure ---這可以是任何可執行的頂級腳本玩有些偷偷摸摸的技巧。如果你有它,也就不用擔心autoconf(我應該補充說我非常喜歡那些工具)。

因此,configure可以只是一個shell腳本,或者甚至是一個通過#!/usr/bin/Rscript執行的R腳本,您可以在其中測試OS和/或編譯器。當且僅當星星對齊時加上-mpopcnt,否則你不會。

而且,你是兼容的。

我的博客上講述的是同樣的想法,一旦in this post它有這個例子刪除一個C++ 14開關:

#!/bin/bash 

## Travis can let us run R 3.4.0 (from CRAN and the PPAs) but this R version 
## does not know about C++14. Even though we can select CXX_STD = C++14, R 
## will fail as the version we use there was built in too old an environment, 
## namely Ubuntu "trusty" 14.04. 
## 
## So we install g++-6 from another repo and rely on the fact that is 
## defaults to C++14. Sadly, we need R to not fail and hence, just on 
## Travis, remove the C++14 instruction 

if [[ "${CI}" == "true" ]]; then 
    if [[ "${TRAVIS}" == "true" ]]; then 
     echo "** Overriding src/Makevars and removing C++14 on Travis only" 
     sed -i 's|CXX_STD = CXX14||' src/Makevars 
    fi 
fi 

您可以使用完全相同的邏輯添加要開關加。