I’m having trouble linking a very simple c++ program on OSX Lion. The error message is
Undefined symbols for architecture x86_64: "std::basic_string<char, std::char_traits<char>
Here’s the complete verbose output from the compiler:
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
I’ve seen various posts saying that this kind of error is due to people using gcc instead of g++ but in my case I use g++. I’m compiling using a macports built GCC 4.8.
Note that this simple program would compile fine on the same system. After a clean install all of a sudden it refuses to compile.
The missing symbol is the move assignment operator for
std::string. I’m going to guess here that what’s going on is you’re mixing object files/libraries that are compiled withlibstd++andlibc++.