使用MatLab dll时出现C++错误:找到一个或多个多重定义的符号
C++ error when using MatLab dll: one or more multiply defined symbols found
我正试图通过使用MCR(MatLab编译器运行时)在C++中使用MatLab函数。然而,当我从C++调用函数时,我遇到了一个错误。
这是我尝试构建时的输出
1>------ Build started: Project: MatLab DLL Test 2, Configuration: Debug x64 ------
1>Compiling...
1>main.cpp
1>libfoo.cpp
1>Generating Code...
1>Linking...
1>libfoo.lib(libfoo.dll) : error LNK2005: "void __cdecl foo(int,class mwArray &,class mwArray const &)" (?foo@@YAXHAEAVmwArray@@AEBV1@@Z) already defined in libfoo.obj
1>libfoo.lib(libfoo.dll) : error LNK2005: "void __cdecl foo(int,class mwArray &,class mwArray const &)" (?foo@@YAXHAEAVmwArray@@AEBV1@@Z) already defined in libfoo.obj
1>C:UsersfmarsmanDocumentsVisual Studio 2008ProjectsProject1MatLab DLL Test 2x64DebugMatLab DLL Test 2.exe : fatal error LNK1169: one or more multiply defined symbols found
1>Build log was saved at "file://c:UsersfmarsmanDocumentsVisual Studio 2008ProjectsProject1MatLab DLL Test 2MatLab DLL Test 2x64DebugBuildLog.htm"
1>MatLab DLL Test 2 - 3 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
这就是我所做的:
我创建了.m文件foo.m:
函数y=foo(x)
y=x+1;
在命令提示符下,我执行了:
mcc–W cpplib:libfoo–T链接:lib-foo
这创建了libfoo.lib、libfoo.h和libfoo.cpp
- 接下来,我在MSVisualStudio2008中创建了一个项目。我将libfoo.cpp添加到"源文件",将libfoo.h添加到"头文件"。我在"配置属性"->"C/C++"->"常规"->"其他包含目录"中添加了三个目录:
C:\Users\fmarsman\Documents\MATLAB\DLL Test 2(所有libfoo.*文件所在的文件夹)
C:\Program Files\MATLAB\MATLAB Compiler Runtime\v82\extern\lib\win64\microsoft(用于mclmcrrt.lib)
C:\MATLAB\R2013b\extern\include(对于mclmcrrt.h)
- 到链接器->输入->我添加的附加依赖项:
"C:\Program Files\MATLAB\MATLAB编译器运行时\v82\extern\lib\win64\microsoft\mclmcrrt.lib"C:\Users\fmarsman\Documents\MATLAB\DLL Test 2\libfoo.lib">
我的源代码:
#include <iostream>
#include <mclmcrrt.h>
#include <mclcppclass.h>
#include <libfoo.h>
using namespace std;
int main( ) {
mclInitializeApplication(NULL,0);
libfooInitialize( );
mwArray y(1, 1, mxDOUBLE_CLASS);
y = 3.0;
const mwArray x = y.Clone();
foo(1,y,x);
mclTerminateApplication( );
libfooTerminate( );
return 0;
} // main
我一整天都在努力寻找解决方案,但没有成功。我真的希望有人能帮我。
从VS studio项目中删除文件libfoo.cpp。您已经导入了libfoo.dll,所以您使用的是libfoo.dll中的函数"foo",所以您不需要将源代码包括在VS项目中。
相关文章:
- 如何在C++中将一个无符号的 int 转换为两个无符号的短裤?
- 为什么我必须在C++中添加一个赋值符号来声明一个数组
- MacOS 上的 Xcode 11 项目不在一个函数中使用 sin 和 cos:未定义的符号"___sincosf_stret"
- 为什么不建议使用宏符号常量定义一个固定长度的数组呢
- 类模板上一个特定函数的未解析外部符号
- 使用无符号int作为二进制来在c++中实现一个集
- 编译了一个recent-C++.因此,如果没有暴露std符号,请在旧系统上运行
- 我没有得到一个数字作为输出,而是一个表情符号
- 为无符号字符* 分配一个数字
- 编写一个程序,输入整数 n 并打印该数字的字符数(符号除外)
- 我正在为学校开发一个小班模板实验室,我的代码无法编译,它给了我一个未解析的外部符号
- 需要的具体示例.错误:已经定义的.OBJ 一个或多个多个定义的符号
- 给定一个无符号整数,很容易交换每个偶数位和奇数位。这可以推广到交换每个偶数和奇数n位吗?
- 当我尝试将文件添加到另一个文件时出现怪异符号时
- C ++读取用户输入的字符一个一个符号
- 在链接链接静态(GSOAP)库的共享库时,为什么会得到一个未定义的符号
- 致命错误LNK1169:在C++Visual Studio中编写战舰游戏时发现的一个或多个多重定义的符号
- 给定一个填充无符号字符**的 C 函数,如何在没有中间副本的情况下用数据填充 std::vector
- 找到一个或多个乘法定义的符号LNK1169错误
- 'char' c++ 类型的数组中的最后一个符号