2
votes

Hello I'm trying to build simple C function with external commands provide by library NPTrackingTools API

 #include <stdio.h>
 #include "mex.h"
 #include "NPTrackingTools.h"
 void mexFunction(int nlhs, mxArray *plhs[],
                 int nrhs, const mxArray *prhs[])
{
    int ret1,ret2,ret3;
    ret1=TT_Initialize();
    ret2=TT_FinalCleanup();
    ret3=TT_Shutdown();
    printf("Hello, World! \n");
    return 0;
}

I tried the following compiler code

mex -v '-Id:\or hirshfeld\onedrive\work control lab aero summer 2014 technio\C_code' '-LD:\or hirshfeld\onedrive\work control lab aero summer 2014 technion\C_code' '-lNPTrackingToolsx64.lib' test_C_compile_with_include_trackingtools.c

I have all files in the same directory "d:\or hirshfeld\onedrive\work control lab aero summer 2014 technio\C_code"

but the compiler return an error that he can't understand my commands

Error using mex Creating library test_C_compile_with_include_trackingtools.lib and object test_C_compile_with_include_trackingtools.exp test_C_compile_with_include_trackingtools.obj : error LNK2019: unresolved external symbol __imp_TT_Initialize referenced in function mexFunction test_C_compile_with_include_trackingtools.obj : error LNK2019: unresolved external symbol __imp_TT_Shutdown referenced in function mexFunction test_C_compile_with_include_trackingtools.obj : error LNK2019: unresolved external symbol __imp_TT_FinalCleanup referenced in function mexFunction test_C_compile_with_include_trackingtools.mexw64 : fatal error LNK1120: 3 unresolved externals

I tried different variation but still have the same problem, can you help me?

Thanks

Or Hirshfeld

אור הירשפלד

1
all the blank spaces in your pathnames may be causing a problem; try surrounding the pathnames with "" ? - Buck Thorn
@TryHard thanks for the comment, i tried the following code and still the same problem. mex -v '-I"D:\or hirshfeld\onedrive\work control lab aero summer 2014 technion\C_code\Motive-S-function"' '-lNPTrackingTools' '-L"D:\or hirshfeld\onedrive\work control lab aero summer 2014 technion\C_code\Motive-S-function"' test_C_compile_with_include_trackingtools.c - Or Hirshfeld

1 Answers

3
votes

The library (.lib) you are trying to link to seems to be a C++ library, although these functions have C entry points (check with Dependency Walker). I got it to compile by renaming your mexFunction source from .c to .cpp, putting the header and source in the same folder, and compiling like:

mex -v  -L. -lNPTrackingToolsx64 test_C_compile_with_include_trackingtools.cpp

although you can simply list object files on the command line like this:

mex -v test_C_compile_with_include_trackingtools.cpp NPTrackingToolsx64.lib

Just list the source file first or the output .mexw64 file will have the name of the library!

Also note that you will need LIBIOMP5MD.DLL to run the code. This is Intel's OpenMP runtime library and you can find it all over as it is freely redistributable.