diff --git a/CMakeLists.txt b/CMakeLists.txt index 65b3d28e..015896b8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -256,6 +256,8 @@ if (DO_TESTS OR DO_EXAMPLES) if (IS_X86) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32") + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -m32") + set(CMAKE_EXECUTABLE_LINKER_FLAGS "${CMAKE_EXECUTABLE_LINKER_FLAGS} -m32") endif() set(CMAKE_THREAD_PREFER_PTHREAD TRUE) set(THREADS_PREFER_PTHREAD_FLAG TRUE) diff --git a/docs/source/api/usertype.rst b/docs/source/api/usertype.rst index 3802cbb6..a891a488 100644 --- a/docs/source/api/usertype.rst +++ b/docs/source/api/usertype.rst @@ -286,7 +286,7 @@ usertype arguments - simple usertype runtime functions ----------------- -You can add functions at runtime **to the whole class**. Set a name under the metatable name you bound using ``new_usertype``/``new_simple_usertype`` to an object. For example: +You can add functions at runtime **to the whole class** (not to individual objects). Set a name under the metatable name you bound using ``new_usertype``/``new_simple_usertype`` to an object. For example: .. code-block:: cpp :linenos: @@ -393,6 +393,9 @@ compilation speed If you find that compilation times are too long and you're only binding member functions, consider perhaps using :doc:`simple usertypes`. This can reduce compile times (but may cost memory size and speed). See the simple usertypes documentation for more details. +.. note:: + + MSVC and clang/gcc may need additional compiler flags to handle compiling extensive use of usertypes. See: :ref:`the error documentation` for more details. performance note ---------------- @@ -401,14 +404,6 @@ performance note Note that performance for member function calls goes down by a fixed overhead if you also bind variables as well as member functions. This is purely a limitation of the Lua implementation and there is, unfortunately, nothing that can be done about it. If you bind only functions and no variables, however, Sol will automatically optimize the Lua runtime and give you the maximum performance possible. *Please consider ease of use and maintenance of code before you make everything into functions.* - -MSVC note ---------- - -.. note:: - - When using usertype templates extensively, MSVC may invoke `compiler error C1128 `_ , which is solved by using the `/bigobj compilation flag `_. - .. _destructible: http://en.cppreference.com/w/cpp/types/is_destructible .. _default_constructible: http://en.cppreference.com/w/cpp/types/is_constructible .. _runtime extensible: https://github.com/ThePhD/sol2/blob/develop/examples/usertype_advanced.cpp#L81 diff --git a/docs/source/errors.rst b/docs/source/errors.rst index 9c49ed26..4d56ac20 100644 --- a/docs/source/errors.rst +++ b/docs/source/errors.rst @@ -10,6 +10,8 @@ Running Scripts Scripts can have syntax errors, can load from the file system wrong, or have runtime issues. Knowing which one can be troublesome. There are various small building blocks to load and run code, but to check errors you can use the overloaded :ref:`script/script_file functions on sol::state/sol::state_view`, specifically the ``safe_script`` variants. These also take an error callback that is called only when something goes wrong, and Sol comes with some default error handlers in the form of ``sol::script_default_on_error`` and ``sol::script_pass_on_error``. +.. _compilation_errors_warnings: + Compiler Errors / Warnings -------------------------- @@ -18,6 +20,7 @@ A myriad of compiler errors can occur when something goes wrong. Here is some ba * If there are a myriad of errors relating to ``std::index_sequence``, type traits, and other ``std::`` members, it is likely you have not turned on your C++14 switch for your compiler. Visual Studio 2015 turns these on by default, but g++ and clang++ do not have them as defaults and you should pass the flag ``--std=c++1y`` or ``--std=c++14``, or similar for your compiler. * Sometimes, a generated usertype can be very long if you are binding a lot of member functions. You may end up with a myriad of warnings about debug symbols being cut off or about ``__LINE_VAR`` exceeding maximum length. You can silence these warnings safely for some compilers. * Template depth errors may also be a problem on earlier versions of clang++ and g++. Use ``-ftemplate-depth`` compiler flag and specify really high number (something like 2048 or even double that amount) to let the compiler work freely. Also consider potentially using :doc:`simple usertypes` to save compilation speed. +* When using usertype templates extensively, MSVC may invoke `compiler error C1128 `_ , which is solved by using the `/bigobj compilation flag `_. * If you have a move-only type, that type may need to be made ``readonly`` if it is bound as a member variable on a usertype or bound using ``state_view::set_function``. See :doc:`sol::readonly` for more details. * Assigning a ``std::string`` or a ``std::pair`` using ``operator=`` after it's been constructed can result in compiler errors when working with ``sol::function`` and its results. See `this issue for fixes to this behavior`_. * Sometimes, using ``__stdcall`` in a 32-bit (x86) environment on VC++ can cause problems binding functions because of a compiler bug. We have a prelimanry fix in, but if it doesn't work and there are still problems: put the function in a ``std::function`` to make the compiler errors and other problems go away. Also see `this __stdcall issue report`_ for more details. diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index f17634f5..c8971450 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -81,9 +81,6 @@ function (MAKE_EXAMPLE example_source_file is_single) target_compile_options(${example_name} PRIVATE -Wno-noexcept-type) endif() - if (IS_X86) - target_compile_options(${example_name} BEFORE PRIVATE -m32) - endif() if (TESTS_EXAMPLES) if ((NOT is_single) OR (is_single AND TESTS_SINGLE)) diff --git a/examples/require_dll_example/CMakeLists.txt b/examples/require_dll_example/CMakeLists.txt index a8819d4e..88001890 100644 --- a/examples/require_dll_example/CMakeLists.txt +++ b/examples/require_dll_example/CMakeLists.txt @@ -99,10 +99,6 @@ function(make_require_from_dll_example target_lib is_single) target_link_libraries(${example_name} PRIVATE ${LUA_LIBRARIES}) endif() target_include_directories(${example_name} PRIVATE ${LUA_INCLUDE_DIRS}) - if (IS_X86) - target_compile_options(${example_name} BEFORE PRIVATE -m32) - endif() - if (TESTS_DYNAMIC_LOADING_EXAMPLES) if ((NOT is_single) OR (is_single AND DYNAMIC_LOADING_EXAMPLES_SINGLE)) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 991c020d..bb6017f6 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -56,11 +56,10 @@ function(CREATE_TEST test_target_name test_name is_single) PRIVATE -Wno-noexcept-type -ftemplate-depth=1024 -pthread) if (IS_X86) - target_compile_options(${test_target_name} BEFORE PRIVATE -m32) if(MINGW) - #set_target_properties(${test_target_name} - # PROPERTIES - # LINK_FLAGS -static-libstdc++) + set_target_properties(${test_target_name} + PROPERTIES + LINK_FLAGS -static-libstdc++) endif() endif() endif()