compile .C file Include library using mex - error LNK2019: unresolved external symbol - for NPTrackingTools

1 view (last 30 days)
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
אור הירשפלד

Accepted Answer

Or Hirshfeld
Or Hirshfeld on 28 Apr 2015
Solution by chappjc (<http://stackoverflow.com/users/2778484/chappjc>) from Stack Overflow Forum
"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!"
All i needed is rename it .CPP so it compiled in C++. I didn't do anything extra to link it to Intel's OpenMP runtime library, I guess Matlab already link it by defualt.

More Answers (0)

Categories

Find more on Troubleshooting in MATLAB Compiler SDK in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!