我无法在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进行编译。
请注意,这个简单的程序可以在同一系统上正常编译。在彻底安装后,它突然拒绝编译。
答案 0 :(得分:1)
缺少的符号是std::string
的移动赋值运算符。我将在这里猜测,你正在混合使用libstd++
和libc++
编译的目标文件/库。
答案 1 :(得分:0)
你可以链接/ usr / lib / libstdc ++但是对于4.8你需要链接(...)/ gcc4.8 / lib / libstdc ++,它是不同的库。