Matlab failed to link, not able to access libraries

2 views (last 30 days)
Hi,
I am on a linux Virtual Machine running Matlab 2012b and I keep getting this error when I try to run a .m file that calls a c++ file in matlab.
>>rebuildAll
### Start Compiling spherescore_sfun
mex('spherescore_sfun.cpp', '-g', '/home/vagrant/trunk/MatlabSim/CSPHERESCore/Simulink/SpheresSfunInterface.cpp', '-I/home/vagrant/trunk/MatlabSim/CSPHERESCore/Simulink/.', '-I/home/vagrant/trunk/MatlabSim/CSPHERESCore/Simulink/../include', '-I/home/vagrant/trunk/MatlabSim/CSPHERESCore/Simulink/../../../SpheresCore', '-I/home/vagrant/trunk/MatlabSim/CSPHERESCore/Simulink')
SpheresSfunInterface.o: In function `SpheresInterface::closeLibs()':
/home/vagrant/trunk/MatlabSim/CSPHERESCore/Simulink/SpheresSfunInterface.cpp:69: undefined reference to `dlclose'
SpheresSfunInterface.o: In function `SpheresInterface::unloadSCLib(unsigned int)':
/home/vagrant/trunk/MatlabSim/CSPHERESCore/Simulink/SpheresSfunInterface.cpp:78: undefined reference to `dlclose'
SpheresSfunInterface.o: In function `SpheresInterface::loadShared(char const*)':
/home/vagrant/trunk/MatlabSim/CSPHERESCore/Simulink/SpheresSfunInterface.cpp:101: undefined reference to `dlerror'
/home/vagrant/trunk/MatlabSim/CSPHERESCore/Simulink/SpheresSfunInterface.cpp:102: undefined reference to `dlopen'
/home/vagrant/trunk/MatlabSim/CSPHERESCore/Simulink/SpheresSfunInterface.cpp:103: undefined reference to `dlerror'
SpheresSfunInterface.o: In function `lookupFunction(void*, char const*)':
/home/vagrant/trunk/MatlabSim/CSPHERESCore/Simulink/SpheresSfunInterface.cpp:117: undefined reference to `dlerror'
/home/vagrant/trunk/MatlabSim/CSPHERESCore/Simulink/SpheresSfunInterface.cpp:118: undefined reference to `dlsym'
/home/vagrant/trunk/MatlabSim/CSPHERESCore/Simulink/SpheresSfunInterface.cpp:119: undefined reference to `dlerror'
SpheresSfunInterface.o: In function `SpheresInterface::loadComm(SpheresCoreParams*)':
/home/vagrant/trunk/MatlabSim/CSPHERESCore/Simulink/SpheresSfunInterface.cpp:148: undefined reference to `dlclose'
/home/vagrant/trunk/MatlabSim/CSPHERESCore/Simulink/SpheresSfunInterface.cpp:159: undefined reference to `dlclose'
collect2: ld returned 1 exit status
mex: link of ' "spherescore_sfun.mexa64"' failed.
This is what happens when I isolate the c++ file that is called using mex:
>> mex spherescore_sfun.cpp -ldl -I/home/vagrant/trunk/MatlabSim/CSPHERESCore/Simulink
spherescore_sfun.o: In function `mdlInitializeConditions(SimStruct_tag*)':
spherescore_sfun.cpp:(.text+0x1d8c): undefined reference to `initFcn(SpheresCoreParams*)'
spherescore_sfun.o: In function `mdlOutputs(SimStruct_tag*, int)':
spherescore_sfun.cpp:(.text+0x1ff9): undefined reference to `stepFcn(SpheresCoreParams*, SpheresCoreInput*, SpheresCoreOutput*)'
spherescore_sfun.o: In function `mdlTerminate(SimStruct_tag*)':
spherescore_sfun.cpp:(.text+0x221c): undefined reference to `exitFcn()'
collect2: ld returned 1 exit status
mex: link of ' "spherescore_sfun.mexa64"' failed.
All the functions that it is saying are undefined references clearly exist in a header file that I include in the c++ file spherescore_sfun.cpp (I also link its directory location in the call with -I). Also, I have dlfcn.h imported, but that didn't fix the dlclose, dlerror, dlopen errors. This leads me to believe Matlab is having trouble accessing my included files and libraries. Is there some environment variable that I would need to set? How do I get rid of these errors?
Thanks!

Answers (0)

Categories

Find more on Write C Functions Callable from MATLAB (MEX Files) in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!