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

4 ビュー (過去 30 日間)
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
אור הירשפלד

採用された回答

Or Hirshfeld
Or Hirshfeld 2015 年 4 月 28 日
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.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeWrite C Functions Callable from MATLAB (MEX Files) についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by