I called matlab function in C++ and got LNK2001 error.
古いコメントを表示
Hello
C:\Program Files\MATLAB\MATLAB Runtime\v97\extern\lib\win64\mingw64
C:\Program Files\MATLAB\MATLAB Runtime\v97\extern\lib\win64\microsoft
C:\Program Files\MATLAB\MATLAB Runtime\v97\extern\include
C:\Program Files\MATLAB\MATLAB Runtime\v97\bin\win64
C:\Program Files\MATLAB\MATLAB Runtime\v97\lib\win64
C:\Program Files\MATLAB\MATLAB Runtime\v97\runtime\win64
I have already added the above paths to the project.
mclbase.lib, mclcommain.lib, mclmcr.lib, mclmcrrt.lib and mclxlmain.lib were also added.
This causes a LNK2001 unresolved external symbol error in the GT_model function.
The other GT_modelInitialize and mclInitializeApplication functions seem to work well
it seems that lib or dll is added well
GT_model(1, y_pwrOut, inputIn) is not work
i got LNK2001 unrresolved error
I don't know what's wrong.
Thank you for any advice.
Main.cpp
------------------------------------------------------------------------------------
#include <iostream>
#include "GT_model.h"
void GT_modelSample()
{
mxDouble inputInData[] = { -20.0, 101.325, 0.6, 321.3713, -20.0, 100.8011, 281.3149, 873.2329, 2.5707, 200.0, 49492.4247435387, 357.7379, 121.1334, 357.7379, 102.0625, 0.0, 3600.0 };
mwArray inputIn(1, 17, mxDOUBLE_CLASS);
inputIn.SetData(inputInData, 17);
std::cout << "4\n";
mwArray y_pwrOut;
mxArray *plhs;
mxDouble *prhs;
try
{
GT_model(1, y_pwrOut, inputIn);
std::cout << y_pwrOut << std::endl;
std::cout << "5\n";
}
catch (const mwException & e)
{
std::cerr << e.what() << std::endl;
}
catch (...)
{
std::cerr << "Unexpected error thrown" << std::endl;
}
}
int run_main(int argc, const char** argv)
{
std::cout << "2\n";
if (!GT_modelInitialize())
{
std::cerr << "Could not initialize the library properly" << std::endl;
return -2;
}
else
{
std::cout << "3\n";
GT_modelSample();
std::cout << "6\n";
// Call the application and library termination routine
GT_modelTerminate();
std::cout << "7\n";
}
// Note that you should call mclTerminateApplication at the end of
// your application to shut down all MATLAB Runtime instances.
mclTerminateApplication();
std::cout << "8\n";
return 0;
}
// The main routine. On macOS, the main thread runs the system code, and
// user code must be processed by a secondary thread. On other platforms,
// the main thread runs both the system code and the user code.
int main(int argc, const char** argv)
{
/* Call the mclInitializeApplication routine. Make sure that the application
* was initialized properly by checking the return status. This initialization
* has to be done before calling any MATLAB APIs or MATLAB Compiler SDK
* generated shared library functions.
*/
if (!mclmcrInitialize()) {
std::cerr << "Could not initialize the application." << std::endl;
return -1;
}
if (!mclInitializeApplication(nullptr, 0))
{
std::cerr << "Could not initialize the application." << std::endl;
return -1;
}
std::cout << "1\n";
return mclRunMain(static_cast<mclMainFcnType>(run_main), argc, argv);
}
---------------------------------------------------------------------------------
GT_model.h
---------------------------------------------------------------------------------
//
// MATLAB Compiler: 7.1 (R2019b)
// Date: Wed Feb 5 15:51:57 2020
// Arguments:
// "-B""macro_default""-W""cpplib:GT_model,all,version=1.0""-T""link:lib""-d""C:
// \Users\sergey.mishchenko\Desktop\dll
// file\GT_model\for_testing""-v""C:\Users\sergey.mishchenko\Desktop\dll
// file\GT_model.m"
//
#ifndef GT_model_h
#define GT_model_h 1
#if defined(__cplusplus) && !defined(mclmcrrt_h) && defined(__linux__)
# pragma implementation "mclmcrrt.h"
#endif
#include "mclmcrrt.h"
#include "mclcppclass.h"
#ifdef __cplusplus
extern "C" { // sbcheck:ok:extern_c
#endif
/* This symbol is defined in shared libraries. Define it here
* (to nothing) in case this isn't a shared library.
*/
#ifndef LIB_GT_model_C_API
#define LIB_GT_model_C_API /* No special import/export declaration */
#endif
/* GENERAL LIBRARY FUNCTIONS -- START */
extern LIB_GT_model_C_API
bool MW_CALL_CONV GT_modelInitializeWithHandlers(
mclOutputHandlerFcn error_handler,
mclOutputHandlerFcn print_handler);
extern LIB_GT_model_C_API
bool MW_CALL_CONV GT_modelInitialize(void);
extern LIB_GT_model_C_API
void MW_CALL_CONV GT_modelTerminate(void);
extern LIB_GT_model_C_API
void MW_CALL_CONV GT_modelPrintStackTrace(void);
/* GENERAL LIBRARY FUNCTIONS -- END */
/* C INTERFACE -- MLX WRAPPERS FOR USER-DEFINED MATLAB FUNCTIONS -- START */
extern LIB_GT_model_C_API
bool MW_CALL_CONV mlxGT_model(int nlhs, mxArray *plhs[], int nrhs, mxArray *prhs[]);
/* C INTERFACE -- MLX WRAPPERS FOR USER-DEFINED MATLAB FUNCTIONS -- END */
#ifdef __cplusplus
}
#endif
/* C++ INTERFACE -- WRAPPERS FOR USER-DEFINED MATLAB FUNCTIONS -- START */
#ifdef __cplusplus
/* On Windows, use __declspec to control the exported API */
#if defined(_MSC_VER) || defined(__MINGW64__)
#ifdef EXPORTING_GT_model
#define PUBLIC_GT_model_CPP_API __declspec(dllexport)
#else
#define PUBLIC_GT_model_CPP_API __declspec(dllimport)
#endif
#define LIB_GT_model_CPP_API PUBLIC_GT_model_CPP_API
#else
#if !defined(LIB_GT_model_CPP_API)
#if defined(LIB_GT_model_C_API)
#define LIB_GT_model_CPP_API LIB_GT_model_C_API
#else
#define LIB_GT_model_CPP_API /* empty! */
#endif
#endif
#endif
extern LIB_GT_model_CPP_API void MW_CALL_CONV GT_model(int nargout, mwArray& y_pwr, const mwArray& input);
/* C++ INTERFACE -- WRAPPERS FOR USER-DEFINED MATLAB FUNCTIONS -- END */
#endif
#endif
---------------------------------------------------------------------------------
7 件のコメント
Walter Roberson
2020 年 2 月 20 日
Which symbol is noted as unresolved?
HYUK MYEONG KWON
2020 年 2 月 20 日
編集済み: HYUK MYEONG KWON
2020 年 2 月 20 日
Walter Roberson
2020 年 2 月 20 日
I see interfaces defined to call GT_model from MATLAB but I do not see you listing any dll or lib that defines GT_model?
HYUK MYEONG KWON
2020 年 2 月 20 日
Walter Roberson
2020 年 2 月 21 日
Would it be possible to post the entire build log?
HYUK MYEONG KWON
2020 年 2 月 21 日
HYUK MYEONG KWON
2020 年 2 月 21 日
回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Deploy to C++ Applications Using mwArray API (C++03) についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!