admin管理员组

文章数量:1122832

I have a Vulkan Engine I'm working on. I plan to eventually make a game with it, so I've a graphics engine part compile into a .so file from object files and then I link the final application with the graphics engine library. I'm using a makefile that I recently ported from Windows to Linux (Nobara, a fork of Fedora). The failed command is

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

If i run it with -v I get this:

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= --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

I don't know what any of this means.

I've tried replacing the -Lbin with -L/home/documents/vulkan_engine_main/bin and -L./bin. This still returns the same error.

The full sequence of commands is this:

g++ -O0 -Wall -std=c++20 -c app/src/main.cpp -Iapp/header -IgraphicsEngine/header -oapp/obj/main.o
g++ -O0 -Wall -std=c++20 -c -fPIC graphicsEngine/src/graphics_engine.cpp -IgraphicsEngine/header -ographicsEngine/obj/graphics_engine.o
g++ graphicsEngine/obj/graphics_engine.o -obin/GraphicsEngine.so -shared -lglfw -lvulkan
g++  app/obj/main.o -obin/NuclearLaunchActivator.bin -Lbin -lGraphicsEngine
/usr/bin/ld: cannot find -lGraphicsEngine: No such file or directory collect2: error: ld returned 1 exit status
make: *** [Makefile:63: bin/NuclearLaunchActivator.bin] Error 1

I have a Vulkan Engine I'm working on. I plan to eventually make a game with it, so I've a graphics engine part compile into a .so file from object files and then I link the final application with the graphics engine library. I'm using a makefile that I recently ported from Windows to Linux (Nobara, a fork of Fedora). The failed command is

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

If i run it with -v I get this:

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

I don't know what any of this means.

I've tried replacing the -Lbin with -L/home/documents/vulkan_engine_main/bin and -L./bin. This still returns the same error.

The full sequence of commands is this:

g++ -O0 -Wall -std=c++20 -c app/src/main.cpp -Iapp/header -IgraphicsEngine/header -oapp/obj/main.o
g++ -O0 -Wall -std=c++20 -c -fPIC graphicsEngine/src/graphics_engine.cpp -IgraphicsEngine/header -ographicsEngine/obj/graphics_engine.o
g++ graphicsEngine/obj/graphics_engine.o -obin/GraphicsEngine.so -shared -lglfw -lvulkan
g++  app/obj/main.o -obin/NuclearLaunchActivator.bin -Lbin -lGraphicsEngine
/usr/bin/ld: cannot find -lGraphicsEngine: No such file or directory collect2: error: ld returned 1 exit status
make: *** [Makefile:63: bin/NuclearLaunchActivator.bin] Error 1
Share Improve this question edited Nov 22, 2024 at 6:15 3CxEZiVlQ 37.7k10 gold badges70 silver badges88 bronze badges asked Nov 22, 2024 at 1:51 BizzarraKBizzarraK 34 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 2

When you write:

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

You are asking g++ to combine app/obj/main.o with a library named:

  • libGraphicsEngine.so.so (a shared library) or
  • libGraphicsEngine.so.a (a static library)

and produce bin/NuclearLaunchActivator.bin. You are further giving it permission to rummage in the directory ./bin to find that library file.

The library you are looking for is nearly certainly named libGraphicsEngine.so (only one .so), though it might be libGraphicEngine.a. In some very complex cases, you might have both of these lying about, but that is beyond the scope I am choosing to explain.

Either way, you need to switch the -l to -lGraphicsEngine, and then make sure the -L points to a directory that contains it.

In other words, -l means "take the string, and add lib on the front, and then look for .so or .a files in the directories called out by all the -L arguments.

It would probably also be a good idea to put a space after -o.

-lGraphicsEngine looks for either of files libGraphicsEngine.so or libGraphicsEngine.a but the previous command outputs into bin/GraphicsEngine.so.

You can apply any of two solutions:

  1. Change the output -obin/libGraphicsEngine.so.
  2. Or change the input to the file path, replace -Lbin -lGraphicsEngine with bin/libGraphicsEngine.so.

本文标签: cLinux can39t find my directories when linkingStack Overflow