在我阅读了几篇关于我的问题的论坛帖子后,这些帖子对我没有任何帮助,我向您寻求帮助。我正在尝试在 Windows 上使用 GNU 编译器创建 .dll。这个 .dll 需要一个库(我们现在称之为 mylib)才能工作。所以我创建一个静态库 mylib.a :
ar rcs mylib.a file1.o file2.o file3.o file4.o
我单独创建了 .o 文件
g++ -c file1.cpp.
现在要创建 .dll 并链接 mylib.a,我输入以下命令:
g++ -shared -o mydll.dll Dynamicfunc.cpp -l:mylib.a
其中 Dynamicfunc.cpp 包含 .dll 的实现。执行该命令时,出现以下错误信息:
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -l:mylib.a: No such file or directory
collect2.exe: error: ld returned 1 exit status
在有关此主题的大多数帖子中,问题的解决方案是添加前缀“lib”。所以在我的例子中 -l:libmylib.a 不幸的是也不起作用。此外,mylib.a 文件与 Dynamicfunc.cpp 位于同一目录中,这使得不需要使用 -L,但即使使用 -L:C:......\src,ld.exe 也找不到指定的 mylib.a文件。如果我将所有目标文件(file1.o file2.o...)转换为 .lib 而不是 .a 库,它也不起作用。此外,我尝试创建 mylib.a 而不
ar rcs libout.a ...
但与
g++ -static -o mylib.a file1.o file2.o ...
也没有成功。我真的很感激任何建议。g++ -v:
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=C:/mingw64/bin/../libexec/gcc/x86_64-w64-mingw32/13.2.0/lto-wrapper.exe
OFFLOAD_TARGET_NAMES=nvptx-none
Target: x86_64-w64-mingw32
Configured with: ../configure --prefix=/R/winlibs64ucrt_stage/inst_gcc-13.2.0/share/gcc --build=x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --enable-offload-targets=nvptx-none --with-pkgversion='MinGW-W64 x86_64-ucrt-posix-seh, built by Brecht Sanders'
--with-tune=generic --enable-checking=release --enable-threads=posix --disable-sjlj-exceptions --disable-libunwind-exceptions --disable-serial-configure --disable-bootstrap --enable-host-shared --enable-plugin --disable-default-ssp --disable-rpath --disable-libstdcxx-debug --disable-version-specific-runtime-libs
--with-stabs --disable-symvers --enable-languages=c,c++,fortran,lto,objc,obj-c++ --disable-gold --disable-nls --disable-stage1-checking --disable-win32-registry --disable-multilib --enable-ld --enable-libquadmath --enable-libada --enable-libssp --enable-libstdcxx --enable-lto --enable-fully-dynamic-string --enable-libgomp
--enable-graphite --enable-mingw-wildcard --enable-libstdcxx-time --enable-libstdcxx-pch --with-mpc=/d/Prog/winlibs64ucrt_stage/custombuilt --with-mpfr=/d/Prog/winlibs64ucrt_stage/custombuilt --with-gmp=/d/Prog/winlibs64ucrt_stage/custombuilt --with-isl=/d/Prog/winlibs64ucrt_stage/custombuilt
--disable-libstdcxx-backtrace --enable-install-libiberty --enable-__cxa_atexit --without-included-gettext --with-diagnostics-color=auto --enable-clocale=generic --with-libiconv --with-system-zlib
--with-build-sysroot=/R/winlibs64ucrt_stage/gcc-13.2.0/build_mingw/mingw-w64 CFLAGS='-I/d/Prog/winlibs64ucrt_stage/custombuilt/include/libdl-win32 -Wno-int-conversion -march=nocona -msahf -mtune=generic -O2' CXXFLAGS='-Wno-int-conversion -march=nocona -msahf -mtune=generic -O2' LDFLAGS='-pthread -Wl,--no-insert-timestamp -Wl,--dynamicbase -Wl,--high-entropy-va -Wl,--nxcompat -Wl,--tsaware'
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 13.2.0 (MinGW-W64 x86_64-ucrt-posix-seh, built by Brecht Sanders)