Linux 在链接时找不到我的目录

问题描述 投票:0回答:1

我正在开发一个 Vulkan 引擎。我计划最终用它制作一个游戏,因此我将图形引擎部分从对象文件编译成 .so 文件,然后将最终应用程序与图形引擎库链接。我正在使用最近从 Windows 移植到 Linux 的 makefile(Nobara,Fedora 的一个分支)。失败的命令是

g++  app/obj/main.o -obin/NuclearLaunchActivator.bin -Lbin -lGraphicsEngine.so
/usr/bin/ld: cannot find -lGraphicsEngine.so: No such file or directory
collect2: error: ld returned 1 exit status
make: *** [Makefile:63: bin/NuclearLaunchActivator.bin] Error 1

如果我用 -v 运行它,我会得到这个:

g++  app/obj/main.o -obin/NuclearLaunchActivator.bin -L/home/user/documents/vulkan-engine-main/bin -lGraphicsEngine.so  -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/14/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,objc,obj-c++,ada,go,d,m2,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --enable-libstdcxx-backtrace --with-libstdcxx-zoneinfo=/usr/share/zoneinfo --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl=/builddir/build/BUILD/gcc-14.2.1-20240912/obj-x86_64-redhat-linux/isl-install --enable-offload-targets=nvptx-none,amdgcn-amdhsa --enable-offload-defaulted --without-cuda-driver --enable-gnu-indirect-function --enable-cet --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux --with-build-config=bootstrap-lto --enable-link-serialization=1
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 14.2.1 20240912 (Red Hat 14.2.1-3) (GCC) 
COMPILER_PATH=/usr/libexec/gcc/x86_64-redhat-linux/14/:/usr/libexec/gcc/x86_64-redhat-linux/14/:/usr/libexec/gcc/x86_64-redhat-linux/:/usr/lib/gcc/x86_64-redhat-linux/14/:/usr/lib/gcc/x86_64-redhat-linux/
LIBRARY_PATH=/usr/lib/gcc/x86_64-redhat-linux/14/:/usr/lib/gcc/x86_64-redhat-linux/14/../../../../lib64/:/lib/../lib64/:/usr/lib/../lib64/:/usr/lib/gcc/x86_64-redhat-linux/14/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-o' 'bin/NuclearLaunchActivator.bin' '-L/home/user/documents/vulkan-engine-main/bin' '-v' '-foffload-options=-l_GCC_m' '-shared-libgcc' '-mtune=generic' '-march=x86-64' '-dumpdir' 'bin/NuclearLaunchActivator.bin.'
 /usr/libexec/gcc/x86_64-redhat-linux/14/collect2 -plugin /usr/libexec/gcc/x86_64-redhat-linux/14/liblto_plugin.so -plugin-opt=/usr/libexec/gcc/x86_64-redhat-linux/14/lto-wrapper -plugin-opt=-fresolution=/tmp/ccsn7e7s.res -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc --build-id --no-add-needed --eh-frame-hdr --hash-style=gnu -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o bin/NuclearLaunchActivator.bin /usr/lib/gcc/x86_64-redhat-linux/14/../../../../lib64/crt1.o /usr/lib/gcc/x86_64-redhat-linux/14/../../../../lib64/crti.o /usr/lib/gcc/x86_64-redhat-linux/14/crtbegin.o -L/home/user/documents/vulkan-engine-main/bin -L/usr/lib/gcc/x86_64-redhat-linux/14 -L/usr/lib/gcc/x86_64-redhat-linux/14/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib/gcc/x86_64-redhat-linux/14/../../.. app/obj/main.o -lGraphicsEngine.so -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/lib/gcc/x86_64-redhat-linux/14/crtend.o /usr/lib/gcc/x86_64-redhat-linux/14/../../../../lib64/crtn.o
/usr/bin/ld: cannot find -lGraphicsEngine.so: No such file or directory
collect2: error: ld returned 1 exit status
make: *** [Makefile:63: bin/NuclearLaunchActivator.bin] Error 1

我不知道这意味着什么。

我尝试用

-Lbin
-L/home/documents/vulkan_engine_main/bin
替换
-L./bin
。这仍然返回相同的错误。

c++ linker vulkan
1个回答
0
投票

当你写下:

g++  app/obj/main.o -obin/NuclearLaunchActivator.bin -Lbin -lGraphicsEngine.so

您要求 g++ 将 app/obj/main.o 与名为:

的库结合起来
  • libGraphicsEngine.so.so
  • libGraphicsEngine.so.a

并产生

bin/NuclearLaunchActivator.bin
。您进一步授予它在目录
./bin
中翻找该 .so 文件的权限。

您正在寻找的库几乎肯定被命名为

libGraphicsEngine.so
(只有一个 .so),尽管它可能是
libGraphicEngine.a

无论哪种方式,您都需要将 -l 切换为

-lGraphicsEngine
,然后确保 -L 指向包含它的目录。

-o
之后加一个空格可能也是个好主意。

© www.soinside.com 2019 - 2024. All rights reserved.