Undefined symbol std::__throw_bad_function_call

那年仲夏 提交于 2019-12-25 03:22:26

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!