gpt4 book ai didi

c++ - 对 std::bad_cast::bad_cast() 的 undefined reference

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:23:43 24 4
gpt4 key购买 nike

我在 Linux 上使用带有 clang++ 的 cmake。我遇到了一些链接器问题:

Linking CXX executable "/run/media/toi/Storage E/Dropbox/Programmering/Flictus/bin/main"
CMakeFiles/main.dir/GraphicsEngine/Shader.cpp.o:/run/media/toi/Storage E/Dropbox/Programmering/Flictus/src/GraphicsEngine/Shader.cpp:function std::__1::basic_filebuf<char, std::__1::char_traits<char> >::seekoff(long long, std::__1::ios_base::seekdir, unsigned int): error: undefined reference to 'std::bad_cast::bad_cast()'
CMakeFiles/main.dir/GraphicsEngine/Shader.cpp.o:/run/media/toi/Storage E/Dropbox/Programmering/Flictus/src/GraphicsEngine/Shader.cpp:function std::__1::basic_filebuf<char, std::__1::char_traits<char> >::sync(): error: undefined reference to 'std::bad_cast::bad_cast()'
CMakeFiles/main.dir/GraphicsEngine/Shader.cpp.o:/run/media/toi/Storage E/Dropbox/Programmering/Flictus/src/GraphicsEngine/Shader.cpp:function std::__1::basic_filebuf<char, std::__1::char_traits<char> >::underflow(): error: undefined reference to 'std::bad_cast::bad_cast()'
CMakeFiles/main.dir/GraphicsEngine/Shader.cpp.o:/run/media/toi/Storage E/Dropbox/Programmering/Flictus/src/GraphicsEngine/Shader.cpp:function std::__1::basic_filebuf<char, std::__1::char_traits<char> >::overflow(int): error: undefined reference to 'std::bad_cast::bad_cast()'

我假设这确实是一个链接器问题,因为它发生在链接开始并且包含相关 header 之后。

我没有在 std::cout 等上得到 undefined reference 。

生成链接器错误的代码:

std::ifstream file(shaderFile, std::ios::in | std::ios::binary);
if (file) {
file.seekg(0, std::ios::end);
shaderString.resize(file.tellg());
file.seekg(0, std::ios::beg);
file.read(&shaderString[0], shaderString.size());
file.close();
}

在添加上述代码之前,项目运行良好。它在 Visual Studio 2013 中运行没有问题。

cmake 文件的相关部分:

add_compile_options(-stdlib=libc++)
add_compile_options(-std=c++1y)
set(CMAKE_LINKER /usr/bin/clang++) # didn't help when added
set(CMAKE_EXE_LINKER_FLAGS "-lc++ -Wall -fexceptions")
set(CMAKE_CXX_COMPILER /usr/bin/clang++)
set(CMAKE_C_COMPILER /usr/bin/clang)

那么还有什么我应该链接的吗,或者它是 clang++ 的限制吗?

编辑:链接器调用:

"/usr/bin/ld.gold" -export-dynamic --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o 
/run/media/toi/Storage E/Dropbox/Programmering/Flictus/bin/main /usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.8.2/../../../../lib64/crt1.o /usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.8.2/../../../../lib64/crti.o
/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.8.2/crtbegin.o -L/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.8.2 -L/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.8.2/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.8.2/../../.. -L/lib
-L/usr/lib CMakeFiles/main.dir/main.cpp.o CMakeFiles/main.dir/GraphicsEngine/GraphicsEngine.cpp.o CMakeFiles/main.dir/GraphicsEngine/Shader.cpp.o
CMakeFiles/main.dir/GraphicsEngine/TextureLoader.cpp.o CMakeFiles/main.dir/Input/Gamepad.cpp.o CMakeFiles/main.dir/Input/Input.cpp.o CMakeFiles/main.dir/GUI/Font.cpp.o CMakeFiles/main.dir/GUI/GUIEngine.cpp.o
CMakeFiles/main.dir/GUI/GUIRect.cpp.o CMakeFiles/main.dir/GUI/GUISprite.cpp.o CMakeFiles/main.dir/GUI/Objects/Components/GUIText.cpp.o CMakeFiles/main.dir/GUI/Objects/GUIButton.cpp.o
CMakeFiles/main.dir/GUI/Objects/GUIImage.cpp.o CMakeFiles/main.dir/GUI/Objects/GUILabel.cpp.o CMakeFiles/main.dir/GUI/Objects/GUIListBox.cpp.o
CMakeFiles/main.dir/GUI/Objects/GUIObject.cpp.o -lSDL2 -lpthread -lGLEW -lGL -lSOIL -lc++ -lfreetype -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.8.2/crtend.o /usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.8.2/../../../../lib64/crtn.o

最佳答案

这是通过链接 libc++abi 解决的。

关于c++ - 对 std::bad_cast::bad_cast() 的 undefined reference ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22263732/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com