将C代码编译到SO中时找不到RH的功能
我正在尝试通过一些更改将R代码转换为Python。问题在于,R的某些基础代码是用C编写的,并具有.c('函数')函数类型。
我无法在C中进行编码,因此我决定编译一个.So文件,因此我可以在Python代码中使用该功能。但是,在编译.SO文件时,我会遇到问题。看来,当我编译时,C找不到应该包含的几个功能。因此,我会收到以下错误。
Undefined symbols for architecture x86_64:
"_Rf_revsort", referenced from:
_sort_univ_surv_index_double in survivalBIV_test-466caf.o
"_rsort_with_index", referenced from:
_KaplanMeierValueSort in survivalBIV_test-466caf.o
_KaplanMeierVectorSort in survivalBIV_test-466caf.o
_WeightsNNE in survivalBIV_test-466caf.o
_BivDistIPCW in survivalBIV_test-466caf.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
现在,我尝试在r/include
文件夹中找到此文件,并找到了包含以下代码的文件r_ext/utils.h
,
/* Included by R.h: API */
#ifndef R_EXT_UTILS_H_
#define R_EXT_UTILS_H_
#include <R_ext/Boolean.h>
#include <R_ext/Complex.h>
#if defined(__cplusplus) && !defined(DO_NOT_USE_CXX_HEADERS)
# include <cstddef>
# define R_SIZE_T std::size_t
#else
# include <stddef.h>
# define R_SIZE_T size_t
#endif
#define revsort Rf_revsort
#define iPsort Rf_iPsort
#define rPsort Rf_rPsort
#define cPsort Rf_cPsort
#define IndexWidth Rf_IndexWidth
#define setIVector Rf_setIVector
#define setRVector Rf_setRVector
#define StringFalse Rf_StringFalse
#define StringTrue Rf_StringTrue
#define isBlankString Rf_isBlankString
#ifdef __cplusplus
extern "C" {
#endif
/* ../../main/sort.c : */
void R_isort(int*, int);
void R_rsort(double*, int);
void R_csort(Rcomplex*, int);
void rsort_with_index(double *, int *, int);
void revsort(double*, int*, int);/* reverse; sort i[] alongside */
void iPsort(int*, int, int);
void rPsort(double*, int, int);
void cPsort(Rcomplex*, int, int);
因此我可以看到这些功能是在此处定义的,但没有明确定义,因为我看不到他们实际上在做什么。他们可能是从其他地方出口的。
我为何在C汇编过程中找不到这些功能而失去了我的失落,并且无法理解如何手动找到这些功能以完全了解它们的工作。有人有任何想法吗?
I am trying to convert R code into Python with some changes. The problem is that some of the underlying code for R is written in C and has .C('function') type of function.
I can't code in C, so I decide to compile an .so file, so I could use the function from there in my Python code. However, I am encountering a problem when compiling the .so file. It seems that couple of functions that are supposed to be included in R.h are not found by C when I am compiling. So I get the following error.
Undefined symbols for architecture x86_64:
"_Rf_revsort", referenced from:
_sort_univ_surv_index_double in survivalBIV_test-466caf.o
"_rsort_with_index", referenced from:
_KaplanMeierValueSort in survivalBIV_test-466caf.o
_KaplanMeierVectorSort in survivalBIV_test-466caf.o
_WeightsNNE in survivalBIV_test-466caf.o
_BivDistIPCW in survivalBIV_test-466caf.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Now, I have tried to locate this files in the R/include
folder and found the file R_ext/Utils.h
which contains the following code
/* Included by R.h: API */
#ifndef R_EXT_UTILS_H_
#define R_EXT_UTILS_H_
#include <R_ext/Boolean.h>
#include <R_ext/Complex.h>
#if defined(__cplusplus) && !defined(DO_NOT_USE_CXX_HEADERS)
# include <cstddef>
# define R_SIZE_T std::size_t
#else
# include <stddef.h>
# define R_SIZE_T size_t
#endif
#define revsort Rf_revsort
#define iPsort Rf_iPsort
#define rPsort Rf_rPsort
#define cPsort Rf_cPsort
#define IndexWidth Rf_IndexWidth
#define setIVector Rf_setIVector
#define setRVector Rf_setRVector
#define StringFalse Rf_StringFalse
#define StringTrue Rf_StringTrue
#define isBlankString Rf_isBlankString
#ifdef __cplusplus
extern "C" {
#endif
/* ../../main/sort.c : */
void R_isort(int*, int);
void R_rsort(double*, int);
void R_csort(Rcomplex*, int);
void rsort_with_index(double *, int *, int);
void revsort(double*, int*, int);/* reverse; sort i[] alongside */
void iPsort(int*, int, int);
void rPsort(double*, int, int);
void cPsort(Rcomplex*, int, int);
So, I can see that these functions are defined here but not explicitly as I can't see what they actually do. They are probably exported from somewhere else.
I am lost as to why these functions are not found during C compilation and can't understand how to find these functions manually to understand exactly what they do. Does anybody have any idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论