mex compilation errors - undefined symbols for x86_64 | LabJack
 

mex compilation errors - undefined symbols for x86_64

4 posts / 0 new
Last post
matlaw
matlaw's picture
mex compilation errors - undefined symbols for x86_64

I'm trying to get my LabJack u3 working with matlab on a mac.  I didn't realize the matlab support was mainly for windows and I'm by no means a c programmer, so that usually means I try something, look up the generated error and/or write inane questions to forums while trying to figure things out.

So I have the U3 examples that came with the mac installation of the exodriver compiling in C through the makefile and was hoping that it would be somewhat straightforward to compile this code with mex to run in matlab.   I'm at a bit of a loss how to convert the makefile to mex format so am trying to just compile an individual c program.  When I try (I can't seem to get libraries to work with mex, so leaving those off for now):

mex -largeArrayDims u3Stream.c

I get the following:

Building with 'Xcode with Clang'.

Error using mex

Undefined symbols for architecture x86_64:

  "_LJUSB_Read", referenced from:

      _ConfigIO_example in u3Stream.o

      _StreamStop in u3Stream.o

      _StreamConfig_example in u3Stream.o

      _StreamStart in u3Stream.o

  "_LJUSB_Stream", referenced from:

      _StreamData_example in u3Stream.o

  "_LJUSB_Write", referenced from:

      _ConfigIO_example in u3Stream.o

      _StreamStop in u3Stream.o

      _StreamConfig_example in u3Stream.o

      _StreamStart in u3Stream.o

  "_closeUSBConnection", referenced from:

      _main in u3Stream.o

  "_extendedChecksum", referenced from:

      _ConfigIO_example in u3Stream.o

      _StreamConfig_example in u3Stream.o

  "_extendedChecksum16", referenced from:

      _ConfigIO_example in u3Stream.o

      _StreamConfig_example in u3Stream.o

      _StreamData_example in u3Stream.o

  "_extendedChecksum8", referenced from:

      _ConfigIO_example in u3Stream.o

      _StreamConfig_example in u3Stream.o

      _StreamData_example in u3Stream.o

  "_getAinVoltCalibrated", referenced from:

      _StreamData_example in u3Stream.o

  "_getAinVoltCalibrated_hw130", referenced from:

      _StreamData_example in u3Stream.o

  "_getCalibrationInfo", referenced from:

      _main in u3Stream.o

  "_getTickCount", referenced from:

      _StreamData_example in u3Stream.o

  "_mexFunction", referenced from:

     -exported_symbol[s_list] command line option

  "_normalChecksum8", referenced from:

      _StreamStop in u3Stream.o

      _StreamStart in u3Stream.o

  "_openUSBConnection", referenced from:

      _main in u3Stream.o

ld: symbol(s) not found for architecture x86_64

clang: error: linker command failed with exit code 1 (use -v to see invocation)

LabJack Support
LabJack Support's picture
The undefined symbols

The undefined symbols indicate the compiler can't find those functions. u3Stream.c requires u3.c and links to liblabjackusb.dylib. See if something like this works:

mex -largeArrayDims -llabjackusb u3Stream.c u3.c

You may need to include the header files (u3.h and labjackusb.h) to your list of files. If -llabjackusb doesn't work, try -lliblabjackusb instead.

matlaw
matlaw's picture
Definitely getting closer:

Definitely getting closer:

mex -largeArrayDims -llabjackusb u3Stream.c u3.c

Building with 'Xcode with Clang'.

Error using mex

Undefined symbols for architecture x86_64:

  "_mexFunction", referenced from:

     -exported_symbol[s_list] command line option

ld: symbol(s) not found for architecture x86_64

clang: error: linker command failed with exit code 1 (use -v to see invocation)

matlaw
matlaw's picture
So if I copy a generic file

So if I copy a generic file called mexFunction.c (found from a search on matlab mexFunction.c) to the directory I'm trying to compile in and then do this:  

mex -largeArrayDims -llabjackusb u3Stream.c u3.c mexFunction.c

I get:

Building with 'Xcode with Clang'.

MEX completed successfully.

Which is pretty exciting.  I don't have my labJack with me so can't see if this actually does anything, but fingers crossed!!