LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Creating mex-files with gcc with external libraries (matlab) (https://www.linuxquestions.org/questions/linux-software-2/creating-mex-files-with-gcc-with-external-libraries-matlab-865917/)

Reicher 03-02-2011 05:24 AM

Creating mex-files with gcc with external libraries (matlab)
 
Hi, I have been browsing trough forums, manuals and people for a few days now wihout success so I thought i give this a go, any help will be very appricieted!

I'm using Matlab 2010a in Ubuntu 10.10. I also have a AVT Marlin F033C firewire camera and want to use the two together. Since most things i will do with the images will be processed in matlab I decided that the best would be if i could do everything in matlab.

The code for capturing a picture is however in c and uses the library dc1394 (usr/lib). Compiling this with gcc works good:
$ gcc grab_gray_image.c -ldc1394

To be able to create a mex-file of it (that matlab can run) I have included "mex.h" in the headers and added the function mexFunction in the very top, this function should do more once it works...:
#include "mex.h"

void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
mexErrMsgTxt("STUFFNTHINGS");
}

In matlab, after doing the:
>> mex -setup
Choosing "Template Options file for building gcc MEX-files".

When trying to compile i get a few errors but these are easily removed by taking away all the //-comments and all the inline for a few functions (this should do anything for the functionality right?).
After that I am still stuck with this error:

>> mex grab_gray_image.c -ldc1394
/usr/bin/ld: cannot find -lstdc++
collect2: ld returned 1 exit status

mex: link of ' "grab_gray_image.mexa64"' failed.

??? Error using ==> mex at 222
Unable to complete successfully.


I should probably also note that I needed to rollback to gcc 4.1 since that is the latest one matlab 2010a can handle and now don't get that warning anymore.

So, anyone have any idea? I don't even know what this stdc++ is for really=/

knudfl 03-02-2011 06:31 AM

Welcome to LQ.

Quote:

I don't even know what this stdc++ is for really
lstdc++ = libstdc++ >> libstdc++.so
'libstdc++' is the c++ library included in gcc / g++.

sudo apt-get install g++ :
Will install the libstdc++6<.x.x>-dev for your version of Ubuntu.
Providing like : /usr/lib/gcc/i686-linux-gnu/4.4/libstdc++.so
( It may already be installed.)

Just point to it. (Or make a (temporary) link to /usr/lib/).

..

Reicher 03-02-2011 08:23 AM

Quote:

Originally Posted by knudfl (Post 4276190)
Welcome to LQ.



lstdc++ = libstdc++ >> libstdc++.so
'libstdc++' is the c++ library included in gcc / g++.

sudo apt-get install g++ :
Will install the libstdc++6<.x.x>-dev for your version of Ubuntu.
Providing like : /usr/lib/gcc/i686-linux-gnu/4.4/libstdc++.so
( It may already be installed.)

Just point to it. (Or make a (temporary) link to /usr/lib/).

..

After some more playing around with libstdc++ and pointing to diffrent versions of this library it worked with:
mex grab_gray_image.c -ldc1394 -L"/usr/lib/gcc/x86_64-linux-gnu/4.4"

Thank you very much!

Evil85 03-14-2011 04:58 PM

Quote:

Originally Posted by Reicher (Post 4276291)
After some more playing around with libstdc++ and pointing to diffrent versions of this library it worked with:
mex grab_gray_image.c -ldc1394 -L"/usr/lib/gcc/x86_64-linux-gnu/4.4"

Thank you very much!

did you have any linking problem ?

Because I use Ubuntu 10.10 and Matlab 2010a with gcc 4.4 and eclipse I see now that it's very newer.
Matlab 2010a support 4.2.3 but I cant it in repositories :(
And I have a big linking error :

/usr/bin/ld: warning: libicudata.so.40, needed by /home/evil/Matlab2010a/bin/glnxa64/libmx.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: libicuuc.so.40, needed by /home/evil/Matlab2010a/bin/glnxa64/libmx.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: libicui18n.so.40, needed by /home/evil/Matlab2010a/bin/glnxa64/libmx.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: libicuio.so.40, needed by /home/evil/Matlab2010a/bin/glnxa64/libmx.so, not found (try using -rpath or -rpath-link)

.....

knudfl 03-14-2011 05:37 PM

Evil85, post # 4 : Welcome to LQ. .. Ubuntu 10.10 Maverick 64bits :

Adding 'karmic' to /etc/apt/sources.list will make it possible to do :

sudo apt-get update && sudo apt-get install gcc-4.2 libicu40
( You can have as many compilers installed at the same time, as you want.)
'gcc-4.2', 'g++-4.2', libicu40 will install with no problems.
Code:

deb http://76.73.4.58/ubuntu/ karmic main
deb http://76.73.4.58/ubuntu/ karmic universe
deb http://security.ubuntu.com/ubuntu karmic-security main
deb http://security.ubuntu.com/ubuntu karmic-security universe

EDIT : gcc should probably be gcc-4.1 ?

..


All times are GMT -5. The time now is 03:14 AM.