System Command Gives Segmentation Fault?

조회 수: 7 (최근 30일)
jfherrm
jfherrm 2017년 1월 20일
댓글: Walter Roberson 2017년 1월 20일
Hello! I am using an external solver to run simulations. I am trying to call the external solver with system(cmd) from a MATLAB script. The cmd itself runs fine with no problems from the Terminal (I'm running on OSX). However, every time the MATLAB script runs, the status is 139 - Segmentation Fault. Does anyone know why this might be happening?
  댓글 수: 2
jfherrm
jfherrm 2017년 1월 20일
SOLUTION: I found a solution from a separate forum; I am posting here in case anyone has a similar issue. Essentially, the external solver depends on bash environment variables stored in my home .bash_profile and other locations. These variables are not accessible to MATLAB. Therefore, in my main MATLAB script, I added a bunch of "setenv()" commands to set these variables within the script itself. This makes the variables accessible to the external solver so that it functions properly.
Walter Roberson
Walter Roberson 2017년 1월 20일
Another approach might have been to use something like,
system('source ~/.bash_profile; rest of command')

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2017년 1월 20일
It is a DYLD_DYNAMIC_PATH problem. MATLAB puts a dynamic path environment variable that either is missing a directory the executable needs or else puts a directory in priority that contains an incompatible dynamic path.
At the terminal window examine the environment variable. Then in your MATLAB program before calling system, use setenv() to set the environment variable to that same thing.

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by