如何从C++;LuaJIT的可执行文件 我试图把一个Lua脚本加载到我的C++应用程序中并运行它。 我决定使用LuaJIT来利用它的FFI库。 但是我有一个奇怪的问题,我的Lua脚本不能看到我在C++代码中定义的函数符号,而在运行我的应用程序时,我得到这个错误:

如何从C++;LuaJIT的可执行文件 我试图把一个Lua脚本加载到我的C++应用程序中并运行它。 我决定使用LuaJIT来利用它的FFI库。 但是我有一个奇怪的问题,我的Lua脚本不能看到我在C++代码中定义的函数符号,而在运行我的应用程序时,我得到这个错误:,c++,function,symbols,ffi,luajit,C++,Function,Symbols,Ffi,Luajit,未定义的符号:test_func_a 以下是我的C++和Lua Code: //C++// #include <stdlib.h> #include <stdio.h> #include <assert.h> #include <lua.hpp> #ifdef __cplusplus extern "C" { #endif void test_func_a ( void ) { printf ( "hello\n" ); } #ifd

未定义的符号:test_func_a

以下是我的C++和Lua Code:

//C++//

#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <lua.hpp>

#ifdef __cplusplus
  extern "C" {
#endif

void test_func_a ( void ) {
  printf ( "hello\n" );
}

#ifdef __cplusplus
  }
#endif

int main ( int argc, char** argv ) {
  lua_State *lua = luaL_newstate();
  assert ( lua );
  luaL_openlibs ( lua );
  const int status = luaL_dostring ( lua, lua_script_content );

  if ( status )
    printf ( "Couldn't execute LUA code: %s\n", lua_tostring ( lua, -1 ));

  lua_close ( lua );

  return 0;
默认情况下,gcc将导出所有符号,为什么luajit无法看到它们?

使用:

extern "C" __declspec(dllexport) void test_func_a ( void ) {printf ("hello\n" );}

你是如何编译你的C++文件的?你修复了什么以及为什么。
extern "C" __declspec(dllexport) void test_func_a ( void ) {printf ("hello\n" );}