1

我正在尝试使用 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"))");
}

这是它给我的错误

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


编辑:
通过使用 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
4

2 回答 2

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 文件
于 2021-09-29T14:17:23.470 回答
0

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

于 2021-09-29T00:37:48.437 回答