MEX compilation with external libraries errors - .lib needed?
Answers (1)
Haven't ever used it myself, but...
The web site installation says...
"MPIR has an autoconf/automake/libtool based conguration system. ... Important note: by default MPIR produces libraries named libmpir, etc., and the header file mpir.h."
If you can compile (and link) externally, then the needed libraries do exist somewhere; your problem is that mex setup doesn't know about external non-TMW libraries and so it doesn't set the LIB environment variable to include that location (nor the INCLUDE path to find header files if they're not in local directory either).
To build this way under mex, you'll have to modify the default mexopts.bat file manually to include those locations needed or set them in an autostart routine so they're globally already included in the startup. Remember that mex spawns a new console process to execute under and that will be a virgin environment that only has those environment variables set that are either explicitly set in the batch file itself or were inherited from the parent.
ADDENDUM
Or, you could use the $COMPFLAGS$/$LINKFLAGS$ option variables when you call mex but that means specifying them every time which is why I suggested first to either modify the mexopts.bat file or add the flags to the base environment if you're going to be using this library a lot.
13 Comments
- You can't build outside mex either, and
- The install didn't succeed in building the libraries it says it should.
"xyntax [of] LINKFLAGS variable in the mexopts.bat file?"
If you look at the [compiler]OPTS.BAT file (where [compiler] is the shorthand name TMW uses for the compiler you're using, that's the base file mex -setup uses when you run the setup option. Setup then copies that file to the $MATLAB$ location for your installation and renames it MEXOPTS.BAT and that then is the file that mex uses for a given compilation.
If you edit that file, you'll see a LINKFLAGS variable that contains the LIBPATH for the default libraries and the list of those; use that pattern to add the additional path you need for LIPMR and the base library it needs.
Again, alternatively, you can use the -L and -l options each time you invoke the base mex opts file.
The other issue appears to be one of name-mangling. I can't really tell from the snippets you've given where what is coming from but it doesn't seem as though there should be any need for any library other than LIPMR if you can build and link with the shown gcc line.
I don't "know nuthink!" much at all about the C compilers (I'm a Fortran guy) but I'm certain there's a way to build a working mex file; it is just a DLL and I'm certain gcc or whatever C compiler you're using can build a DLL.
I don't know what "other hints" you're speaking of, but looking at the gcc compile and link step I don't see any reference to any other libraries so I'm thinking that is a red herring and the problem is you've got a name-mangling issue that you're getting an extra underscore probably.
Have you successfully been able to build and run one or the sample mex routines first? If so, ensure that the compilation switches for that routine are the same as the ones used in the compilation of the additional code.
Categories
Find more on Write C Functions Callable from MATLAB (MEX Files) in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!