Hi, if I try to load the LJM library in MATLAB I get lots of warnings and then errors (summary here, full log attached):
Error using loadlibrary Building libLabJackM_thunk_glnxa64 failed. Compiler output is: /home/linuxbrew/.linuxbrew/bin/gcc -I"/usr/local/MATLAB/R2019b/extern/include" -fexceptions -fPIC -fno-omit-frame-pointer -pthread -I"/home/cog1" -I"/usr/local/include" "libLabJackM_thunk_glnxa64.c" -o "libLabJackM_thunk_glnxa64.so" -Wl,-E -shared libLabJackM_thunk_glnxa64.c:33:34: error: expected declaration specifiers or '...' before string constant EXPORT_EXTERN_C (__visibility__("default")))intLJM_Close(intHandleThunk(void fcn(),const char *callstack,int stacksize)I can load the exodriver library on the same system without any problems. Ubuntu 19.10 + MATLAB 2019b.
LabJackM.h uses the attribute specifier from C++11: https://en.cppreference.com/w/cpp/language/attributes
Does compilation work if you add the following compile flag?
-std=c++11
I'm not quite sure where this can be passed in to MATLAB, the documentation for loadlibrary is here:
https://uk.mathworks.com/help/matlab/ref/loadlibrary.html
https://uk.mathworks.com/help/matlab/matlab_external/limitations-to-shar...
I have no experiience of C or C++, other than typing make on the commandline ;-)
I found the file to edit in MATLAB: ~/.matlab/R2019b/mex_C_glnxa64.xml --- and I edited it to add that flag:
https://gist.github.com/iandol/07242323696092a46c2e1ee1add9cc0d
But I get these errors:
Sorry, I see now that you were compiling for C, not C++.
If you remove __attribute__((__visibility__("default"))) from LabJackM.h, what is the compilation output? Essentially, change:
#else // Linux
#define LJM_ERROR_RETURN __attribute__((__visibility__("default"))) int
#define LJM_LONG_LONG_RETURN __attribute__((__visibility__("default"))) long long
#define LJM_VOID_RETURN __attribute__((__visibility__("default"))) void
#define LJM_ERROR_STRING __attribute__((__visibility__("default"))) const char *
#define LJM_DOUBLE_RETURN __attribute__((__visibility__("default"))) double
#endif
to:
#else // Linux
#define LJM_ERROR_RETURN int
#define LJM_LONG_LONG_RETURN long long
#define LJM_VOID_RETURN void
#define LJM_ERROR_STRING const char *
#define LJM_DOUBLE_RETURN double
#endif
Hi, yes, that works!
>> header = '/usr/local/include/LabJackM.h'
>> library = '/usr/local/lib/libLabJackM.so'
>> [f,w]=loadlibrary(library,header)
Warning: The data type 'FcnPtr' used by function LJM_SetStreamCallback does not exist.
> In loadlibrary
Warning: The data type 'FcnPtr' used by function LJM_RegisterDeviceReconnectCallback does not exist.
> In loadlibrary
>> libisloaded('libLabJackM')
ans = logical 1
Should I maintain my own modified header file, or will you change this in a future release?
I think it's possible to use macros to correctly select which version of the defines should be used. I will look into this.
Thank you for your help!
We've released LJM 1.2100, which uses a macro to determine which definition of e.g. LJM_ERROR_RETURN is used. The __attribute__ version is used only when LABJACK_LJM_ATTRIBUTE_VISIBILITY_DEFAULT is defined, so you should be able to build without altering LabJackM.h.
If you would like to test it out, we would be happy to hear your results. Currently, LJM 1.2100 is available as a beta installer:
https://labjack.com/support/software/installers/ljm
Hi, I can confirm that the beta fixes the problem; thanks for the support!
Best wishes and stay safe, Ian