重现问题的脚本:
#!/bin/bash
set -ex
rm -rf /tmp/x
cd /tmp
mkdir x
cd x
mkdir lib
cat > lib/f.c << EOF
#include <stdio.h>
void f(void){puts("hello");}
EOF
mkdir exe
cat > exe/main.c << EOF
void f(void);
int main(){f();}
EOF
(
cd lib
libtool c --tag=CC gcc -c f.c
libtool l --tag=CC gcc -rpath /usr/local/lib -no-undefined -o libf.la f.lo
)
(
cd exe
libtool c --tag=CC gcc -c main.c
libtool l --tag=CC gcc -o main main.lo ../lib/libf.la
)
exe/main.exe
exe/main.exe --lt-debug
exe/.libs/main.exe || echo failed
export PATH="/tmp/x/lib/.libs:$PATH"
exe/main.exe
exe/main.exe --lt-debug
exe/.libs/main.exe || echo failed
输出:
+ rm -rf /tmp/x
+ cd /tmp
+ mkdir x
+ cd x
+ mkdir lib
+ cat
+ mkdir exe
+ cat
+ cd lib
+ libtool c --tag=CC gcc -c f.c
libtool: compile: gcc -c f.c -DDLL_EXPORT -DPIC -o .libs/f.o
libtool: compile: gcc -c f.c -o f.o >/dev/null 2>&1
+ libtool l --tag=CC gcc -rpath /usr/local/lib -no-undefined -o libf.la f.lo
libtool: link: gcc -shared .libs/f.o -o .libs/msys-f-0.dll -Wl,--enable-auto-image-base -Xlinker --out-implib -Xlinker .libs/libf.dll.a
libtool: link: ar cru .libs/libf.a f.o
libtool: link: ranlib .libs/libf.a
libtool: link: ( cd ".libs" && rm -f "libf.la" && cp -pR "../libf.la" "libf.la" )
+ cd exe
+ libtool c --tag=CC gcc -c main.c
libtool: compile: gcc -c main.c -DDLL_EXPORT -DPIC -o .libs/main.o
libtool: compile: gcc -c main.c -o main.o >/dev/null 2>&1
+ libtool l --tag=CC gcc -o main main.lo ../lib/libf.la
libtool: link: gcc -o .libs/main .libs/main.o ../lib/.libs/libf.dll.a -L/usr/local/lib
+ exe/main.exe
+ exe/main.exe --lt-debug
main.exe:./.libs/lt-main.c:231: libtool wrapper (GNU libtool) 2.4.6
main.exe:./.libs/lt-main.c:232: (main) argv[0]: C:\msys64\tmp\x\exe\main.exe
main.exe:./.libs/lt-main.c:233: (main) program_name: main.exe
main.exe:./.libs/lt-main.c:394: (find_executable): C:\msys64\tmp\x\exe\main.exe
main.exe:./.libs/lt-main.c:349: (check_executable): C:\msys64\tmp\x\exe\main.exe
main.exe:./.libs/lt-main.c:238: (main) found exe (before symlink chase) at: C:\msys64\tmp\x\exe\main.exe
main.exe:./.libs/lt-main.c:243: (main) found exe (after symlink chase) at: C:\msys64\tmp\x\exe\main.exe
main.exe:./.libs/lt-main.c:266: (main) libtool target name: main.exe
main.exe:./.libs/lt-main.c:617: (lt_setenv) setting 'BIN_SH' to 'xpg4'
main.exe:./.libs/lt-main.c:617: (lt_setenv) setting 'DUALCASE' to '1'
main.exe:./.libs/lt-main.c:667: (lt_update_exe_path) modifying 'PATH' by prepending '/tmp/x/lib/.libs:/usr/local/lib:/usr/local/bin:'
main.exe:./.libs/lt-main.c:617: (lt_setenv) setting 'PATH' to '/tmp/x/lib/.libs:/usr/local/lib:/usr/local/bin:C:\msys64\mingw64\bin;C:\msys64\usr\local\bin;C:\msys64\usr\bin;C:\msys64\usr\bin;C:\Windows\System32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\msys64\usr\bin\site_perl;C:\msys64\usr\bin\vendor_perl;C:\msys64\usr\bin\core_perl'
main.exe:./.libs/lt-main.c:688: (lt_update_lib_path) modifying 'PATH' by prepending '/tmp/x/lib/.libs:'
main.exe:./.libs/lt-main.c:617: (lt_setenv) setting 'PATH' to '/tmp/x/lib/.libs:/tmp/x/lib/.libs:/usr/local/lib:/usr/local/bin:C:\msys64\mingw64\bin;C:\msys64\usr\local\bin;C:\msys64\usr\bin;C:\msys64\usr\bin;C:\Windows\System32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\msys64\usr\bin\site_perl;C:\msys64\usr\bin\vendor_perl;C:\msys64\usr\bin\core_perl'
main.exe:./.libs/lt-main.c:298: (main) lt_argv_zero: C:\msys64\tmp\x\exe\.libs/main.exe
main.exe:./.libs/lt-main.c:302: (main) newargz[0]: C:\msys64\tmp\x\exe\.libs/main.exe
+ exe/.libs/main.exe
C:/msys64/tmp/x/exe/.libs/main.exe: error while loading shared libraries: msys-f-0.dll: cannot open shared object file: No such file or directory
+ echo failed
failed
+ export PATH=/tmp/x/lib/.libs:/mingw64/bin:/usr/local/bin:/usr/bin:/bin:/c/Windows/System32:/c/Windows:/c/Windows/System32/Wbem:/c/Windows/System32/WindowsPowerShell/v1.0/:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl
+ PATH=/tmp/x/lib/.libs:/mingw64/bin:/usr/local/bin:/usr/bin:/bin:/c/Windows/System32:/c/Windows:/c/Windows/System32/Wbem:/c/Windows/System32/WindowsPowerShell/v1.0/:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl
+ exe/main.exe
+ exe/main.exe --lt-debug
main.exe:./.libs/lt-main.c:231: libtool wrapper (GNU libtool) 2.4.6
main.exe:./.libs/lt-main.c:232: (main) argv[0]: C:\msys64\tmp\x\exe\main.exe
main.exe:./.libs/lt-main.c:233: (main) program_name: main.exe
main.exe:./.libs/lt-main.c:394: (find_executable): C:\msys64\tmp\x\exe\main.exe
main.exe:./.libs/lt-main.c:349: (check_executable): C:\msys64\tmp\x\exe\main.exe
main.exe:./.libs/lt-main.c:238: (main) found exe (before symlink chase) at: C:\msys64\tmp\x\exe\main.exe
main.exe:./.libs/lt-main.c:243: (main) found exe (after symlink chase) at: C:\msys64\tmp\x\exe\main.exe
main.exe:./.libs/lt-main.c:266: (main) libtool target name: main.exe
main.exe:./.libs/lt-main.c:617: (lt_setenv) setting 'BIN_SH' to 'xpg4'
main.exe:./.libs/lt-main.c:617: (lt_setenv) setting 'DUALCASE' to '1'
main.exe:./.libs/lt-main.c:667: (lt_update_exe_path) modifying 'PATH' by prepending '/tmp/x/lib/.libs:/usr/local/lib:/usr/local/bin:'
main.exe:./.libs/lt-main.c:617: (lt_setenv) setting 'PATH' to '/tmp/x/lib/.libs:/usr/local/lib:/usr/local/bin:C:\msys64\tmp\x\lib\.libs;C:\msys64\mingw64\bin;C:\msys64\usr\local\bin;C:\msys64\usr\bin;C:\msys64\usr\bin;C:\Windows\System32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\msys64\usr\bin\site_perl;C:\msys64\usr\bin\vendor_perl;C:\msys64\usr\bin\core_perl'
main.exe:./.libs/lt-main.c:688: (lt_update_lib_path) modifying 'PATH' by prepending '/tmp/x/lib/.libs:'
main.exe:./.libs/lt-main.c:617: (lt_setenv) setting 'PATH' to '/tmp/x/lib/.libs:/tmp/x/lib/.libs:/usr/local/lib:/usr/local/bin:C:\msys64\tmp\x\lib\.libs;C:\msys64\mingw64\bin;C:\msys64\usr\local\bin;C:\msys64\usr\bin;C:\msys64\usr\bin;C:\Windows\System32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\msys64\usr\bin\site_perl;C:\msys64\usr\bin\vendor_perl;C:\msys64\usr\bin\core_perl'
main.exe:./.libs/lt-main.c:298: (main) lt_argv_zero: C:\msys64\tmp\x\exe\.libs/main.exe
main.exe:./.libs/lt-main.c:302: (main) newargz[0]: C:\msys64\tmp\x\exe\.libs/main.exe
+ exe/.libs/main.exe
hello
要注意的事项:exe/main.exe
中的包装器永远不会正确执行。它也不会返回错误(请注意我们有set -e
)。它始终无声地失败,无需打印"hello"
。 exe/.libs/main.exe
中的真实可执行文件按预期报告丢失的DLL。如果我手动将该DLL的路径(/tmp/x/lib/.libs
)添加到PATH
环境变量,则真正的可执行文件可以正常工作,但包装器仍会无提示失败。
请注意,从--lt-debug
输出中,包装似乎做了正确的事情,将正确的目录添加到PATH
。
gcc -v
:
Using built-in specs.
COLLECT_GCC=C:\msys64\mingw64\bin\gcc.exe
COLLECT_LTO_WRAPPER=C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/6.3.0/lto-wrapper.exe
Target: x86_64-w64-mingw32
Configured with: ../gcc-6.3.0/configure --prefix=/mingw64 --with-local-prefix=/mingw64/local --build=x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --with-native-system-header-dir=/mingw64/x86_64-w64-mingw32/include --libexecdir=/mingw64/lib --enable-bootstrap --with-arch=x86-64 --with-tune=generic --enable-languages=c,lto,c++,objc,obj-c++,fortran,ada --enable-shared --enable-static --enable-libatomic --enable-threads=posix --enable-graphite --enable-fully-dynamic-string --enable-libstdcxx-time=yes --disable-libstdcxx-pch --disable-libstdcxx-debug --disable-isl-version-check --enable-lto --enable-libgomp --disable-multilib --enable-checking=release --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --with-libiconv --with-system-zlib --with-gmp=/mingw64 --with-mpfr=/mingw64 --with-mpc=/mingw64 --with-isl=/mingw64 --with-pkgversion='Rev3, Built by MSYS2 project' --with-bugurl=https://sourceforge.net/projects/msys2 --with-gnu-as --with-gnu-ld
Thread model: posix
gcc version 6.3.0 (Rev3, Built by MSYS2 project)
libtool -v
:
libtool (GNU libtool) 2.4.6
Written by Gordon Matzigkeit, 1996
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
答案 0 :(得分:1)
我使用的是MinGW-w64 Win64 Shell
,但我使用了错误的libtool
。做
pacman -R libtool
pacman -S mingw64/mingw-w64-x86_64-libtool
解决了这个问题。
普通libtool
包中的libtool
以MSYS2本身为目标,可能是MSYS2 Shell
中使用的正确选项。