Jump to content

As of July 17, 2015, the LabJack forums here at forums.labjack.com are shut down. New registrations, topics, and replies are disabled. All forums are in a read-only state for archive purposes.

Please visit our current forums at labjack.com/forums to view and make new posts. To post on the current forums, use your labjack.com login account. Your old LabJack forums login credentials have been retired. There are no longer separate logins for labjack.com and LabJack forums.


Photo

Compling mex files to run U12 in MATLAB


  • Please log in to reply
11 replies to this topic

#1 Martha

Martha
  • Members
  • 4 posts

Posted 05 February 2013 - 09:07 AM

Hi all, I've been banging my head against this for a while and was wondering if anyone could help me. I have the .dll and .cpp files for all the functions needed to run the labjack U12 through MATLAB. I also have the ljackuw.h and ljackuw.lib files. I'm using Windows 7 and Microsoft Software Development Kit (SDK) 7.1. When I attempt to compile the mex files (eg AISample here) I get the following error: mex C:\MATLAB\LabJack\AISample.cpp -L"C:\MATLAB\LabJack\ljackuw.lib" AISample.obj : error LNK2019: unresolved external symbol AISample referenced in function mexFunction AISample.mexw64 : fatal error LNK1120: 1 unresolved externals C:\MATLAB\BIN\MEX.PL: Error: Link of 'AISample.mexw64' failed. Is there anything obvious I'm doing wrong here? Thanks, Martha

#2 MCT Support

MCT Support
  • Members
  • 16 posts

Posted 05 February 2013 - 10:38 AM

Hi Martha, It's been a while since I've looked at mex functions, but I'll see if there is anything I can do. What version of Matlab are you using?

#3 Martha

Martha
  • Members
  • 4 posts

Posted 06 February 2013 - 04:43 AM

I'm using MATLAB 2012b

#4 MCT Support

MCT Support
  • Members
  • 16 posts

Posted 08 February 2013 - 03:17 PM

Do you have to compile mex functions for your application? Have you looked at the loadlibrary function which allows you to load the library directly inside Matlab? loadlibrary(libname,hfile) loadlibrary(libname,hfile,Name,Value) A quick search on the linker error you are seeing (2019) indicates some compiler options not quite right (assuming a .NET compiler). Take a look at the MSDN (http://msdn.microsoft.com) website and look up the linker error you are getting and see if it helps you out any. Sometimes getting the correct compiler options can be tricky.

#5 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 08 February 2013 - 03:21 PM

Hi all,

I've been banging my head against this for a while and was wondering if anyone could help me. I have the .dll and .cpp files for all the functions needed to run the labjack U12 through MATLAB. I also have the ljackuw.h and ljackuw.lib files.

I'm using Windows 7 and Microsoft Software Development Kit (SDK) 7.1. When I attempt to compile the mex files (eg AISample here) I get the following error:

mex C:\MATLAB\LabJack\AISample.cpp -L"C:\MATLAB\LabJack\ljackuw.lib"


AISample.obj : error LNK2019: unresolved external symbol AISample referenced in function mexFunction
AISample.mexw64 : fatal error LNK1120: 1 unresolved externals

C:\MATLAB\BIN\MEX.PL: Error: Link of 'AISample.mexw64' failed.


Is there anything obvious I'm doing wrong here?

Thanks,

Martha


Is it a 64-bit version of Matlab? You might need the 64-bit version of the .dll which can be found here. Just place that in the C:\windows\system32 folder (if it is 64-bit that is where Windows keeps 64-bit .dlls).

#6 Martha

Martha
  • Members
  • 4 posts

Posted 13 February 2013 - 09:03 AM

Thank you - using loadlibrary and calllib (along with defining the arguments as int32 or Single pointers) allows me to run the U12 from MATLAB.

#7 pierre

pierre
  • Members
  • 4 posts

Posted 04 April 2013 - 06:07 AM

Hi, I have the same problem. Matlab displays this error message: >> loadlibrary('ljackuw', header) Error using loadlibrary>lFullPath (line 586) Could not find file C:\Program Files\LabJack\drivers\ljackuw.h. Error in loadlibrary (line 220) header=lFullPath(header); Someone have a idea? Thanks

#8 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 04 April 2013 - 04:11 PM

Hi,

I have the same problem. Matlab displays this error message:


>> loadlibrary('ljackuw', header)
Error using loadlibrary>lFullPath (line 586)
Could not find file C:\Program Files\LabJack\drivers\ljackuw.h.

Error in loadlibrary (line 220)
header=lFullPath(header);


Someone have a idea?

Thanks


The most likely case is the path has changed. First, you should make sure our installer has been used and the LabJack driver/library is on the system. You can get that here: http://labjack.com/s...12SetupV121.exe

If that has been done there should be a LabJack Legacy folder in the start menu. Next, you should find the ljackuw.h file installed there. The new path is likely something like:

C:\Program Files\LabJackU12Legacy\drivers\ljackuw.h on 32-bit system or:
C:\Program Files (x86)\LabJackU12Legacy\drivers\ljackuw.h. on 64-bit ones.

Once you know the path you will need to change the .m file that references it to point that location.

Matlab is really picky about this kind of stuff (for no good reason) and thus we have been looking at alternative options. One that we have found so far is using .NET components in Matlab which the newer versions support. We just created some examples for that which I have attached in a .zip file.

By using our .NET wrapper to the ljackuw.dll library you don't need to fuss with any compiler tools or anything else. The only change needed to the attached .m file is to extract it and the .dll somewhere and then put the path of the LJDotNet.dll into the .m file. It should be much simpler. If this is a solution that people like, we will create other examples for it (maybe as soon as tomorrow). If you call methodsview(lj.LabJack) after the library is loaded you can get a list of functions with parameter types & return lists.

Attached Files



#9 pierre

pierre
  • Members
  • 4 posts

Posted 05 April 2013 - 06:19 AM

When I call methodsview(lj.LabJack) I can get the list of functions but when I try to run the program, I have this error message: Error using analogIn (line 40) Message: Impossible de charger la DLL 'ljackuw.dll': Le module spécifié est introuvable. (Exception de HRESULT : 0x8007007E) Source: LJDotNet HelpLink: I try with another function and I have the same message. Do you have a idea? Thanks

#10 pierre

pierre
  • Members
  • 4 posts

Posted 05 April 2013 - 06:35 AM

When I use the files .mexw64 it works but I can only use the functions EAnalogIn, Out and EDigitalIN, Out.

#11 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 05 April 2013 - 01:00 PM

When I call methodsview(lj.LabJack) I can get the list of functions but when I try to run the program, I have this error message:

Error using analogIn (line 40)
Message: Impossible de charger la DLL 'ljackuw.dll': Le module spécifié est
introuvable. (Exception de HRESULT : 0x8007007E)
Source: LJDotNet
HelpLink:

I try with another function and I have the same message. Do you have a idea?

Thanks


It is probably missing the ljackuw.dll, which is strange since the other functions work. There should be two copies, one (32-bit) in the C:\windows\SysWOW64\ folder and one (64-bit) in the C:\windows\System32 folder.

Can you check and see if both of those exist?

#12 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 11 November 2013 - 02:45 PM

 

Hi,

I have the same problem. Matlab displays this error message:


>> loadlibrary('ljackuw', header)
Error using loadlibrary>lFullPath (line 586)
Could not find file C:\Program Files\LabJack\drivers\ljackuw.h.

Error in loadlibrary (line 220)
header=lFullPath(header);


Someone have a idea?

Thanks


The most likely case is the path has changed. First, you should make sure our installer has been used and the LabJack driver/library is on the system. You can get that here: http://labjack.com/s...12SetupV121.exe

If that has been done there should be a LabJack Legacy folder in the start menu. Next, you should find the ljackuw.h file installed there. The new path is likely something like:

C:\Program Files\LabJackU12Legacy\drivers\ljackuw.h on 32-bit system or:
C:\Program Files (x86)\LabJackU12Legacy\drivers\ljackuw.h. on 64-bit ones.

Once you know the path you will need to change the .m file that references it to point that location.

Matlab is really picky about this kind of stuff (for no good reason) and thus we have been looking at alternative options. One that we have found so far is using .NET components in Matlab which the newer versions support. We just created some examples for that which I have attached in a .zip file.

By using our .NET wrapper to the ljackuw.dll library you don't need to fuss with any compiler tools or anything else. The only change needed to the attached .m file is to extract it and the .dll somewhere and then put the path of the LJDotNet.dll into the .m file. It should be much simpler. If this is a solution that people like, we will create other examples for it (maybe as soon as tomorrow). If you call methodsview(lj.LabJack) after the library is loaded you can get a list of functions with parameter types & return lists.

 

 

To update our U12 MATLAB support, we now provide MATLAB .NET examples on our site:

 

http://labjack.com/s...examples/matlab

 

It provides a couple more examples than the U12Matlab.zip download and a helpful README file.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users