gpt4 book ai didi

c++ - 初学者应对 Octave 音阶和 mex 问题

转载 作者:行者123 更新时间:2023-11-30 05:41:15 25 4
gpt4 key购买 nike

我是一位经验丰富的 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);
}

(测试.h)

namespace test
{
void testMethod();
}

(测试.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

我再次收到提示。

我输入

myhello(1,2,3)

然后得到这个:

error: /home/brush/Documents/mex_tests/myhello.mex: failed to load: /home/brush/Documents/mex_tests/myhello.mex: undefined symbol: _ZN4test10testMethodEv

很明显有些东西没有正确链接,但我不知道如何让一切都这样做。抱歉,我已经搜索了一段时间,但没有找到任何可以解决这个简单问题的方法。

提前致谢,本

附言我的系统是 Ubuntu 15.04,64 位。

最佳答案

除非我在 namespace test 中定义 void testMethod(),否则我什至无法在 VS2013 中编译(实际上是链接)。这有效:

//test.cpp
#include "test.h"
#include <iostream>

using namespace std;

namespace test
{
void testMethod()
{
cout << "this works." << endl;
}
}

没有namespace test{ ... },有未解析的符号:

myhello.obj : error LNK2019: unresolved external symbol "void __cdecl test::testMethod(void)"

当它工作时,我得到:

>> myhello
Hello, World!
I have 0 inputs and 0 outputs

关于c++ - 初学者应对 Octave 音阶和 mex 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31213178/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com