在构建链接到NLopt库(http://ab-initio.mit.edu/wiki/index.php/NLopt)的Rcpp包方面,我需要一些帮助。
我在Windows上使用RStudio的“Build&Reload”。
包的\src文件夹中有以下文件:
在这里,我将.lib (使用MinGW构建)和dll文件复制到\src文件夹中,希望R能够自己编译它们。然而,情况似乎并非如此,为此,我添加了一个Makevars文件,尝试链接到库。
在从RStudio运行时,我会收到以下错误消息,我猜想,它告诉我链接存在问题(cf )。)对NLop库的“未定义引用”:
安装到库‘C:/Users/g 49128/Documents/R/win- library /3.2’ 安装源代码包“NewPackage”. ** lib g++ -m64 -shared -s -libgcc -o NewPackage.dll tmp.def RcppExports.o Rcpp_project_test.o -Lc:/Temp/R/Rcpp/NewPackage/src/libnlopt.a -LC:/application/extsoft/lib/x64-LC:/application/extsoft/lib -LC:/PROGRA~1/R/R-32~1.2/bin/x64 -lR -lR未定义为`__imp_nlopt_create‘
因此,我怀疑我没有正确的马克瓦尔斯,不太熟悉这些。
通过查阅几个CRAN包,特别是nloptr,我目前对两个Makevars文件的内容的最佳猜测是:
NLOPT_HOME = c:/Temp/R/Rcpp/NewPackage/src。 KG_CFLAGS = -I"$(NLOPT_HOME)“ PKG_LIBS = -L"$(NLOPT_HOME)/libnlopt.a“
其中'libnlopt.a‘是库,环境变量'NLOPT_HOME’保存到库的路径。
有人能告诉我我在这里错过了什么吗?任何帮助都将不胜感激,谢谢。
发布于 2016-04-28 11:06:12
非洛普包本身能够可靠地做到这一点。它使用以下Makevars.win
# Copyright (C) 2010 Jelmer Ypma. All Rights Reserved.
# This code is published under the L-GPL.
#
# File: Makevars.win
# Author: Jelmer Ypma
# Date: 18 August 2010
#
# 09 June 2011: Windows support added thanks to Stefan Theussl and Uwe Ligges.
# NLOPT_HOME is the directory where a working installation of
# NLopt is located (within subdirectories NLOPT_VERSION/R_ARCH)
# 18 November 2011: Removed NLOPT_VERSION macro and adopted some other changes
# proposed by Brian Ripley to make nloptr work with his new toolchain.
# NLopt should now be located in NLOPT_HOME/R_ARCH (i.e. without
# version number)
# 19 February 2013: NLopt is compiled with --with-cxx option, in order to include
# the StoGo algorithm. This means that we now need to link to
# with -lnlopt_cxx and also link to the c++ library, -lstdc++.
# 7 November 2013: Changed PKG_CPPFLAGS to PKG_CFLAGS.
# 2 May 2014: Added quotes around include paths to allow for spaces in NLOPT_HOME.
# C Compiler options
PKG_CFLAGS = -I"$(NLOPT_HOME)$(R_ARCH)/include"
PKG_LIBS = -L"$(NLOPT_HOME)$(R_ARCH)/lib" -lnlopt_cxx要求您拥有正确的NLOPT_HOME变量集。
您有时可以从CRAN支持站点下载相应的预构建库,但我在这里没有看到这一点。
https://stackoverflow.com/questions/36909850
复制相似问题