10

I'm planning to create a new C++ project, write some C++ functions in it, embed a Lua engine with wxLua into it, make my C/C++ functions available to a Lua side and then write my main program (including the GUI) in Lua.

My IDE/compiler are Code::Blocks/GCC on Windows. I want to compile it for Windows, Linux and OSX.

My issues:

  • compiling wxWidgets and Lua
  • building wxLua
  • creating a cross-platform project that knows which libs to use for which OS

I read a lot of documentation on wxLua and found that you should probably use wxWidgets 2.8.12 and Lua 5.2.3 (as they are the two latest stable and supported versions).

If possible, I'd like the program to be a standalone executable in the end.
So I guess I need to compile Lua and wxWidgets as .lib libraries (Windows) and .a libraries (Linux/OSX), is that correct? How would I do that?

Once that is done, what kind of project do I need to create and how would I embed wxLua into that project? I couldn't find a lot of information on that.

And finally, how would I tell my IDE/project/makefile(?) which libraries to use for which OS?

4

1 回答 1

5

以下是我如何在 Windows/OSX/Linux 上为我的跨平台项目编译 wxwidgets/wxlua 的说明,但我使用 gcc/mingw-tdm 而不是 Code::Blocks,因此您可能需要调整它们以适应您的环境。

以下是在 Windows 上构建 wxwidgets 的方法:

  ./configure --prefix="$INSTALL_DIR" --disable-shared --enable-unicode \
    --enable-compat28 \
    --with-libjpeg=builtin --with-libpng=builtin --with-libtiff=no --with-expat=no \
    --with-zlib=builtin --disable-richtext \
    CFLAGS="-Os -fno-keep-inline-dllexport" CXXFLAGS="-Os -fno-keep-inline-dllexport"
  make
  make install

这是在 Windows 上构建 wxlua 的方法:

  cmake -G "MSYS Makefiles" -DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" -DCMAKE_BUILD_TYPE=MinSizeRel -DBUILD_SHARED_LIBS=FALSE \
    -DwxWidgets_CONFIG_EXECUTABLE="$INSTALL_DIR/bin/wx-config" \
    -DwxWidgets_COMPONENTS="stc;html;aui;adv;core;net;base" \
    -DwxLuaBind_COMPONENTS="stc;html;aui;adv;core;net;base" -DwxLua_LUA_LIBRARY_USE_BUILTIN=FALSE \
    -DwxLua_LUA_INCLUDE_DIR="$INSTALL_DIR/include" -DwxLua_LUA_LIBRARY="$INSTALL_DIR/lib/lua51.dll" .
  (cd modules/luamodule; make)
  (cd modules/luamodule; make install/strip)

您需要更新 wxlua 构建指令以使用 Lua5.2 而不是我正在使用的 Lua5.1。

我在这个存储库中有适用于WindowsOSXLinux的构建脚本。这些脚本已经在最新的 wxwidgets 和 wxlua 版本上进行了测试(使用两个存储库的主干)。它们生成一个链接到 Lua dll 的 wxlua 库(在 Windows 上),因此它可能不是您正在寻找的静态配置,但是静态构建可能会阻止您加载其他 Lua 库(除非您导出正确的符号并提供代理 DLL如此处所述),所以我不推荐该配置。

此外,我仍在使用 Lua5.1 和 wxlua 和 wxwidgets,因为这允许我使用 LuaJIT 作为替代品,以便在某些情况下获得更好的性能。如果你用 Lua 5.2 编译 wxlua,你将没有这个选项,因为它们的 ABI 不同。

在与您自己的基于 C++ 的工具包集成方面,最好的选择可能是将其公开为 Lua 库并从 wxlua 应用程序加载,就像您加载任何其他库一样,因为它允许您保持组件彼此独立。

于 2015-04-12T20:37:12.027 回答