mex: linker does not seem to be able to access external lib file; -l & -L options not helping

4 views (last 30 days)
For a project for college I need to write an S-Function in Matlab to acquire data from a data acquisition device (NI USB-6008).
I've been reading the on-line help and I've successfully compiled a simple S-Function.
Then I added to my basic S-Function (NI_USB_6008_AnalogInput.c):
#include "NIDAQmx.h"
and then added this declaration to the function 'mdlOutputs':
TaskHandle taskHandle = 0;
(The 'TaskHandle' type is declared in the header file above.)
That compiles.
However, when I try to call a function from the NIDAQmx library:
DAQmxCreateTask("", taskHandle);
I get the following error:
>> mex NI_USB_6008_AnalogInput.c
Writing library for NI_USB_6008_AnalogInput.mexw32
c:\docume~1\l10\config~1\temp\ni_usb_6008_analoginput.obj .text:
undefined reference to '_DAQmxCreateTask@8'
C:\ARCHIVOS DE PROGRAMA\MATLAB\R2006A\BIN\MEX.PL: Error: Link of
'NI_USB_6008_AnalogInput.mexw32' failed.
??? Error using ==> mex
Unable to complete successfully
(I tried two compilers: the default one, LCC, and MS Visual C++ 2005, the error is similar with both of them.)
The problem, I understand, is that the compiler generates an object file with the correct reference to the function I'm trying to call, but then the linker is unable to access that function from the NIDAQmx.lib library. (Both the header and the library files are in the same directory as the source file.)
I tried using the -l and -L options to MEX and adding the .lib file at the end of the mex command, but I still get the same error message.
(I shuold add that I could successfully compile a simple C file with calls to the NIDAQmx library using MS Visual C++ 2005, but in Matlab I get the linker error, even when Matlab is configured to use the MS compiler.)
Can anyone suggest a solution?
FWIW, I'm running Matlab R2006a (7.2) on Windows XP with SP2.
Thank you.
Ignacio

Accepted Answer

Ignacio
Ignacio on 17 Aug 2012
For lack of a better solution, here's what I'm doing.
I removed the following libraries:
  • user32.lib
  • gdi32.lib
  • winspool.lib
  • comdlg32.lib
  • advapi32.lib
  • shell32.lib
  • ole32.lib
  • oleaut32.lib
  • uuid.lib
  • odbc32.lib
  • odbccp32.lib
from this file:
C:\Documents and Settings\{USER}\Application Data\MathWorks\MATLAB\R2006a\mexopts.bat
Using MS Visual C++ 2005 it compiles correctly.
The correct way to do it would be to make the compiler/linker see the libraries above. It's not clear to me why it cannot access them, but I haven't looked much into it. What I just described is a quick & dirty solution. Hope it helps someone else who runs into this problem -- at least to get things to work!

More Answers (1)

Titus Edelhofer
Titus Edelhofer on 27 Jul 2012
Hi,
you are right, you need the -l and -L. Your call should look something like
mex NI_USB_6008_AnalogInput.c -Lc:\someFolder -lsomLibrary.lib
Second, I would compile using verbose mode, i.e.
mex -v ...
to see in more detail what happens. Please try both (again) and tell us what happens, or what error comes up ...
Titus
  6 Comments
Titus Edelhofer
Titus Edelhofer on 30 Jul 2012
Hi Ignacio,
I'm sorry but I have to admit I don't know any further. If you followed the advice about the Platform SDK, I don't know what to do next except for trying to contact MathWorks support...
Titus
Ignacio
Ignacio on 30 Jul 2012
Thank you, Titus. I really appreciate your input.
I will follow your advice and contact MathWorks support. I will come back to this thread when I have a solution.
Ignacio

Sign in to comment.

Categories

Find more on MATLAB Compiler in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!