X
xz
I am programming some c++ codes to be called within Matlab.
If there is only one c++ file, life is simple. You simply mex the cpp
file (
with mexFunction(...) )and call the function within Matlab.
However, if you have several c++/h files, then what's standard
procedure to
compile and link the files?
for example, I have:
A.cpp (which contains the mexFunction and includes B.h)
B.h (contains the declarations of some data structures used in A.cpp)
B.cpp (implementation of the data structures declared in B.h)
The weird thing I found is that if you simply run:
mex B.cpp
It just compiles without complaining there is no mexFunction() or
main(),
which is not like the case if you gcc some c++ file without a main()
and
without using the option -c.
If you run
mex A.cpp
It also compiles without complaining that some function called in A
(defined
in B) has not be defined.
If you run
mex A.cpp B.cpp
you get an A.mexa64. However, when I call this A within Matlab, it
seems
like the functions defined in B and called in A are ignored without
being
called.
Anyway, I don't think I am compiling or linking in a correct way. "mex
--help" does not help very much.
Can you guys give some ideas about the compiling and linking of c++
with mex?
If there is only one c++ file, life is simple. You simply mex the cpp
file (
with mexFunction(...) )and call the function within Matlab.
However, if you have several c++/h files, then what's standard
procedure to
compile and link the files?
for example, I have:
A.cpp (which contains the mexFunction and includes B.h)
B.h (contains the declarations of some data structures used in A.cpp)
B.cpp (implementation of the data structures declared in B.h)
The weird thing I found is that if you simply run:
mex B.cpp
It just compiles without complaining there is no mexFunction() or
main(),
which is not like the case if you gcc some c++ file without a main()
and
without using the option -c.
If you run
mex A.cpp
It also compiles without complaining that some function called in A
(defined
in B) has not be defined.
If you run
mex A.cpp B.cpp
you get an A.mexa64. However, when I call this A within Matlab, it
seems
like the functions defined in B and called in A are ignored without
being
called.
Anyway, I don't think I am compiling or linking in a correct way. "mex
--help" does not help very much.
Can you guys give some ideas about the compiling and linking of c++
with mex?