I'm trying to compile an application pipeline
and link it with my library matlabengine
, which acts as a wrapper to Matlab calls. Matlab uses it's own older version of libstc++
which is mixed in Matlab's lib folder .../bin/glnxa64
matlabengine
compiles ok, but pipeline
fails for unresolved symbols (because pipeline uses Matlab's libstdc++
version)
Basically i have two problem and solving either one should fix this:
Remove arguments
-leng -lmx -L/usr/local/MATLAB/R2013a/bin/glnxa64
frompipeline
linking, which origin from subdirectorymex
. When I compilematlabengine
by hand and let cmake link it to pipeline, these flags do not appear and everything is fine. Why are these added to pipeline's linking when it works perfectly without them?Since Matlab's old libstc++ is used before the the system-wide libstdc++ i get unresolved symbols. fixing the order c++ searches for these libraries should also solve this.
Any help is much appreciated...
CMakeList.txt
link_directories("/usr/local/MATLAB/R2013a}/bin/glnxa64")
include_directories(mex)
add_subdirectory(mex)
ADD_EXECUTABLE( pipeline pipeline.cpp )
TARGET_LINK_LIBRARIES( pipeline matlabengine ${OpenCV_LIBS})
mex/CMakeList.txt (this should emulate what matlab's mex compiler wrapper does)
# mex specific c++ flags
set(MATLAB_PATH "/usr/local/MATLAB/R2013a")
set(CMAKE_CXX_COMPILER "gcc-4.4")
set(CMAKE_CXX_FLAGS "-D_GNU_SOURCE -fexceptions -DMX_COMPAT_32 -O -DNDEBUG -fPIC -DMATLAB_MEX_FILE")
include_directories("${MATLAB_PATH}/extern/include")
link_directories("${MATLAB_PATH}/bin/glnxa64")
add_library(matlabengine SHARED matlabengine.cpp)
target_link_libraries(matlabengine eng mx m)