mex: Link Failed when compile C file

I have my C file and h file in one directory. but when I use mex command like
>>mex checkPeriod.c checkPeriod.h
I got some error:
checkPeriod.h:16:24: error: mwmathutil.h: No such file or directory
checkPeriod.h:18:22: error: tmwtypes.h: No such file or directory
checkPeriod.h:19:17: error: mex.h: No such file or directory
checkPeriod.h:20:19: error: emlrt.h: No such file or directory
checkPeriod.h:21:18: error: blas.h: No such file or directory
In file included from checkPeriod.h:23:
checkPeriod_types.h:25: error: expected specifier-qualifier-list before ‘uint32_T’
checkPeriod_types.h:35: error: expected specifier-qualifier-list before ‘real_T’
checkPeriod_types.h:50: error: expected specifier-qualifier-list before ‘real_T’
checkPeriod_types.h:67: error: expected specifier-qualifier-list before ‘real_T’
checkPeriod_types.h:83: error: expected specifier-qualifier-list before ‘int32_T’
checkPeriod_types.h:97: error: expected specifier-qualifier-list before ‘boolean_T’
checkPeriod_types.h:130: error: expected specifier-qualifier-list before ‘int32_T’
checkPeriod_types.h:144: error: expected specifier-qualifier-list before ‘real_T’
checkPeriod_types.h:160: error: expected specifier-qualifier-list before ‘int32_T’
checkPeriod_types.h:174: error: expected specifier-qualifier-list before ‘real_T’
checkPeriod_types.h:192: error: expected specifier-qualifier-list before ‘int32_T’
checkPeriod_types.h:206: error: expected specifier-qualifier-list before ‘int32_T’
checkPeriod_types.h:221: error: expected specifier-qualifier-list before ‘real_T’
checkPeriod_types.h:233: error: expected specifier-qualifier-list before ‘real_T’
checkPeriod_types.h:245: error: expected specifier-qualifier-list before ‘real_T’
checkPeriod.h:26: error: expected )before ‘boundary’
mex: link of ' "checkPeriod.mexa64"' failed.
At beginning, I thought this is because a lot of other function used in this function. But when I try to compile all the files, these errors still came out. Any help??

Answers (1)

James Tursa
James Tursa on 21 Jul 2016
Edited: James Tursa on 21 Jul 2016
You typically do not include header .h files in a mex command. They are generally intended to be included in the source file via a #include statement. Do you have this line in checkPeriod.c:
#include "checkPeriod.h"
If so, things are set up as I would expect, and you can try this:
mex checkPeriod.c
This is all somewhat guesswork on my part because I can't see your source files.

1 Comment

#include "rt_nonfinite.h"
#include "checkPeriod.h"
#include "checkPeriod_emxutil.h"
#include "setinterlist.h"
#include "periodSegment.h"
#include "moveRec.h"
#include "inrec.h"
#include "checkPeriod_data.h"
This is what I find in the file, But even I use the command you mentioned. The error still come out.
checkPeriod.o: In function `checkPeriod':
checkPeriod.c:(.text+0x39): undefined reference to `emlrtRootTLSGlobal'
checkPeriod.c:(.text+0x41): undefined reference to `emlrtHeapReferenceStackEnterFcnR2012b'
checkPeriod.c:(.text+0x70): undefined reference to `emxEnsureCapacity_struct_T'
checkPeriod.c:(.text+0xa5): undefined reference to `emxCopyStruct_struct_T'
checkPeriod.c:(.text+0xbc): undefined reference to `emlrtRootTLSGlobal'
checkPeriod.c:(.text+0xcb): undefined reference to `emlrtPushRtStackR2012b'
checkPeriod.c:(.text+0xe7): undefined reference to `emlrtRootTLSGlobal'
checkPeriod.c:(.text+0xf1): undefined reference to `l_emlrtRSI'
checkPeriod.c:(.text+0xf9): undefined reference to `emlrtPushRtStackR2012b'
checkPeriod.c:(.text+0xfe): undefined reference to `check_forloop_overflow_error'
checkPeriod.c:(.text+0x109): undefined reference to `emlrtPopRtStackR2012b'
checkPeriod.c:(.text+0x110): undefined reference to `emlrtRootTLSGlobal'
checkPeriod.c:(.text+0x11f): undefined reference to `emlrtPopRtStackR2012b'
checkPeriod.c:(.text+0x137): undefined reference to `emxInitStruct_struct_T'
checkPeriod.c:(.text+0x154): undefined reference to `b_emxInit_struct_T'
checkPeriod.c:(.text+0x171): undefined reference to `c_emxInit_struct_T'
checkPeriod.c:(.text+0x189): undefined reference to `emxInitStruct_struct_T'
checkPeriod.c:(.text+0x1cc): undefined reference to `emlrtRootTLSGlobal'
checkPeriod.c:(.text+0x1e6): undefined reference to `emlrtDynamicBoundsCheckR2012b'
checkPeriod.c:(.text+0x200): undefined reference to `muDoubleScalarAbs'
checkPeriod.c:(.text+0x218): undefined reference to `muDoubleScalarAbs'
checkPeriod.c:(.text+0x261): undefined reference to `muDoubleScalarIsNaN'
checkPeriod.c:(.text+0x294): undefined reference to `muDoubleScalarIsNaN'
checkPeriod.c:(.text+0x316): undefined reference to `emlrtRootTLSGlobal'
checkPeriod.c:(.text+0x330): undefined reference to `emlrtDynamicBoundsCheckR2012b'
checkPeriod.c:(.text+0x33f): undefined reference to `muDoubleScalarAbs'
checkPeriod.c:(.text+0x357): undefined reference to `muDoubleScalarAbs'
checkPeriod.c:(.text+0x3a0): undefined reference to `muDoubleScalarIsNaN'
checkPeriod.c:(.text+0x3d3): undefined reference to `muDoubleScalarIsNaN'
checkPeriod.c:(.text+0x457): undefined reference to `emlrtRootTLSGlobal'
checkPeriod.c:(.text+0x471): undefined reference to `emlrtDynamicBoundsCheckR2012b'
checkPeriod.c:(.text+0x478): undefined reference to `emlrtRootTLSGlobal'
checkPeriod.c:(.text+0x487): undefined reference to `emlrtPushRtStackR2012b'
checkPeriod.c:(.text+0x538): undefined reference to `inrec'
checkPeriod.c:(.text+0x53f): undefined reference to `emlrtRootTLSGlobal'
checkPeriod.c:(.text+0x54e): undefined reference to `emlrtPopRtStackR2012b'
checkPeriod.c:(.text+0x5a2): undefined reference to `muDoubleScalarSign'
checkPeriod.c:(.text+0x5fc): undefined reference to `emxCopyStruct_struct_T'
checkPeriod.c:(.text+0x60f): undefined reference to `moveRec'
checkPeriod.c:(.text+0x639): undefined reference to `b_emxEnsureCapacity_struct_T'
checkPeriod.c:(.text+0x672): undefined reference to `b_emxEnsureCapacity_struct_T'
checkPeriod.c:(.text+0x6bf): undefined reference to `b_emxCopyStruct_struct_T'
checkPeriod.c:(.text+0x6d3): undefined reference to `emlrtRootTLSGlobal'
checkPeriod.c:(.text+0x6e2): undefined reference to `emlrtPushRtStackR2012b'
checkPeriod.c:(.text+0x6fc): undefined reference to `muDoubleScalarSign'
checkPeriod.c:(.text+0x744): undefined reference to `emxEnsureCapacity_struct_T'
checkPeriod.c:(.text+0x781): undefined reference to `emxCopyStruct_struct_T'
checkPeriod.c:(.text+0x7f1): undefined reference to `periodSegment'
checkPeriod.c:(.text+0x7f8): undefined reference to `emlrtRootTLSGlobal'
checkPeriod.c:(.text+0x807): undefined reference to `emlrtPopRtStackR2012b'
checkPeriod.c:(.text+0x83d): undefined reference to `emxEnsureCapacity_struct_T'
checkPeriod.c:(.text+0x880): undefined reference to `emxCopyStruct_struct_T'
checkPeriod.c:(.text+0x897): undefined reference to `emlrtRootTLSGlobal'
checkPeriod.c:(.text+0x8a6): undefined reference to `emlrtPushRtStackR2012b'
checkPeriod.c:(.text+0x8d8): undefined reference to `emlrtRootTLSGlobal'
checkPeriod.c:(.text+0x8f4): undefined reference to `emlrtDynamicBoundsCheckR2012b'
checkPeriod.c:(.text+0x910): undefined reference to `emlrtRootTLSGlobal'
checkPeriod.c:(.text+0x92c): undefined reference to `emlrtDynamicBoundsCheckR2012b'
checkPeriod.c:(.text+0x94c): undefined reference to `emxCopyStruct_struct_T'
checkPeriod.c:(.text+0x97d): undefined reference to `emlrtRootTLSGlobal'
checkPeriod.c:(.text+0x997): undefined reference to `emlrtDynamicBoundsCheckR2012b'
checkPeriod.c:(.text+0x9b0): undefined reference to `b_setinterlist'
checkPeriod.c:(.text+0x9b7): undefined reference to `emlrtRootTLSGlobal'
checkPeriod.c:(.text+0x9c6): undefined reference to `emlrtPopRtStackR2012b'
checkPeriod.c:(.text+0x9fc): undefined reference to `emlrtRootTLSGlobal'
checkPeriod.c:(.text+0xa16): undefined reference to `emlrtDynamicBoundsCheckR2012b'
checkPeriod.c:(.text+0xa3a): undefined reference to `emxCopyStruct_struct_T'
checkPeriod.c:(.text+0xa86): undefined reference to `muDoubleScalarSign'
checkPeriod.c:(.text+0xae0): undefined reference to `emxCopyStruct_struct_T'
checkPeriod.c:(.text+0xaf3): undefined reference to `moveRec'
checkPeriod.c:(.text+0xb1d): undefined reference to `b_emxEnsureCapacity_struct_T'
checkPeriod.c:(.text+0xb56): undefined reference to `b_emxEnsureCapacity_struct_T'
checkPeriod.c:(.text+0xba3): undefined reference to `b_emxCopyStruct_struct_T'
checkPeriod.c:(.text+0xbb7): undefined reference to `emlrtRootTLSGlobal'
checkPeriod.c:(.text+0xbc6): undefined reference to `emlrtPushRtStackR2012b'
checkPeriod.c:(.text+0xbe0): undefined reference to `muDoubleScalarSign'
checkPeriod.c:(.text+0xc28): undefined reference to `emxEnsureCapacity_struct_T'
checkPeriod.c:(.text+0xc65): undefined reference to `emxCopyStruct_struct_T'
checkPeriod.c:(.text+0xce1): undefined reference to `periodSegment'
checkPeriod.c:(.text+0xce8): undefined reference to `emlrtRootTLSGlobal'
checkPeriod.c:(.text+0xcf7): undefined reference to `emlrtPopRtStackR2012b'
checkPeriod.c:(.text+0xd2d): undefined reference to `emxEnsureCapacity_struct_T'
checkPeriod.c:(.text+0xd70): undefined reference to `emxCopyStruct_struct_T'
checkPeriod.c:(.text+0xd87): undefined reference to `emlrtRootTLSGlobal'
checkPeriod.c:(.text+0xd96): undefined reference to `emlrtPushRtStackR2012b'
checkPeriod.c:(.text+0xdc8): undefined reference to `emlrtRootTLSGlobal'
checkPeriod.c:(.text+0xde4): undefined reference to `emlrtDynamicBoundsCheckR2012b'
checkPeriod.c:(.text+0xe00): undefined reference to `emlrtRootTLSGlobal'
checkPeriod.c:(.text+0xe1c): undefined reference to `emlrtDynamicBoundsCheckR2012b'
checkPeriod.c:(.text+0xe3c): undefined reference to `emxCopyStruct_struct_T'
checkPeriod.c:(.text+0xe71): undefined reference to `emlrtRootTLSGlobal'
checkPeriod.c:(.text+0xe8b): undefined reference to `emlrtDynamicBoundsCheckR2012b'
checkPeriod.c:(.text+0xea4): undefined reference to `b_setinterlist'
checkPeriod.c:(.text+0xeb3): undefined reference to `emlrtPopRtStackR2012b'
checkPeriod.c:(.text+0xed3): undefined reference to `emlrtRootTLSGlobal'
checkPeriod.c:(.text+0xeed): undefined reference to `emlrtDynamicBoundsCheckR2012b'
checkPeriod.c:(.text+0xf2b): undefined reference to `muDoubleScalarSign'
checkPeriod.c:(.text+0xf66): undefined reference to `emxCopyStruct_struct_T'
checkPeriod.c:(.text+0xf79): undefined reference to `moveRec'
checkPeriod.c:(.text+0xfa3): undefined reference to `b_emxEnsureCapacity_struct_T'
checkPeriod.c:(.text+0xfdc): undefined reference to `b_emxEnsureCapacity_struct_T'
checkPeriod.c:(.text+0x1029): undefined reference to `b_emxCopyStruct_struct_T'
checkPeriod.c:(.text+0x103d): undefined reference to `emlrtRootTLSGlobal'
checkPeriod.c:(.text+0x104c): undefined reference to `emlrtPushRtStackR2012b'
checkPeriod.c:(.text+0x108c): undefined reference to `emxEnsureCapacity_struct_T'
checkPeriod.c:(.text+0x10c9): undefined reference to `emxCopyStruct_struct_T'
checkPeriod.c:(.text+0x111c): undefined reference to `muDoubleScalarSign'
checkPeriod.c:(.text+0x1165): undefined reference to `b_periodSegment'
checkPeriod.c:(.text+0x116c): undefined reference to `emlrtRootTLSGlobal'
checkPeriod.c:(.text+0x117b): undefined reference to `emlrtPopRtStackR2012b'
checkPeriod.c:(.text+0x11b1): undefined reference to `emxEnsureCapacity_struct_T'
checkPeriod.c:(.text+0x11f4): undefined reference to `emxCopyStruct_struct_T'
checkPeriod.c:(.text+0x120b): undefined reference to `emlrtRootTLSGlobal'
checkPeriod.c:(.text+0x121a): undefined reference to `emlrtPushRtStackR2012b'
checkPeriod.c:(.text+0x124c): undefined reference to `emlrtRootTLSGlobal'
checkPeriod.c:(.text+0x1268): undefined reference to `emlrtDynamicBoundsCheckR2012b'
checkPeriod.c:(.text+0x1284): undefined reference to `emlrtRootTLSGlobal'
checkPeriod.c:(.text+0x12a0): undefined reference to `emlrtDynamicBoundsCheckR2012b'
checkPeriod.c:(.text+0x12c0): undefined reference to `emxCopyStruct_struct_T'
checkPeriod.c:(.text+0x12f5): undefined reference to `emlrtRootTLSGlobal'
checkPeriod.c:(.text+0x130f): undefined reference to `emlrtDynamicBoundsCheckR2012b'
checkPeriod.c:(.text+0x1328): undefined reference to `b_setinterlist'
checkPeriod.c:(.text+0x1337): undefined reference to `emlrtPopRtStackR2012b'
checkPeriod.c:(.text+0x1357): undefined reference to `emlrtRootTLSGlobal'
checkPeriod.c:(.text+0x1371): undefined reference to `emlrtDynamicBoundsCheckR2012b'
checkPeriod.c:(.text+0x137e): undefined reference to `muDoubleScalarSign'
checkPeriod.c:(.text+0x13b3): undefined reference to `muDoubleScalarSign'
checkPeriod.c:(.text+0x13e8): undefined reference to `muDoubleScalarSign'
checkPeriod.c:(.text+0x13fd): undefined reference to `muDoubleScalarSign'
checkPeriod.c:(.text+0x141f): undefined reference to `emxCopyStruct_struct_T'
checkPeriod.c:(.text+0x1432): undefined reference to `moveRec'
checkPeriod.c:(.text+0x145c): undefined reference to `b_emxEnsureCapacity_struct_T'
checkPeriod.c:(.text+0x1495): undefined reference to `b_emxEnsureCapacity_struct_T'
checkPeriod.c:(.text+0x14e2): undefined reference to `b_emxCopyStruct_struct_T'
checkPeriod.c:(.text+0x14f6): undefined reference to `emlrtRootTLSGlobal'
checkPeriod.c:(.text+0x1505): undefined reference to `emlrtPushRtStackR2012b'
checkPeriod.c:(.text+0x1545): undefined reference to `emxEnsureCapacity_struct_T'
checkPeriod.c:(.text+0x1582): undefined reference to `emxCopyStruct_struct_T'
checkPeriod.c:(.text+0x15f6): undefined reference to `c_periodSegment'
checkPeriod.c:(.text+0x15fd): undefined reference to `emlrtRootTLSGlobal'
checkPeriod.c:(.text+0x160c): undefined reference to `emlrtPopRtStackR2012b'
checkPeriod.c:(.text+0x1642): undefined reference to `emxEnsureCapacity_struct_T'
checkPeriod.c:(.text+0x1685): undefined reference to `emxCopyStruct_struct_T'
checkPeriod.c:(.text+0x169c): undefined reference to `emlrtRootTLSGlobal'
checkPeriod.c:(.text+0x16ab): undefined reference to `emlrtPushRtStackR2012b'
checkPeriod.c:(.text+0x16dd): undefined reference to `emlrtRootTLSGlobal'
checkPeriod.c:(.text+0x16f9): undefined reference to `emlrtDynamicBoundsCheckR2012b'
checkPeriod.c:(.text+0x1715): undefined reference to `emlrtRootTLSGlobal'
checkPeriod.c:(.text+0x1731): undefined reference to `emlrtDynamicBoundsCheckR2012b'
checkPeriod.c:(.text+0x1751): undefined reference to `emxCopyStruct_struct_T'
checkPeriod.c:(.text+0x1782): undefined reference to `emlrtRootTLSGlobal'
checkPeriod.c:(.text+0x179c): undefined reference to `emlrtDynamicBoundsCheckR2012b'
checkPeriod.c:(.text+0x17b5): undefined reference to `b_setinterlist'
checkPeriod.c:(.text+0x17bc): undefined reference to `emlrtRootTLSGlobal'
checkPeriod.c:(.text+0x17cb): undefined reference to `emlrtPopRtStackR2012b'
checkPeriod.c:(.text+0x17d2): undefined reference to `emlrtBreakCheckR2012bFlagVar'
checkPeriod.c:(.text+0x17e3): undefined reference to `emlrtRootTLSGlobal'
checkPeriod.c:(.text+0x17eb): undefined reference to `emlrtBreakCheckR2012b'
checkPeriod.c:(.text+0x1812): undefined reference to `b_emxFreeStruct_struct_T'
checkPeriod.c:(.text+0x181e): undefined reference to `c_emxFree_struct_T'
checkPeriod.c:(.text+0x182a): undefined reference to `b_emxFree_struct_T'
checkPeriod.c:(.text+0x1836): undefined reference to `b_emxFreeStruct_struct_T'
checkPeriod.c:(.text+0x1867): undefined reference to `b_emxEnsureCapacity_struct_T'
checkPeriod.c:(.text+0x186e): undefined reference to `emlrtRootTLSGlobal'
checkPeriod.c:(.text+0x187d): undefined reference to `emlrtPushRtStackR2012b'
checkPeriod.c:(.text+0x188c): undefined reference to `emlrtPopRtStackR2012b'
checkPeriod.c:(.text+0x18a9): undefined reference to `emxInit_struct_T'
checkPeriod.c:(.text+0x18e4): undefined reference to `emlrtRootTLSGlobal'
checkPeriod.c:(.text+0x18fb): undefined reference to `emlrtDynamicBoundsCheckR2012b'
checkPeriod.c:(.text+0x1948): undefined reference to `b_emxEnsureCapacity_struct_T'
checkPeriod.c:(.text+0x198b): undefined reference to `emlrtRootTLSGlobal'
checkPeriod.c:(.text+0x19a2): undefined reference to `emlrtDynamicBoundsCheckR2012b'
checkPeriod.c:(.text+0x19dd): undefined reference to `b_emxEnsureCapacity_struct_T'
checkPeriod.c:(.text+0x1a00): undefined reference to `emlrtRootTLSGlobal'
checkPeriod.c:(.text+0x1a1d): undefined reference to `emlrtDynamicBoundsCheckR2012b'
checkPeriod.c:(.text+0x1a41): undefined reference to `emlrtRootTLSGlobal'
checkPeriod.c:(.text+0x1a5e): undefined reference to `emlrtDynamicBoundsCheckR2012b'
checkPeriod.c:(.text+0x1ae8): undefined reference to `emlrtRootTLSGlobal'
checkPeriod.c:(.text+0x1b02): undefined reference to `emlrtDynamicBoundsCheckR2012b'
checkPeriod.c:(.text+0x1b33): undefined reference to `b_emxCopyStruct_struct_T'
checkPeriod.c:(.text+0x1ba0): undefined reference to `b_emxEnsureCapacity_struct_T'
checkPeriod.c:(.text+0x1bf4): undefined reference to `emlrtRootTLSGlobal'
checkPeriod.c:(.text+0x1c0e): undefined reference to `emlrtDynamicBoundsCheckR2012b'
checkPeriod.c:(.text+0x1c53): undefined reference to `b_emxCopyStruct_struct_T'
checkPeriod.c:(.text+0x1c78): undefined reference to `emlrtBreakCheckR2012bFlagVar'
checkPeriod.c:(.text+0x1c89): undefined reference to `emlrtRootTLSGlobal'
checkPeriod.c:(.text+0x1c91): undefined reference to `emlrtBreakCheckR2012b'
checkPeriod.c:(.text+0x1cb5): undefined reference to `emxFree_struct_T'
checkPeriod.c:(.text+0x1cbc): undefined reference to `emlrtRootTLSGlobal'
checkPeriod.c:(.text+0x1cc4): undefined reference to `emlrtHeapReferenceStackLeaveFcnR2012b'
checkPeriod.c:(.text+0x1cf1): undefined reference to `emxCopyStruct_struct_T'
checkPeriod.c:(.text+0x1d2a): undefined reference to `emxCopyStruct_struct_T'
checkPeriod.c:(.text+0x1d54): undefined reference to `b_setinterlist'
checkPeriod.c:(.text+0x1d5b): undefined reference to `emlrtRootTLSGlobal'
checkPeriod.c:(.text+0x1d6a): undefined reference to `emlrtPopRtStackR2012b'
checkPeriod.c:(.text+0x1d92): undefined reference to `emxCopyStruct_struct_T'
checkPeriod.c:(.text+0x1dbc): undefined reference to `b_setinterlist'
checkPeriod.c:(.text+0x1dc3): undefined reference to `emlrtRootTLSGlobal'
checkPeriod.c:(.text+0x1dd2): undefined reference to `emlrtPopRtStackR2012b'
checkPeriod.c:(.text+0x1dfa): undefined reference to `emxCopyStruct_struct_T'
checkPeriod.c:(.text+0x1e1f): undefined reference to `emlrtRootTLSGlobal'
checkPeriod.c:(.text+0x1e3b): undefined reference to `emlrtDynamicBoundsCheckR2012b'
checkPeriod.c:(.text+0x1e68): undefined reference to `emlrtRootTLSGlobal'
checkPeriod.c:(.text+0x1e84): undefined reference to `emlrtDynamicBoundsCheckR2012b'
checkPeriod.c:(.text+0x1eb1): undefined reference to `emlrtRootTLSGlobal'
checkPeriod.c:(.text+0x1ecd): undefined reference to `emlrtDynamicBoundsCheckR2012b'
checkPeriod.c:(.text+0x1efa): undefined reference to `emlrtRootTLSGlobal'
checkPeriod.c:(.text+0x1f16): undefined reference to `emlrtDynamicBoundsCheckR2012b'
collect2: ld returned 1 exit status
mex: link of ' "checkPeriod.mexa64"' failed.

Sign in to comment.

Categories

Asked:

on 21 Jul 2016

Commented:

on 21 Jul 2016

Community Treasure Hunt

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

Start Hunting!