gpt4 book ai didi

c++ - Macports GCC 4.8 无法链接 OSX Lion 上的 c++ 库

转载 作者:太空宇宙 更新时间:2023-11-04 12:05:23 25 4
gpt4 key购买 nike

我在 OSX Lion 上链接一个非常简单的 c++ 程序时遇到问题。错误信息是

Undefined symbols for architecture x86_64: "std::basic_string<char, std::char_traits<char>

这是编译器的完整详细输出:

Nicholass-MacBook-Pro:hello_vbo-build jubei$ make VERBOSE=1
"/Applications/CMake 2.8-9.app/Contents/bin/cmake" -H/Users/jubei/coding/hello_vbo - B/Users/jubei/coding/hello_vbo-build --check-build-system CMakeFiles/Makefile.cmake 0
"/Applications/CMake 2.8-9.app/Contents/bin/cmake" -E cmake_progress_start /Users/jubei/coding/hello_vbo-build/CMakeFiles /Users/jubei/coding/hello_vbo-build/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make -f CMakeFiles/hellovbo.dir/build.make CMakeFiles/hellovbo.dir/depend
cd /Users/jubei/coding/hello_vbo-build && "/Applications/CMake 2.8-9.app/Contents/bin/cmake" -E cmake_depends "Unix Makefiles" /Users/jubei/coding/hello_vbo /Users/jubei/coding/hello_vbo /Users/jubei/coding/hello_vbo-build /Users/jubei/coding/hello_vbo-build /Users/jubei/coding/hello_vbo-build/CMakeFiles/hellovbo.dir/DependInfo.cmake --color=
make -f CMakeFiles/hellovbo.dir/build.make CMakeFiles/hellovbo.dir/build
"/Applications/CMake 2.8-9.app/Contents/bin/cmake" -E cmake_progress_report/Users/jubei/coding/hello_vbo-build/CMakeFiles 1
[100%] Building CXX object CMakeFiles/hellovbo.dir/main.cpp.o
/opt/local/bin/g++-mp-4.8 --std=c++11 -I/usr/local/include -I/Users/jubei/coding/hello_vbo/include -o CMakeFiles/hellovbo.dir/main.cpp.o -c /Users/jubei/coding/hello_vbo/main.cpp
Linking CXX executable hellovbo
"/Applications/CMake 2.8-9.app/Contents/bin/cmake" -E cmake_link_script CMakeFiles/hellovbo.dir/link.txt --verbose=1
/opt/local/bin/g++-mp-4.8 --std=c++11 -Wl,-search_paths_first -Wl,-headerpad_max_install_names CMakeFiles/hellovbo.dir/main.cpp.o -o hellovbo -L/usr/local/lib -lglfw -lglew -framework Cocoa -framework OpenGL -framework IOKit -lstdc++
Undefined symbols for architecture x86_64:
"std::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator=(std::basic_string<char, std::char_traits<char>, std::allocator<char> >&&)", referenced from:
readTextFile(char const*) in main.cpp.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
make[2]: *** [hellovbo] Error 1
make[1]: *** [CMakeFiles/hellovbo.dir/all] Error 2
make: *** [all] Error 2

我看过很多帖子说这种错误是由于人们使用 gcc 而不是 g++,但在我的例子中我使用的是 g++。我正在使用 macports 构建的 GCC 4.8 进行编译。

请注意,这个简单的程序可以在同一系统上正常编译。全新安装后突然拒绝编译。

最佳答案

缺少的符号是 std::string 的移动赋值运算符。我在这里猜测发生的事情是你正在混合使用 libstd++libc++ 编译的目标文件/库。

关于c++ - Macports GCC 4.8 无法链接 OSX Lion 上的 c++ 库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12382188/

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