Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > How to compile and link several c++ files with *mex*

Reply
Thread Tools

How to compile and link several c++ files with *mex*

 
 
xz
Guest
Posts: n/a
 
      03-14-2008
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?
 
Reply With Quote
 
 
 
 
red floyd
Guest
Posts: n/a
 
      03-14-2008
xz wrote:
> I am programming some c++ codes to be called within Matlab.
>
> I[redacted]


Any specifics on compilation options, etc.. are OT.

Try comp.soft-sys.matlab
 
Reply With Quote
 
 
 
 
ngoonee@gmail.com
Guest
Posts: n/a
 
      03-15-2008
On Mar 15, 12:26 am, xz <(E-Mail Removed)> wrote:
> 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?


This really is a Matlab question, not a c++ question. However, I do
recall that the Matlab documentation covers the issue of multiple
files being mex-ed. I've done a project before and the documentation
there was really everything I ever needed.

The alternative idea (and the method I'm using now) is to use a third-
party compiler. I'm using Visual Studio, and specific instructions are
available for it in the Matlab documentation (been doing it for a
couple of years). I'm pretty sure its possible with gcc and the like
as well, perhaps you should go looking around the documentation for
more information.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Is there a way to "link" a python program from several files? Edward A. Falk Python 10 03-04-2008 07:06 AM
RDOC: several related modules in several C files Victor \Zverok\ Shepelev Ruby 3 03-16-2007 04:15 PM
cant compile on linux system.cant compile on cant compile onlinux system. Nagaraj C++ 1 03-01-2007 11:18 AM
Re: Link Link Link DANGER WILL ROBINSON!!! Kevin Spencer ASP .Net 0 05-17-2005 10:41 AM



Advertisments