I'm an experienced C/C++ developer, but I'm extremely green when it comes to dealing with mex in octave. I'm sure I'm missing something basic here, but I can't find what it is.
These are my files:
myhello.cpp
test.cpp
test.h
Here are the contents of the files
(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;
}
So then I launch Octave 4.0.0 through ./run-octave --no-gui, and type the following at the prompt:
mex -v myhello.cpp test.cpp
The response I get is:
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
And I'm once again presented with the prompt.
I type
myhello(1,2,3)
And get this:
error: /home/brush/Documents/mex_tests/myhello.mex: failed to load: /home/brush/Documents/mex_tests/myhello.mex: undefined symbol: _ZN4test10testMethodEv
So obviously something isn't linking properly, but I cannot figure out how to get everything to do so. Sorry, but I've searched for a while and haven't found anything that fixed this simple issue.
Thanks in advance, Ben
P.S. My system is Ubuntu 15.04, 64-bit.
-vto see if there are any more clues. Also, this is a long shot, but try putting#include "mex.h"first. It's like it thinkstestMethodis extern... or dynamically loaded. - chappjcvoid testMethod()be defined in test.CPP innamespace test? - chappjc