我正在尝试使用模板类链接到共享库,但它给了我"未定义的符号"错误.我已经将问题浓缩为大约20行代码.
shared.h
template <class Type> class myclass {
Type x;
public:
myclass() { x=0; }
void setx(Type y);
Type getx();
};
Run Code Online (Sandbox Code Playgroud)
shared.cpp
#include "shared.h"
template <class Type> void myclass<Type>::setx(Type y) { x = y; }
template <class Type> Type myclass<Type>::getx() { return x; }
Run Code Online (Sandbox Code Playgroud)
main.cpp中
#include <iostream>
#include "shared.h"
using namespace std;
int main(int argc, char *argv[]) {
myclass<int> m;
cout << m.getx() << endl;
m.setx(10);
cout << m.getx() << endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这是我编译库的方式:
g++ -fPIC -c shared.cpp -o …
Run Code Online (Sandbox Code Playgroud) 我想让我的用户创建Ruby脚本,对驻留在Web服务器上的某些数据进行计算,然后输出结果.脚本在服务器上执行.有没有办法安全地做到这一点?
更具体地说,我想:
是否有任何图书馆或项目可以满足我的要求?如果不是在Ruby中,也许还有其他语言?
我有一个C++库repeater.so
,我可以通过以下方式从Linux加载Python:
import numpy as np
repeater = np.ctypeslib.load_library('librepeater.so', '.')
Run Code Online (Sandbox Code Playgroud)
但是,当我在Mac OS X(Snow Leopard,32位)上编译相同的库并获取repeater.dylib
,然后在Python中运行以下内容时:
import numpy as np
repeater = np.ctypeslib.load_library('librepeater.dylib', '.')
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
OSError: dlopen(/mydir/librepeater.dylib, 6): no suitable image found. Did find:
/mydir/librepeater.dylib: mach-o, but wrong architecture
Run Code Online (Sandbox Code Playgroud)
在Mac OS X上,我是否必须采用不同的方法在Python中加载动态库?