I'm having hard time trying to compile the following sample code:
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <engine.h>
int main(int argc, char **argv )
{
Engine *m_pEngine;
if (!(m_pEngine = engOpen("\0"))) {
fprintf(stderr, "\nCan't start MATLAB engine\n");
return EXIT_FAILURE;
}
std::cout << "I'm alive!" << std::endl;
return 0;
}
which is suppose to call a Matlab
function using the engine interface. Compiling it with the following compiler's options:
g++ -Wall -pedantic main.cpp -o main -I/usr/local/MATLAB/R2013a/extern/include -L/usr/local/MATLAB/R2013a/bin/glnxa64 -leng -lmat -lut -lmx -std=c++11
gives thousand error messages => Link
After reading and searching in internet and in this forum I found the following answers #1, #2, #3 helpful and I can compile the same program simply setting the LD_LIBRARY_PATH
of my system like the following:
declare -x LD_LIBRARY_PATH="/home/lukas/workspace_ros/devel/lib:/home/lukas/workspace_ros/devel/lib/x86_64-linux-gnu:/opt/ros/indigo/lib:/opt/ros/indigo/lib/x86_64-linux-gnu:/usr/local/MATLAB/R2013a/bin/glnxa64"
BUT another program, which is sharing the same variable (ROS), is not working anymore and I get the following error message:
lukas@ubuntu:~$ roscore
Traceback (most recent call last):
File "/opt/ros/indigo/bin/roscore", line 62, in <module>
import roslaunch
File "/opt/ros/indigo/lib/python2.7/dist-packages/roslaunch/__init__.py", line 48, in <module>
import rospkg
File "/usr/lib/python2.7/dist-packages/rospkg/__init__.py", line 43, in <module>
from .rospack import RosPack, RosStack, \
File "/usr/lib/python2.7/dist-packages/rospkg/rospack.py", line 35, in <module>
from xml.etree.cElementTree import ElementTree
File "/usr/lib/python2.7/xml/etree/cElementTree.py", line 3, in <module>
from _elementtree import *
ImportError: PyCapsule_Import could not import module "pyexpat"
So I must set the environment variable back and log out-in again to work with ROS.
So it seems to me that Matlab and ROS are not actually seeing and identifying their paths in that environment variable. Using one excludes the resource for the other one. How can they coexist in the same system? How should I set this variable?
UPDATE #1: according to Michael's suggestion I tried the following shell command:
LD_LIBRARY_PATH="/usr/local/MATLAB/R2013a/bin/glnxa64" g++ -Wall -pedantic main.cpp -o main -I/usr/local/MATLAB/R2013a/extern/include -L/usr/local/MATLAB/R2013a/bin/glnxa64 -leng -lmat -lut -lmex -std=c++11
and it compiles!!! :) So an upvote to Michael.
But the problem persists: if I try to run the program I get the following error message:
:~$ ./main
./main: error while loading shared libraries: libeng.so: cannot open shared object file: No such file or directory
that's because the library are shared and should be found at running time. Any idea???
Regards