使用Macports gcc47编译C ++链接错误

时间:2013-02-28 04:19:10

标签: macos eclipse-cdt macports

我正在使用Eclipse CDT中的macports在Mac 10.7.5上用gcc47编写一个小应用程序来学习C ++ 11中的新功能。我有大量的代码编译,链接和运行。当我将调用添加到“async”时,我收到链接器错误。最简单的程序将重现链接错误。提前感谢您的帮助。

#include <iostream>
#include <future>

using namespace std;

void bar()
{
cout << "!!!Hello World!!!" << endl;
}

int main() {
future<void> f1(async(bar));

return 0;
}

输出结果为:

21:56:46 **** Incremental Build of configuration Debug for project Hello ****
make all
Building file: ../src/Hello.cpp
Invoking: GCC C++ Compiler g++ -D__GXX_EXPERIMENTAL_CXX0X__ -I/opt/local/include/gcc47/c++ -O0 -g3 -Wall -c -fmessage-length=0 -std=c++11 -MMD -MP -MF"src/Hello.d" -MT"src/Hello.d" -o "src/Hello.o" "../src/Hello.cpp"
Finished building: ../src/Hello.cpp
Building target: Hello
Invoking: MacOS X C++ Linker g++  -o "Hello" 
./src/Hello.o    Undefined symbols for architecture x86_64:  
"___emutls_v._ZSt11__once_call", referenced from:
      void std::call_once<void (std::__future_base::_State_base::*)(std::function<std::unique_ptr<std::__future_base::_Result_base,
std::__future_base::_Result_base::_Deleter> ()>&, bool&),
std::__future_base::_State_base* const,
std::reference_wrapper<std::function<std::unique_ptr<std::__future_base::_Result_base,
std::__future_base::_Result_base::_Deleter> ()> >,
std::reference_wrapper<bool> >(std::once_flag&, void
(std::__future_base::_State_base::*&&)(std::function<std::unique_ptr<std::__future_base::_Result_base,
std::__future_base::_Result_base::_Deleter> ()>&, bool&),
std::__future_base::_State_base* const&&,
std::reference_wrapper<std::function<std::unique_ptr<std::__future_base::_Result_base,
std::__future_base::_Result_base::_Deleter> ()> >&&,
std::reference_wrapper<bool>&&) in Hello.o
      void std::call_once<void (std::thread::*)(), std::reference_wrapper<std::thread> >(std::once_flag&, void
(std::thread::*&&)(), std::reference_wrapper<std::thread>&&) in
Hello.o   "___emutls_v._ZSt15__once_callable", referenced from:
      void std::call_once<void (std::__future_base::_State_base::*)(std::function<std::unique_ptr<std::__future_base::_Result_base,
std::__future_base::_Result_base::_Deleter> ()>&, bool&),
std::__future_base::_State_base* const,
std::reference_wrapper<std::function<std::unique_ptr<std::__future_base::_Result_base,
std::__future_base::_Result_base::_Deleter> ()> >,
std::reference_wrapper<bool> >(std::once_flag&, void
(std::__future_base::_State_base::*&&)(std::function<std::unique_ptr<std::__future_base::_Result_base,
std::__future_base::_Result_base::_Deleter> ()>&, bool&),
std::__future_base::_State_base* const&&,
std::reference_wrapper<std::function<std::unique_ptr<std::__future_base::_Result_base,
std::__future_base::_Result_base::_Deleter> ()> >&&,
std::reference_wrapper<bool>&&) in Hello.o
      void std::call_once<void (std::thread::*)(), std::reference_wrapper<std::thread> >(std::once_flag&, void
(std::thread::*&&)(), std::reference_wrapper<std::thread>&&) in
Hello.o
      void std::__once_call_impl<std::_Bind_simple<std::_Mem_fn<void (std::__future_base::_State_base::*)(std::function<std::unique_ptr<std::__future_base::_Result_base,
std::__future_base::_Result_base::_Deleter> ()>&, bool&)>
(std::__future_base::_State_base*,
std::reference_wrapper<std::function<std::unique_ptr<std::__future_base::_Result_base,
std::__future_base::_Result_base::_Deleter> ()> >,
std::reference_wrapper<bool>)> >() in Hello.o
      void std::__once_call_impl<std::_Bind_simple<std::_Mem_fn<void (std::thread::*)()> (std::reference_wrapper<std::thread>)> >() in
Hello.o ld: symbol(s) not found for architecture x86_64 collect2:
error: ld returned 1 exit status make: *** [Hello] Error 1

1 个答案:

答案 0 :(得分:0)

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54806https://trac.macports.org/ticket/36093处的信息表明此错误是由于GCP的MacPorts版本中的错误造成的。根据{{​​3}},已经修复了MacPorts的r98493。如果你更新到端口存储库的那个版本然后重新安装GCC,我希望你的问题会消失。