问题
I'm building C++ code in Eclipse CDT with g++ and I'm getting the following linker error:
Undefined symbols for architecture x86_64:
"std::__throw_bad_function_call()", referenced from:
std::function<void (graphics::RenderingContext*)>::operator()(graphics::RenderingContext*) const in GameWindow.o
I have std::function
members in a class called GameWindow.
Is there something I have to link to in order to get code using std::function
to link properly?
回答1:
Turns out my lib path wasn't set correctly for g++.
For posterity: I use gcc 4.7 for compiling because I need C++11 features. XCode (on OS X Mountain Lion), ships with gcc 4.2 so I installed gcc 4.7 through Homebrew.
For Eclipse to compile with gcc 4.7, I had to change the path to the compiler and linker in project settings to correspond to the newly installed via Homebrew version. However, I still had the old library path to the gcc 4.2 stdlibc++ in my project settings.
回答2:
If this is your only error, why you don't try to implement that function in your own code? something like:
namespace std {
void __throw_bad_function_call() {throw bad_function_call("invalid function called");}
}
来源:https://stackoverflow.com/questions/12942538/undefined-symbol-std-throw-bad-function-call