使用 mex 编译 .C 文件包含库 - 错误 LNK2019:未解析的外部符号 - 对于 NPTrackingTools
compile .C file Include library using mex - error LNK2019: unresolved external symbol - for NPTrackingTools
您好,我正在尝试使用 NPTrackingTools 库提供的外部命令构建简单的 C 函数 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;
}
我尝试了以下编译器代码
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
我的所有文件都在同一个目录下"d:\or hirshfeld\onedrive\work control lab aero summer 2014 technio\C_code"
但是编译器return一个错误,他无法理解我的命令
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
我尝试了不同的变体,但仍然遇到同样的问题,你能帮我吗?
谢谢
或赫斯菲尔德
阿拉伯联合酋长国
您尝试 link 的库 (.lib) 似乎是一个 C++ 库,尽管这些函数有 C 入口点(检查 Dependency Walker)。我通过将 mexFunction
源代码从 .c 重命名为 .cpp,将 header 和源代码放在同一个文件夹中,然后像这样编译:
来编译它
mex -v -L. -lNPTrackingToolsx64 test_C_compile_with_include_trackingtools.cpp
尽管您可以像这样在命令行上简单地列出 object 个文件:
mex -v test_C_compile_with_include_trackingtools.cpp NPTrackingToolsx64.lib
只需先列出源文件,否则输出的 .mexw64 文件将具有库的名称!
另请注意,您将需要 LIBIOMP5MD.DLL 到 运行 代码。这是 Intel 的 OpenMP 运行time 库,你可以在所有地方找到它,因为它可以自由再分发。
您好,我正在尝试使用 NPTrackingTools 库提供的外部命令构建简单的 C 函数 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;
}
我尝试了以下编译器代码
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
我的所有文件都在同一个目录下"d:\or hirshfeld\onedrive\work control lab aero summer 2014 technio\C_code"
但是编译器return一个错误,他无法理解我的命令
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
我尝试了不同的变体,但仍然遇到同样的问题,你能帮我吗?
谢谢
或赫斯菲尔德
阿拉伯联合酋长国
您尝试 link 的库 (.lib) 似乎是一个 C++ 库,尽管这些函数有 C 入口点(检查 Dependency Walker)。我通过将 mexFunction
源代码从 .c 重命名为 .cpp,将 header 和源代码放在同一个文件夹中,然后像这样编译:
mex -v -L. -lNPTrackingToolsx64 test_C_compile_with_include_trackingtools.cpp
尽管您可以像这样在命令行上简单地列出 object 个文件:
mex -v test_C_compile_with_include_trackingtools.cpp NPTrackingToolsx64.lib
只需先列出源文件,否则输出的 .mexw64 文件将具有库的名称!
另请注意,您将需要 LIBIOMP5MD.DLL 到 运行 代码。这是 Intel 的 OpenMP 运行time 库,你可以在所有地方找到它,因为它可以自由再分发。