【问题标题】:Compiling Chaiscript with i686-w64-mingw32-g++ fails使用 i686-w64-mingw32-g++ 编译 Chaiscript 失败
【发布时间】:2021-09-29 00:32:45
【问题描述】:

我正在尝试使用 i686-w64-mingw32-g++ 编译器从 Linux 编译一个简单的 chaiscript 示例。我已经让它与 g++ 一起工作,但是在使用命令编译我的应用程序时

i686-w64-mingw32-g++ ./main.cpp -pthread -L/lib/x86_64-linux-gnu/libdl.a -std=c++17

这里是main.cpp的内容

#include "chaiscript/chaiscript.hpp"
#include "chaiscript/chaiscript_stdlib.hpp"

int main()
{
  chaiscript::ChaiScript chai;

  chai.eval(R"(puts("Hello"))");
}

This is the error it gives me

如何修复此错误以便编译我的代码?


编辑:
通过使用 x86_64-w64-mingw32-g++ 而不是 i686-w64-mingw32-g++,我能够走得更远,但现在我收到了这个错误:
/usr/bin/x86_64-w64-mingw32-as: /tmp/ccE1ZcKe.o: too many sections (73147)
/tmp/ccwlaMBb.s: Assembler messages:
/tmp/ccwlaMBb.s: Fatal error: can't write 41 bytes to section .text of /tmp/ccE1ZcKe.o: 'file too big'
/usr/bin/x86_64-w64-mingw32-as: /tmp/ccE1ZcKe.o: too many sections (73147)
/tmp/ccwlaMBb.s: Fatal error: can't close /tmp/ccE1ZcKe.o: file too big

【问题讨论】:

  • 您应该在 ? 中包含您的操作系统和硬件。

标签: c++ c++17 chaiscript


【解决方案1】:

这是使用 cmake 的解决方案:

首先制作一个工具链文件:

# the name of the target operating system
set(CMAKE_SYSTEM_NAME Windows)

 

# which compilers to use
set(CMAKE_C_COMPILER x86_64-w64-mingw32-g++)
set(CMAKE_CXX_COMPILER x86_64-w64-mingw32-g++)

set(CMAKE_FIND_ROOT_PATH /usr/x86_64-w64-mingw32)


# adjust the default behavior of the find commands:
# search headers and libraries in the target environment
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)

 

# search programs in the host environment
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)

下一步是制作实际的 CMakeLists.txt:
# set minimum cmake version
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)

# project name and language
project(HelloWorld LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

 

include(GNUInstallDirs)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR})

# define executable and its source file
add_executable(HelloWorld main.cpp)

if("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
  add_definitions(-O3)
  SET(CMAKE_CXX_FLAGS  "-pthread -Wa,-mbig-obj -static -std=c++17")
  target_link_libraries(HelloWorld PUBLIC "-L/lib/x86_64-linux-gnu/libdl.a")
endif()

之后,运行以下命令进行构建:
mkdir build
cd build
cmake .. -DCMAKE_TOOLCHAIN_FILE=../toolchainfile.cmake
cmake --build .

你现在应该有一个适用于 chaiscript 的 exe 文件

【讨论】:

    【解决方案2】:

    看来您首先需要#include <mutex>。也许你也需要其他人。

    【讨论】:

    • 另见stackoverflow.com/questions/17242516/… -- mingw-w64 的一些二进制发行版不包括标准库的线程部分,因此 OP 可能需要构建或安装不同的发行版或获取线程插件跨度>
    • 很遗憾,这不起作用,但如果您查看编辑,您会看到我为使其发挥更大作用所做的工作。
    猜你喜欢
    • 2016-03-11
    • 2020-09-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-31
    • 1970-01-01
    • 1970-01-01
    • 2022-07-29
    相关资源
    最近更新 更多