2014-04-04 2 views
2

C S-function에서 사용해야하는 Simulink Coder에 의해 생성 된 C 코드가 있습니다.Matlab 2013b 생성 코드 생성 mex의 x86_64 아키텍처에 대한 정의되지 않은 기호

조금 이상하게 들릴지 모르지만이 코드는 s- 함수의 출력을 작성하기 전에 s- 함수 내에서 여러 번 실행해야합니다 (많은 개인의 예측을 시뮬레이트하는 데 필요한 진화 알고리즘입니다. 평가 및 순위 결정을하기 전에 ...하지만 세부 사항은 중요하지 않습니다.)

문제점은 내 코드를 mex 할 때 64 비트 명령어 세트에 문제가있는 것처럼 보입니다. the erg_main.c에서 그 헤더를 포함한 지금은 단지 Peltier_model_initialize(); 사용하여 내 모델을 초기화하려고 들어

/* 
* File: ert_main.c 
* 
* Code generated for Simulink model 'Peltier_model'. 
* 
* Model version     : 1.14 
* Simulink Coder version   : 8.5 (R2013b) 08-Aug-2013 
* C/C++ source code generated on : Thu Apr 3 18:01:46 2014 
* 
* Target selection: ert.tlc 
* Embedded hardware selection: 32-bit Generic 
* Emulation hardware selection: 
* Differs from embedded hardware (MATLAB Host) 
* Code generation objective: Debugging 
* Validation result: Passed (0), Warning (1), Error (0) 
*/ 

#include <stdio.h>      /* This ert_main.c example uses printf/fflush */ 
#include "Peltier_model.h"    /* Model's header file */ 
#include "rtwtypes.h" 

/* 
* Associating rt_OneStep with a real-time clock or interrupt service routine 
* is what makes the generated code "real-time". The function rt_OneStep is 
* always associated with the base rate of the model. Subrates are managed 
* by the base rate from inside the generated code. Enabling/disabling 
* interrupts and floating point context switches are target specific. This 
* example code indicates where these should take place relative to executing 
* the generated code step function. Overrun behavior should be tailored to 
* your application needs. This example simply sets an error status in the 
* real-time model and returns from rt_OneStep. 
*/ 
void rt_OneStep(void) 
{ 
    static boolean_T OverrunFlag = 0; 

    /* Disable interrupts here */ 

    /* Check for overrun */ 
    if (OverrunFlag) { 
    rtmSetErrorStatus(Peltier_model_M, "Overrun"); 
    return; 
    } 

    OverrunFlag = TRUE; 

    /* Save FPU context here (if necessary) */ 
    /* Re-enable timer or interrupt here */ 
    /* Set model inputs here */ 

    /* Step the model */ 
    Peltier_model_step(); 

    /* Get model outputs here */ 

    /* Indicate task complete */ 
    OverrunFlag = FALSE; 

    /* Disable interrupts here */ 
    /* Restore FPU context here (if necessary) */ 
    /* Enable interrupts here */ 
} 

/* 
* The example "main" function illustrates what is required by your 
* application code to initialize, execute, and terminate the generated code. 
* Attaching rt_OneStep to a real-time clock is target specific. This example 
* illustates how you do this relative to initializing the model. 
*/ 
int_T main(int_T argc, const char *argv[]) 
{ 
    /* Unused arguments */ 
    (void)(argc); 
    (void)(argv); 

    /* Initialize model */ 
    Peltier_model_initialize(); 

    /* Attach rt_OneStep to a timer or interrupt service routine with 
    * period 0.01 seconds (the model's base sample time) here. The 
    * call syntax for rt_OneStep is 
    * 
    * rt_OneStep(); 
    */ 
    printf("Warning: The simulation will run forever. " 
     "Generated ERT main won't simulate model step behavior. " 
     "To change this behavior select the 'MAT-file logging' option.\n"); 
    fflush((NULL)); 
    while (rtmGetErrorStatus(Peltier_model_M) == (NULL)) { 
    /* Perform other application tasks here */ 
    } 

    /* Disable rt_OneStep() here */ 

    /* Terminate model */ 
    Peltier_model_terminate(); 
    return 0; 
} 

/* 
* File trailer for generated code. 
* 
* [EOF] 
*/ 

과 :

나는 생성 된 코드와 상호 작용하는 방법에 대한 예제로 생성 erg_main.c을 복용하고 이 결과 MEX하려고

다음 :

************************************************************************** 
    Warning: Neither -compatibleArrayDims nor -largeArrayDims is selected. 
      Using -compatibleArrayDims. In the future, MATLAB will require 
      the use of -largeArrayDims and remove the -compatibleArrayDims 
      option. For more information, see: 
      http://www.mathworks.com/help/matlab/matlab_external/upgrading-mex-files-to-use-64-bit-api.html 
************************************************************************** 

-> mexopts.sh sourced from directory (DIR = $PREF_DIR) 
    FILE = /Users/JoachimSA/.matlab/R2013b/mexopts.sh 
---------------------------------------------------------------- 
-> MATLAB    = /Applications/MATLAB_R2013b.app 
-> CC     = xcrun -sdk macosx10.9 clang 
-> CC flags: 
     CFLAGS    = -fno-common -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk -mmacosx-version-min=10.9 -fexceptions 
     CDEBUGFLAGS  = -g 
     COPTIMFLAGS  = -O2 -DNDEBUG 
     CLIBS    = -L/Applications/MATLAB_R2013b.app/bin/maci64 -lmx -lmex -lmat -lstdc++ 
     arguments   = -DMX_COMPAT_32 
-> CXX     = xcrun -sdk macosx10.9 clang++ 
-> CXX flags: 
     CXXFLAGS   = -fno-common -fexceptions -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk -mmacosx-version-min=10.9 
     CXXDEBUGFLAGS  = -g 
     CXXOPTIMFLAGS  = -O2 -DNDEBUG 
     CXXLIBS   = -L/Applications/MATLAB_R2013b.app/bin/maci64 -lmx -lmex -lmat -lstdc++ 
     arguments   = -DMX_COMPAT_32 
-> FC     = gfortran 
-> FC flags: 
     FFLAGS    = -fexceptions -m64 -fbackslash 
     FDEBUGFLAGS  = -g 
     FOPTIMFLAGS  = -O 
     FLIBS    = -L/Applications/MATLAB_R2013b.app/bin/maci64 -lmx -lmex -lmat -L -lgfortran -L -lgfortranbegin 
     arguments   = -DMX_COMPAT_32 
-> LD     = xcrun -sdk macosx10.9 clang 
-> Link flags: 
     LDFLAGS   = -arch x86_64 -Wl,-syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk -mmacosx-version-min=10.9 -bundle -Wl,-exported_symbols_list,/Applications/MATLAB_R2013b.app/extern/lib/maci64/mexFunction.map 
     LDDEBUGFLAGS  = -g 
     LDOPTIMFLAGS  = -O 
     LDEXTENSION  = .mexmaci64 
     arguments   = 
-> LDCXX     = 
-> Link flags: 
     LDCXXFLAGS   = 
     LDCXXDEBUGFLAGS = 
     LDCXXOPTIMFLAGS = 
     LDCXXEXTENSION  = 
     arguments   = 
---------------------------------------------------------------- 

-> xcrun -sdk macosx10.9 clang -c -I/Applications/MATLAB_R2013b.app/rtw/c/src -I/Users/JoachimSA/Documents/WICHTIG/Diplomarbeit/Matlab_FIles/Peltier_Codegen/Peltier_model_ert_rtw -I/Applications/MATLAB_R2013b.app/extern/include -I/Applications/MATLAB_R2013b.app/simulink/include -DMATLAB_MEX_FILE -fno-common -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk -mmacosx-version-min=10.9 -fexceptions -DMX_COMPAT_32 -O2 -DNDEBUG "CC_IMEA.c" 

-> xcrun -sdk macosx10.9 clang -c -I/Applications/MATLAB_R2013b.app/rtw/c/src -I/Users/JoachimSA/Documents/WICHTIG/Diplomarbeit/Matlab_FIles/Peltier_Codegen/Peltier_model_ert_rtw -I/Applications/MATLAB_R2013b.app/extern/include -I/Applications/MATLAB_R2013b.app/simulink/include -DMATLAB_MEX_FILE -fno-common -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk -mmacosx-version-min=10.9 -fexceptions -DMX_COMPAT_32 -O2 -DNDEBUG "CC_Opt_Objectives.c" 

-> xcrun -sdk macosx10.9 clang -c -I/Applications/MATLAB_R2013b.app/rtw/c/src -I/Users/JoachimSA/Documents/WICHTIG/Diplomarbeit/Matlab_FIles/Peltier_Codegen/Peltier_model_ert_rtw -I/Applications/MATLAB_R2013b.app/extern/include -I/Applications/MATLAB_R2013b.app/simulink/include -DMATLAB_MEX_FILE -fno-common -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk -mmacosx-version-min=10.9 -fexceptions -DMX_COMPAT_32 -O2 -DNDEBUG "CC_System_Utils.c" 

-> xcrun -sdk macosx10.9 clang -c -I/Applications/MATLAB_R2013b.app/rtw/c/src -I/Users/JoachimSA/Documents/WICHTIG/Diplomarbeit/Matlab_FIles/Peltier_Codegen/Peltier_model_ert_rtw -I/Applications/MATLAB_R2013b.app/extern/include -I/Applications/MATLAB_R2013b.app/simulink/include -DMATLAB_MEX_FILE -fno-common -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk -mmacosx-version-min=10.9 -fexceptions -DMX_COMPAT_32 -O2 -DNDEBUG "CC_Opt_SystemCabin.c" 

-> xcrun -sdk macosx10.9 clang -c -I/Applications/MATLAB_R2013b.app/rtw/c/src -I/Users/JoachimSA/Documents/WICHTIG/Diplomarbeit/Matlab_FIles/Peltier_Codegen/Peltier_model_ert_rtw -I/Applications/MATLAB_R2013b.app/extern/include -I/Applications/MATLAB_R2013b.app/simulink/include -DMATLAB_MEX_FILE -fno-common -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk -mmacosx-version-min=10.9 -fexceptions -DMX_COMPAT_32 -O2 -DNDEBUG "CC_Optimiser.c" 

-> xcrun -sdk macosx10.9 clang -O -arch x86_64 -Wl,-syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk -mmacosx-version-min=10.9 -bundle -Wl,-exported_symbols_list,/Applications/MATLAB_R2013b.app/extern/lib/maci64/mexFunction.map -o "CC_Optimiser.mexmaci64" CC_IMEA.o CC_Opt_Objectives.o CC_System_Utils.o CC_Opt_SystemCabin.o CC_Optimiser.o -L/Applications/MATLAB_R2013b.app/bin/maci64 -lmx -lmex -lmat -lstdc++ 

Undefined symbols for architecture x86_64: 
    "_Peltier_model_initialize", referenced from: 
     _CC_Opt_SystemCabin in CC_Opt_SystemCabin.o 
ld: symbol(s) not found for architecture x86_64 
clang: error: linker command failed with exit code 1 (use -v to see invocation) 

    mex: link of ' "CC_Optimiser.mexmaci64"' failed. 

Unable to complete successfully. 

Error in build_mex_files (line 6) 
mex -v ... 

Error in run (line 63) 
evalin('caller', [script ';']); 

난 정말 내 6 비트에 문제가 있나요 버전이 아니면 코드를 올바르게 처리하지 못합니까?

도움을 주셔서 감사합니다.

+0

문제를 해결할 수있었습니다. 그것은 64 비트와 관련이 없지만 32 비트 시스템에서 시도하면 올바른 경로로 나에게 오류 메시지가 나타납니다. mex 명령에 추가 C 파일을 포함하는 것을 잊었습니다. 코드에서 링크되는 모든 c 파일을 지정합니다. –

답변

0

OP는 모든 소스 파일을 mex 명령에 지정해야 함을 발견했습니다.

모든 필수 선언이 기본 소스 파일에 포함되어 있으면 컴파일이 성공하지만 실패로 연결될 수 있습니다. 당신은 바이너리 MEX-파일을 구축, 여러 소스 파일을 결합 오브젝트 파일, 파일 라이브러리 수

: 여기

는 매스 웍스 웹 사이트 "Building MEX-Files"의 연결 여러 파일 섹션에서 몇 가지 추가 정보입니다 . 이렇게하려면 추가 파일을 파일 확장자와 함께 공백으로 구분하여 나열하십시오. MEX 파일의 이름은 목록의 첫 번째 파일 이름입니다.

mex circle.c square.obj rectangle.c shapes.lib

이 말하기를 :

다음 명령은 내선은 확장이 현재의 플랫폼에 대응 circle.ext라는 이진 MEX-파일에 다른 유형의 여러 파일을 결합 위에 mexFunction과 함께 파일을 목록의 첫 번째 파일로 지정하면 MEX- 파일이 해당 파일에서 이름을 가져옵니다.

MEX -largeArrayDims fulltosparse.F loadsparse.F

MEX-파일 이름이 fulltosparse fulltosparse 때문이다 포트란 소스 있지만

mex 도움말 페이지는 유사한 예와 섹션 "Build MEX-File from Multiple Source Files"있다 .F는 명령 행의 첫 번째 파일입니다.

관련 문제