如何解决从 macOS 为 Windows 交叉编译? - i686-w64-mingw32-ld:错误:无法消除歧义:-search_paths_first你的意思是--search_paths_first?
尝试交叉编译,这里是最小的例子CMakeLists.txt
cmake_minimum_required(VERSION 3.0)
project(hello VERSION 0.0.0 LANGUAGES C)
set(src "${CMAKE_CURRENT_BINARY_DIR}/src/main.c")
file(WRITE "${src}" "int main(){}")
add_executable(${PROJECT_NAME} "${src}")
$ brew install mingw-w64
$ mkdir 'cmake-build-win64-debug' && cd "$_"
$ cmake .. \
-DCMAKE_BUILD_TYPE='Debug' \
-DCMAKE_C_COMPILER='i686-w64-mingw32-gcc' \
-DCMAKE_CXX_COMPILER='i686-w64-mingw32-g++'
-- The C compiler identification is GNU 10.3.0
-- The CXX compiler identification is GNU 10.3.0
-- Checking whether C compiler has -isysroot
-- Checking whether C compiler has -isysroot - yes
-- Checking whether C compiler supports OSX deployment target flag
-- Checking whether C compiler supports OSX deployment target flag - no
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: /usr/local/bin/i686-w64-mingw32-gcc
-- Check for working C compiler: /usr/local/bin/i686-w64-mingw32-gcc - broken
CMake Error at /usr/local/Cellar/cmake/3.20.1/share/cmake/Modules/CMakeTestCCompiler.cmake:66 (message):
The C compiler
"/usr/local/bin/i686-w64-mingw32-gcc"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: cmake-build-win64-debug/CMakeFiles/CMakeTmp
Run Build Command(s):/usr/bin/make -f Makefile cmTC_f30ca/fast && /Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/cmTC_f30ca.dir/build.make CMakeFiles/cmTC_f30ca.dir/build
Building C object CMakeFiles/cmTC_f30ca.dir/testCCompiler.c.o
/usr/local/bin/i686-w64-mingw32-gcc -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk -o CMakeFiles/cmTC_f30ca.dir/testCCompiler.c.o -c cmake-build-win64-debug/CMakeFiles/CMakeTmp/testCCompiler.c
Linking C executable cmTC_f30ca
/usr/local/Cellar/cmake/3.20.1/bin/cmake -E cmake_link_script CMakeFiles/cmTC_f30ca.dir/link.txt --verbose=1
/usr/local/bin/i686-w64-mingw32-gcc -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk -Wl,-search_paths_first -Wl,-headerpad_max_install_names CMakeFiles/cmTC_f30ca.dir/testCCompiler.c.o -o cmTC_f30ca
/usr/local/Cellar/mingw-w64/8.0.0_4/toolchain-i686/bin/i686-w64-mingw32-ld: Error: unable to disambiguate: -search_paths_first (did you mean --search_paths_first ?)
collect2: error: ld returned 1 exit status
make[1]: *** [cmTC_f30ca] Error 1
make: *** [cmTC_f30ca/fast] Error 2
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:3 (project)
-- Configuring incomplete,errors occurred!
See also "cmake-build-win64-debug/CMakeFiles/CMakeOutput.log".
See also "cmake-build-win64-debug/CMakeFiles/CMakeError.log".
所以我尝试了https://stackoverflow.com/a/54482619,特别是
-DCMAKE_CXX_LINK_FLAGS='' \
-DHAVE_FLAG_SEARCH_PATHS_FIRST=0
但这并没有解决问题。如何从 macOS 为 Windows 构建?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。