【发布时间】:2015-07-03 19:30:49
【问题描述】:
我是一位经验丰富的 C/C++ 开发人员,但在处理 octave 中的 mex 时,我是非常绿色的。我确定我在这里遗漏了一些基本的东西,但我找不到它是什么。
这些是我的文件:
myhello.cpp
test.cpp
test.h
这是文件的内容
(myhello.cpp):
#include "test.h"
#include "mex.h"
using namespace test;
void
mexFunction (int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[])
{
mexPrintf ("Hello, World!\n");
testMethod();
mexPrintf ("I have %d inputs and %d outputs\n", nrhs, nlhs);
}
(test.h)
namespace test
{
void testMethod();
}
(test.cpp)
#include "test.h"
#include <iostream>
using namespace std;
using namespace test;
void testMethod()
{
cout << "this works." << endl;
}
然后我通过 ./run-octave --no-gui 启动 Octave 4.0.0,并在提示符下键入以下内容:
mex -v myhello.cpp test.cpp
我得到的回应是:
g++ -c -fPIC -I/usr/local/include/octave-4.0.0/octave/.. -I/usr/local/include/octave-4.0.0/octave -I/usr/local/include -pthread -fopenmp -g - O2-I。 myhello.cpp -o myhello.o g++ -c -fPIC -I/usr/local/include/octave-4.0.0/octave/.. -I/usr/local/include/octave-4.0.0/octave -I /usr/local/include -pthread -fopenmp -g -O2 -I。 test.cpp -o test.o g++ -shared -Wl,-Bsymbolic -o myhello.mex myhello.o test.o -L/usr/local/lib/octave/4.0.0 -L/usr/local/lib - loctinterp -loctave
我再次看到提示。
我输入
我的你好(1,2,3)
得到这个:
错误:/home/brush/Documents/mex_tests/myhello.mex:加载失败: /home/brush/Documents/mex_tests/myhello.mex:未定义符号: _ZN4test10testMethodEv
所以显然有些东西没有正确链接,但我不知道如何让所有东西都这样做。抱歉,但我已经搜索了一段时间,但没有找到任何解决这个简单问题的方法。
提前致谢, 本
附:我的系统是 Ubuntu 15.04,64 位。
【问题讨论】:
-
试试
-v看看有没有更多线索。此外,这是一个很长的镜头,但请尝试将#include "mex.h"放在首位。就好像它认为testMethod是外部的……或者是动态加载的。 -
等等,
void testMethod()不应该在namespace test的 test.CPP 中定义吗? -
@chappjc 我在代码中遇到了一些奇怪的奇怪错误(我通常在 Microsoft Visual Studio 中工作),但要让 mex 编译,我必须在开头包含命名空间test.cpp 文件,然后定义函数。
标签: c++ namespaces octave mex