C++ Unresolved External Symbols Embedded Lua(基于longjmp问题)(非重复)

我将描述问题如下:

编译器:Visual Studio 2019

问题的根源是手动将我的代码映射到进程中,因此longjump会导致进程崩溃。

代码按如下方式工作得很好,但由于longjump,lua脚本中的任何语法错误都会导致崩溃:

extern "C" {
#include "lua.h"
#include "lualib.h"
.....
}

我希望C++异常源自:

#if defined(__cplusplus) && !defined(LUA_USE_LONGJMP) /* { */

/* C++ exceptions */
#define LUAI_THROW(L,c) throw(c)
#define LUAI_TRY(L,c,a) \
try { a } catch(...) { if ((c)->status == 0) (c)->status = -1; }
#define luai_jmpbuf int /* dummy variable */

#elif defined(LUA_USE_POSIX) /* }{ */

/* in POSIX, try _longjmp/_setjmp (more efficient) */
#define LUAI_THROW(L,c) _longjmp((c)->b, 1)
#define LUAI_TRY(L,c,a) if (_setjmp((c)->b) == 0) { a }
#define luai_jmpbuf jmp_buf

#else /* }{ */

/* ISO C handling with long jumps */
#define LUAI_THROW(L,c) longjmp((c)->b, 1)
#define LUAI_TRY(L,c,a) if (setjmp((c)->b) == 0) { a }
#define luai_jmpbuf jmp_buf

#endif /* } */

因为longjmp会导致我的进程崩溃。

因此,我决定使用C++编译器(不使用extern C)编译我的代码,并将以下内容包含:

#include "lua.h"
#include "lualib.h"
.....

这是我调用它的方式。但这也导致了以下问题: 错误LNK2019:无法解析的外部符号_lua_pcall ... ... ...

我想了很多,但找不到解决方案。这是荒谬的,因为所有的lua头文件和c文件都加入了我的项目中。

原文链接 https://stackoverflow.com/questions/70115255

点赞
stackoverflow用户14902625
stackoverflow用户14902625
#define LUAI_THROW(L,c) c->throwed = true
#define LUAI_TRY(L,c,a) \
    __try { a } __except(filter()) { if ((c)->status == 0 && ((c)->throwed)) (c)->status = -1; }
#define luai_jmpbuf     int  /* dummy variable */

顺便说一下,我已经解决了我的抛出异常问题。我不确定是否正确,但不会再崩溃了。

struct lua_longjmp {
  struct lua_longjmp *previous;
  luai_jmpbuf b;
  volatile int status;  /* error code */
  bool throwed;
};

即使没有使用C ++异常,也能按预期工作。

2021-11-25 21:42:03