在我读了几个论坛帖子后,我的问题根本没有帮助,我向你寻求帮助。我试图在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)
型
1条答案
按热度按时间5hcedyr01#
-l:mylib.a
在库搜索路径中搜索名为mylib.a
的文件。默认情况下,当前工作目录不在库搜索路径中。您可以将其添加到那里:字符串
或者直接使用文件名,不带
-l
标志:型
如果你正在创建一个DLL,你 * 可能 * 需要另外几个标志:
型
g++ -static -o mylib.a ...
不起作用。使用ar
创建静态库。