Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/139.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 链接到预编译库时链接器错误_C++_Linker Errors_Clang++_Ln_Rendering Engine - Fatal编程技术网

C++ 链接到预编译库时链接器错误

C++ 链接到预编译库时链接器错误,c++,linker-errors,clang++,ln,rendering-engine,C++,Linker Errors,Clang++,Ln,Rendering Engine,我正在尝试以一种非常基本的方式(不使用任何Makefile或CMakeLists.txt)使用以下clang++命令链接到许多库: FILAMENT_LIBS="-lassimp -lbackend -lbluegl -lbluevk -lcamutils -lfilabridge -lfilaflat -lfilagui -lfilamat -lfilamat_combined -lfilamat_lite -lfilament -lfilameshio -lgeometry -lgltfio

我正在尝试以一种非常基本的方式(不使用任何Makefile或CMakeLists.txt)使用以下clang++命令链接到许多库:

FILAMENT_LIBS="-lassimp -lbackend -lbluegl -lbluevk -lcamutils -lfilabridge -lfilaflat -lfilagui -lfilamat -lfilamat_combined -lfilamat_lite -lfilament -lfilameshio -lgeometry -lgltfio -lgltfio_core -lgltfio_pipeline -lgltfio_resources -libl -limage -limageio -limgui -lmatdbg -lmatdbg_resources -lmath -lmeshoptimizer -lrays -lshaders -lsmol-v -lutils"
clang++-7 -L../lib/x86_64/ ${FILAMENT_LIBS} -lpthread -lc++ -ldl -lSDL2 -I./ -I../include/ -I../app/ -I${RESOURCE_DIR} -Wno-extern-c-compat -std=c++14 -pthread ../suzanne.cpp ../app/Cube.cpp ../app/FilamentApp.cpp ../app/IBL.cpp ../app/IcoSphere.cpp ../app/Image.cpp ../app/NativeWindowHelperLinux.cpp ../app/Sphere.cpp -o suzanne
但是,这会导致错误
app.cpp:(.text+0x4d2):未定义对
的引用。。。然后是对上述库中的函数的每一个调用都必须执行的操作

为了提供一些上下文,我正在尝试编译渲染引擎提供的一个示例应用程序。当使用源代码编译时,一切正常,但是当我尝试链接库的预编译版本时,我得到了上面的错误

此外,当我尝试使用tester main.cpp文件和附带的Makefile(如中所述)链接相同的库时,所有内容都链接并编译得非常好

我有一种感觉,我在这里做了一些明显的错误,特别是我正在使用的叮当声命令,但我不能为我的生活看到它是什么。任何帮助都将不胜感激

编辑-前几行错误:

../lib/x86_64//libfilament.a(Engine.cpp.o): In function `filament::details::FEngine::loop()':
Engine.cpp:(.text._ZN8filament7details7FEngine4loopEv+0x22): undefined reference to `filament::backend::DefaultPlatform::create(filament::backend::Backend*)'
../lib/x86_64//libfilament.a(Engine.cpp.o): In function `filament::details::FEngine::init()':
Engine.cpp:(.text._ZN8filament7details7FEngine4initEv+0x1f): undefined reference to `filament::backend::CommandStream::CommandStream(filament::backend::Driver&, filament::backend::CircularBuffer&)'
../lib/x86_64//libfilament.a(Engine.cpp.o): In function `filament::details::FEngine::FEngine(filament::backend::Backend, filament::backend::Platform*, void*)':
Engine.cpp:(.text._ZN8filament7details7FEngineC2ENS_7backend7BackendEPNS2_8PlatformEPv+0x267): undefined reference to `filament::backend::CommandBufferQueue::CommandBufferQueue(unsigned long, unsigned long)'
Engine.cpp:(.text._ZN8filament7details7FEngineC2ENS_7backend7BackendEPNS2_8PlatformEPv+0x332): undefined reference to `filaflat::ShaderBuilder::ShaderBuilder()'
Engine.cpp:(.text._ZN8filament7details7FEngineC2ENS_7backend7BackendEPNS2_8PlatformEPv+0x342): undefined reference to `filaflat::ShaderBuilder::ShaderBuilder()'
Engine.cpp:(.text._ZN8filament7details7FEngineC2ENS_7backend7BackendEPNS2_8PlatformEPv+0x462): undefined reference to `filaflat::ShaderBuilder::~ShaderBuilder()'
Engine.cpp:(.text._ZN8filament7details7FEngineC2ENS_7backend7BackendEPNS2_8PlatformEPv+0x471): undefined reference to `filaflat::ShaderBuilder::~ShaderBuilder()'
Engine.cpp:(.text._ZN8filament7details7FEngineC2ENS_7backend7BackendEPNS2_8PlatformEPv+0x4a2): undefined reference to `filament::backend::CommandBufferQueue::~CommandBufferQueue()'
../lib/x86_64//libfilament.a(Engine.cpp.o): In function `filament::details::FEngine::~FEngine()':
Engine.cpp:(.text._ZN8filament7details7FEngineD2Ev+0x3e): undefined reference to `filament::backend::DefaultPlatform::destroy(filament::backend::DefaultPlatform**)'
Engine.cpp:(.text._ZN8filament7details7FEngineD2Ev+0x10c): undefined reference to `filaflat::ShaderBuilder::~ShaderBuilder()'
Engine.cpp:(.text._ZN8filament7details7FEngineD2Ev+0x118): undefined reference to `filaflat::ShaderBuilder::~ShaderBuilder()'
Engine.cpp:(.text._ZN8filament7details7FEngineD2Ev+0x148): undefined reference to `filament::backend::CommandBufferQueue::~CommandBufferQueue()'
../lib/x86_64//libfilament.a(Engine.cpp.o): In function `filament::details::FEngine::shutdown()':
Engine.cpp:(.text._ZN8filament7details7FEngine8shutdownEv+0x207): undefined reference to `filament::backend::CommandBufferQueue::flush()'
Engine.cpp:(.text._ZN8filament7details7FEngine8shutdownEv+0x20f): undefined reference to `filament::backend::CommandBufferQueue::requestExit()'
../lib/x86_64//libfilament.a(Engine.cpp.o): In function `filament::details::FEngine::flushCommandBuffer(filament::backend::CommandBufferQueue&)':
Engine.cpp:(.text._ZN8filament7details7FEngine18flushCommandBufferERNS_7backend18CommandBufferQueueE+0x12): undefined reference to `filament::backend::CommandBufferQueue::flush()'
../lib/x86_64//libfilament.a(Engine.cpp.o): In function `filament::details::FEngine::flush()':
Engine.cpp:(.text._ZN8filament7details7FEngine5flushEv+0x19): undefined reference to `filament::backend::CommandBufferQueue::flush()'
../lib/x86_64//libfilament.a(Engine.cpp.o): In function `filament::details::FEngine::execute()':
Engine.cpp:(.text._ZN8filament7details7FEngine7executeEv+0x1b): undefined reference to `filament::backend::CommandBufferQueue::waitForCommands() const'
Engine.cpp:(.text._ZN8filament7details7FEngine7executeEv+0x4c): undefined reference to `filament::backend::CommandStream::execute(void*)'
Engine.cpp:(.text._ZN8filament7details7FEngine7executeEv+0x57): undefined reference to `filament::backend::CommandBufferQueue::releaseBuffer(filament::backend::CommandBufferQueue::Slice const&)'
/tmp/suzanne-ef5171.o: In function `main::$_0::operator()(filament::Engine*, filament::View*, filament::Scene*) const':
suzanne.cpp:(.text+0x1dc0): undefined reference to `TEXTURES_ALBEDO_S3TC_OFFSET'
suzanne.cpp:(.text+0x1dc7): undefined reference to `TEXTURES_PACKAGE'
suzanne.cpp:(.text+0x1dce): undefined reference to `TEXTURES_ALBEDO_S3TC_SIZE'
suzanne.cpp:(.text+0x1e10): undefined reference to `TEXTURES_AO_OFFSET'
suzanne.cpp:(.text+0x1e17): undefined reference to `TEXTURES_PACKAGE'
suzanne.cpp:(.text+0x1e1d): undefined reference to `TEXTURES_AO_SIZE'
suzanne.cpp:(.text+0x1e5e): undefined reference to `TEXTURES_METALLIC_OFFSET'
suzanne.cpp:(.text+0x1e65): undefined reference to `TEXTURES_PACKAGE'
suzanne.cpp:(.text+0x1e6b): undefined reference to `TEXTURES_METALLIC_SIZE'
suzanne.cpp:(.text+0x1eac): undefined reference to `TEXTURES_ROUGHNESS_OFFSET'
suzanne.cpp:(.text+0x1eb3): undefined reference to `TEXTURES_PACKAGE'
suzanne.cpp:(.text+0x1eb9): undefined reference to `TEXTURES_ROUGHNESS_SIZE'
suzanne.cpp:(.text+0x1f85): undefined reference to `TEXTURES_NORMAL_OFFSET'
suzanne.cpp:(.text+0x1f8c): undefined reference to `TEXTURES_PACKAGE'
suzanne.cpp:(.text+0x1f93): undefined reference to `TEXTURES_NORMAL_SIZE'
suzanne.cpp:(.text+0x1fdb): undefined reference to `RESOURCES_TEXTUREDLIT_OFFSET'
suzanne.cpp:(.text+0x1fe2): undefined reference to `RESOURCES_PACKAGE'
suzanne.cpp:(.text+0x1fe9): undefined reference to `RESOURCES_TEXTUREDLIT_SIZE'
suzanne.cpp:(.text+0x21ea): undefined reference to `RESOURCES_SUZANNE_OFFSET'
suzanne.cpp:(.text+0x21f0): undefined reference to `RESOURCES_PACKAGE'
/tmp/FilamentApp-94694a.o: In function `FilamentApp::run(Config const&, std::__1::function<void (filament::Engine*, filament::View*, filament::Scene*)>, std::__1::function<void (filament::Engine*, filament::View*, filament::Scene*)>, std::__1::function<void (filament::Engine*, filament::View*)>, std::__1::function<void (filament::Engine*, filament::View*, filament::Scene*, filament::Renderer*)>, std::__1::function<void (filament::Engine*, filament::View*, filament::Scene*, filament::Renderer*)>, unsigned long, unsigned long)':
FilamentApp.cpp:(.text+0xd8e): undefined reference to `RESOURCES_DEPTHVISUALIZER_OFFSET'
FilamentApp.cpp:(.text+0xd95): undefined reference to `RESOURCES_PACKAGE'
FilamentApp.cpp:(.text+0xd9c): undefined reference to `RESOURCES_DEPTHVISUALIZER_SIZE'
FilamentApp.cpp:(.text+0xe2c): undefined reference to `RESOURCES_AIDEFAULTMAT_OFFSET'
FilamentApp.cpp:(.text+0xe33): undefined reference to `RESOURCES_PACKAGE'
FilamentApp.cpp:(.text+0xe3a): undefined reference to `RESOURCES_AIDEFAULTMAT_SIZE'
FilamentApp.cpp:(.text+0xeaf): undefined reference to `RESOURCES_TRANSPARENTCOLOR_OFFSET'
FilamentApp.cpp:(.text+0xeb6): undefined reference to `RESOURCES_PACKAGE'
FilamentApp.cpp:(.text+0xebd): undefined reference to `RESOURCES_TRANSPARENTCOLOR_SIZE'
/tmp/FilamentApp-94694a.o: In function `FilamentApp::Window::configureCamerasForWindow()':
FilamentApp.cpp:(.text+0x6902): undefined reference to `filament::Camera::setLensProjection(double, double, double, double)'
FilamentApp.cpp:(.text+0x6a34): undefined reference to `filament::Camera::lookAt(filament::math::details::TVec3<float> const&, filament::math::details::TVec3<float> const&)'
../lib/x86_64//libfilament.a(VertexBuffer.cpp.o): In function `filament::VertexBuffer::Builder::attribute(filament::VertexAttribute, unsigned char, filament::backend::ElementType, unsigned int, unsigned char)':
/tmp/suzanne-e10eca.o: In function `main::$_0::operator()(filament::Engine*, filament::View*, filament::Scene*) const':
suzanne.cpp:(.text+0x1dc0): undefined reference to `TEXTURES_ALBEDO_S3TC_OFFSET'
suzanne.cpp:(.text+0x1dc7): undefined reference to `TEXTURES_PACKAGE'
suzanne.cpp:(.text+0x1dce): undefined reference to `TEXTURES_ALBEDO_S3TC_SIZE'
suzanne.cpp:(.text+0x1e10): undefined reference to `TEXTURES_AO_OFFSET'
suzanne.cpp:(.text+0x1e17): undefined reference to `TEXTURES_PACKAGE'
suzanne.cpp:(.text+0x1e1d): undefined reference to `TEXTURES_AO_SIZE'
suzanne.cpp:(.text+0x1e5e): undefined reference to `TEXTURES_METALLIC_OFFSET'
suzanne.cpp:(.text+0x1e65): undefined reference to `TEXTURES_PACKAGE'
suzanne.cpp:(.text+0x1e6b): undefined reference to `TEXTURES_METALLIC_SIZE'
suzanne.cpp:(.text+0x1eac): undefined reference to `TEXTURES_ROUGHNESS_OFFSET'
suzanne.cpp:(.text+0x1eb3): undefined reference to `TEXTURES_PACKAGE'
suzanne.cpp:(.text+0x1eb9): undefined reference to `TEXTURES_ROUGHNESS_SIZE'
suzanne.cpp:(.text+0x1f85): undefined reference to `TEXTURES_NORMAL_OFFSET'
suzanne.cpp:(.text+0x1f8c): undefined reference to `TEXTURES_PACKAGE'
suzanne.cpp:(.text+0x1f93): undefined reference to `TEXTURES_NORMAL_SIZE'
suzanne.cpp:(.text+0x1fdb): undefined reference to `RESOURCES_TEXTUREDLIT_OFFSET'
suzanne.cpp:(.text+0x1fe2): undefined reference to `RESOURCES_PACKAGE'
suzanne.cpp:(.text+0x1fe9): undefined reference to `RESOURCES_TEXTUREDLIT_SIZE'
suzanne.cpp:(.text+0x21ea): undefined reference to `RESOURCES_SUZANNE_OFFSET'
suzanne.cpp:(.text+0x21f0): undefined reference to `RESOURCES_PACKAGE'
/tmp/FilamentApp-0b5ad4.o: In function `FilamentApp::run(Config const&, std::__1::function<void (filament::Engine*, filament::View*, filament::Scene*)>, std::__1::function<void (filament::Engine*, filament::View*, filament::Scene*)>, std::__1::function<void (filament::Engine*, filament::View*)>, std::__1::function<void (filament::Engine*, filament::View*, filament::Scene*, filament::Renderer*)>, std::__1::function<void (filament::Engine*, filament::View*, filament::Scene*, filament::Renderer*)>, unsigned long, unsigned long)':
FilamentApp.cpp:(.text+0xd8e): undefined reference to `RESOURCES_DEPTHVISUALIZER_OFFSET'
FilamentApp.cpp:(.text+0xd95): undefined reference to `RESOURCES_PACKAGE'
FilamentApp.cpp:(.text+0xd9c): undefined reference to `RESOURCES_DEPTHVISUALIZER_SIZE'
FilamentApp.cpp:(.text+0xe2c): undefined reference to `RESOURCES_AIDEFAULTMAT_OFFSET'
FilamentApp.cpp:(.text+0xe33): undefined reference to `RESOURCES_PACKAGE'
FilamentApp.cpp:(.text+0xe3a): undefined reference to `RESOURCES_AIDEFAULTMAT_SIZE'
FilamentApp.cpp:(.text+0xeaf): undefined reference to `RESOURCES_TRANSPARENTCOLOR_OFFSET'
FilamentApp.cpp:(.text+0xeb6): undefined reference to `RESOURCES_PACKAGE'
FilamentApp.cpp:(.text+0xebd): undefined reference to `RESOURCES_TRANSPARENTCOLOR_SIZE'
/tmp/FilamentApp-0b5ad4.o: In function `FilamentApp::Window::configureCamerasForWindow()':
FilamentApp.cpp:(.text+0x6902): undefined reference to `filament::Camera::setLensProjection(double, double, double, double)'
FilamentApp.cpp:(.text+0x6a34): undefined reference to `filament::Camera::lookAt(filament::math::details::TVec3<float> const&, filament::math::details::TVec3<float> const&)'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
我已经在clang命令中包含了
-I./
,那么clang肯定能够看到这些文件吗

这是
纹理。h

#ifndef TEXTURES_H_
#define TEXTURES_H_

#include <stdint.h>

extern "C" {
    extern const uint8_t TEXTURES_PACKAGE[];
    extern int TEXTURES_ALBEDO_S3TC_OFFSET;
    extern int TEXTURES_ALBEDO_S3TC_SIZE;
    extern int TEXTURES_ROUGHNESS_OFFSET;
    extern int TEXTURES_ROUGHNESS_SIZE;
    extern int TEXTURES_METALLIC_OFFSET;
    extern int TEXTURES_METALLIC_SIZE;
    extern int TEXTURES_AO_OFFSET;
    extern int TEXTURES_AO_SIZE;
    extern int TEXTURES_NORMAL_OFFSET;
    extern int TEXTURES_NORMAL_SIZE;
}
#define TEXTURES_ALBEDO_S3TC_DATA (TEXTURES_PACKAGE + TEXTURES_ALBEDO_S3TC_OFFSET)
#define TEXTURES_ROUGHNESS_DATA (TEXTURES_PACKAGE + TEXTURES_ROUGHNESS_OFFSET)
#define TEXTURES_METALLIC_DATA (TEXTURES_PACKAGE + TEXTURES_METALLIC_OFFSET)
#define TEXTURES_AO_DATA (TEXTURES_PACKAGE + TEXTURES_AO_OFFSET)
#define TEXTURES_NORMAL_DATA (TEXTURES_PACKAGE + TEXTURES_NORMAL_OFFSET)

#endif

编译时将所有库放在最后一行:

clang++-7 -stdlib=libc++ -L../lib/x86_64/ -I./ -I../include/ -I../app/ -I${RESOURCE_DIR} -Wno-extern-c-compat -std=c++14 ../suzanne.cpp ../app/Cube.cpp ../app/FilamentApp.cpp ../app/IBL.cpp ../app/IcoSphere.cpp ../app/Image.cpp ../app/NativeWindowHelperLinux.cpp ../app/Sphere.cpp -o suzanne ${FILAMENT_LIBS} -lSDL2 -ldl -pthread
另外,仅使用
-pthread
(删除
-lphread
)。两者都不需要

您可能还需要删除
-lc++
,并将其替换为
-stdlib=libc++
(不需要在行尾)

链接程序时发生的情况是,当链接器遇到以前从未遇到过的符号(函数)时,它会将其放在未解析符号列表中。对于此后检查的每个库,将检查未解析的符号。如果遇到已检查的库中存在的符号,链接将失败

灯丝库的顺序也很重要,因此请尝试:

FILAMENT_LIBS=-lfilament -lbackend -lbluegl -lbluevk -lfilabridge -lfilaflat -lutils -lgeometry -lsmol-v -libl
如文件中所述。请注意,我已从
灯丝库
中删除了非灯丝库。将这些库放在单独的变量中,并在编译时将其放在
LIBS
变量之前

如果
SDL2
使用
灯丝
,则应将
-lSDL2
放在灯丝库之前,否则,将其保留在原来的位置

如果仍然失败,作为最后一种手段,您可以将灯丝库包装在库组中,使其解决内部灯丝相关性:

-Wl,--start-group $(FILAMENT_LIBS) -Wl,--end-group
然而,这不是你想要的,因为它很慢,但是,它是一种选择


更绝望的选择是将所有库包装在
-Wl,--start组中
-Wl,--end group
配对以验证它是否编译,以及您是否拥有所需的所有库和目标文件。

非常感谢您的回答!将命令更改为您给出的命令将引发的“未定义引用”错误数量减半,但仍有大约200个错误仍在发生。还有其他明显的原因吗?@JoelMcAllister不客气。将前10-20行错误复制到问题中,我会看看是否能解决。@JoelMcAllister更新。太好了,错误数量现在已经减少到35行了!使用
clang++-7[…]-o suzanne-Wl、-start-group${dependencies}${filame\u LIBS}-Wl、-end-group-lSDL2[…]
对灯丝依赖项进行分组会得到相同的结果。将我的
libfilame.a
文件替换为调试生成类型上的文件会产生有关
对DebugServer的未定义引用的错误,因此,我将尝试使用版本构建类型从源代码处编译。
clang++-7 -stdlib=libc++ -L../lib/x86_64/ -I./ -I../include/ -I../app/ -I${RESOURCE_DIR} -Wno-extern-c-compat -std=c++14 ../suzanne.cpp ../app/Cube.cpp ../app/FilamentApp.cpp ../app/IBL.cpp ../app/IcoSphere.cpp ../app/Image.cpp ../app/NativeWindowHelperLinux.cpp ../app/Sphere.cpp -o suzanne ${FILAMENT_LIBS} -lSDL2 -ldl -pthread
FILAMENT_LIBS=-lfilament -lbackend -lbluegl -lbluevk -lfilabridge -lfilaflat -lutils -lgeometry -lsmol-v -libl
-Wl,--start-group $(FILAMENT_LIBS) -Wl,--end-group