C++ 使用gcc/g++;MinGW的仪器功能?

C++ 使用gcc/g++;MinGW的仪器功能?,c++,gcc,mingw,C++,Gcc,Mingw,我尝试在MinGW的g++编译器中使用gcc工具函数,但是我 总是有链接器问题。是否可以将仪表功能与一起使用 MinGW/MSYS 链接器故障输出: $ g++ instrumentFunctions.cpp -o iftest -finstrument-functions >> iflog.txt C:/Users/HELLHO~1/AppData/Local/Temp/ccUwxrxt.o:instrumentFunctions.cpp:(.text+0x4e): undefin

我尝试在MinGW的g++编译器中使用gcc工具函数,但是我 总是有链接器问题。是否可以将仪表功能与一起使用 MinGW/MSYS

链接器故障输出:

$ g++ instrumentFunctions.cpp -o iftest -finstrument-functions >> iflog.txt
C:/Users/HELLHO~1/AppData/Local/Temp/ccUwxrxt.o:instrumentFunctions.cpp:(.text+0x4e): undefined reference to `__cyg_prof
ile_func_enter'
C:/Users/HELLHO~1/AppData/Local/Temp/ccUwxrxt.o:instrumentFunctions.cpp:(.text+0x158): undefined reference to `__cyg_pro
file_func_exit'
C:/Users/HELLHO~1/AppData/Local/Temp/ccUwxrxt.o:instrumentFunctions.cpp:(.text+0x179): undefined reference to `__cyg_pro
file_func_enter'
C:/Users/HELLHO~1/AppData/Local/Temp/ccUwxrxt.o:instrumentFunctions.cpp:(.text+0x18c): undefined reference to `__cyg_pro
file_func_exit'
C:/Users/HELLHO~1/AppData/Local/Temp/ccUwxrxt.o:instrumentFunctions.cpp:(.text+0x1a7): undefined reference to `__cyg_pro
file_func_enter'
C:/Users/HELLHO~1/AppData/Local/Temp/ccUwxrxt.o:instrumentFunctions.cpp:(.text+0x1bf): undefined reference to `__cyg_pro
file_func_exit'
C:/Users/HELLHO~1/AppData/Local/Temp/ccUwxrxt.o:instrumentFunctions.cpp:(.text+0x1db): undefined reference to `__cyg_pro
file_func_enter'
C:/Users/HELLHO~1/AppData/Local/Temp/ccUwxrxt.o:instrumentFunctions.cpp:(.text+0x1f3): undefined reference to `__cyg_pro
file_func_exit'
C:/Users/HELLHO~1/AppData/Local/Temp/ccUwxrxt.o:instrumentFunctions.cpp:(.text+0x22f): undefined reference to `__cyg_pro
file_func_enter'
C:/Users/HELLHO~1/AppData/Local/Temp/ccUwxrxt.o:instrumentFunctions.cpp:(.text+0x27a): undefined reference to `__cyg_pro
file_func_exit'
C:/Users/HELLHO~1/AppData/Local/Temp/ccUwxrxt.o:instrumentFunctions.cpp:(.text+0x29b): undefined reference to `__cyg_pro
file_func_enter'
C:/Users/HELLHO~1/AppData/Local/Temp/ccUwxrxt.o:instrumentFunctions.cpp:(.text+0x2e4): undefined reference to `__cyg_pro
file_func_exit'
C:/Users/HELLHO~1/AppData/Local/Temp/ccUwxrxt.o:instrumentFunctions.cpp:(.text+0x2ff): undefined reference to `__cyg_pro
file_func_enter'
C:/Users/HELLHO~1/AppData/Local/Temp/ccUwxrxt.o:instrumentFunctions.cpp:(.text+0x326): undefined reference to `__cyg_pro
file_func_exit'
C:/Users/HELLHO~1/AppData/Local/Temp/ccUwxrxt.o:instrumentFunctions.cpp:(.text+0x341): undefined reference to `__cyg_pro
file_func_enter'
C:/Users/HELLHO~1/AppData/Local/Temp/ccUwxrxt.o:instrumentFunctions.cpp:(.text+0x368): undefined reference to `__cyg_pro
file_func_exit'
C:/Users/HELLHO~1/AppData/Local/Temp/ccUwxrxt.o:instrumentFunctions.cpp:(.text$printf[_printf]+0x16): undefined referenc
e to `__cyg_profile_func_enter'
C:/Users/HELLHO~1/AppData/Local/Temp/ccUwxrxt.o:instrumentFunctions.cpp:(.text$printf[_printf]+0x43): undefined referenc
e to `__cyg_profile_func_exit'
C:/Users/HELLHO~1/AppData/Local/Temp/ccUwxrxt.o:instrumentFunctions.cpp:(.text$_ZSt3minIjERKT_S2_S2_[unsigned int const&
 std::min<unsigned int>(unsigned int const&, unsigned int const&)]+0x15): undefined reference to `__cyg_profile_func_ent
er'
C:/Users/HELLHO~1/AppData/Local/Temp/ccUwxrxt.o:instrumentFunctions.cpp:(.text$_ZSt3minIjERKT_S2_S2_[unsigned int const&
 std::min<unsigned int>(unsigned int const&, unsigned int const&)]+0x42): undefined reference to `__cyg_profile_func_exi
t'
collect2: ld returned 1 exit status
我的testsource列表:

#include <stdio.h>

  void __cyg_profile_func_enter( void *, void * ) __attribute__ ((no_instrument_function));

  void __cyg_profile_func_enter(void *func, void *callsite)
  {
    printf("%p\n", (int)func);
  }


  void func_c( void )
  {
    return;
  }

  void func_b( void )
  {
    func_c();

    return;
  }

  void func_a( void )
  {
    func_b();
    return;
  }


  int main()
  {
    func_a();
    func_c();
  }
#包括
void uuu cyg u profile u func u enter(void*,void*)uuu属性uuu((无工具函数));
void\uuu cyg\u profile\u func\u enter(void*func,void*callsite)
{
printf(“%p\n”,(int)func);
}
无效函数(无效)
{
返回;
}
无效函数b(无效)
{
func_c();
返回;
}
无效函数a(无效)
{
func_b();
返回;
}
int main()
{
func_a();
func_c();
}

您需要为u cyg*函数指定“C”链接。C++中定义的函数通常会被损坏的名称无法从C++中使用的库中使用。您可以要求编译器通过使用`extern“C{}块为函数命名为C。下面的代码应该可以编译

#include <stdio.h>

extern "C" {
  void __cyg_profile_func_enter( void *, void * ) __attribute__ ((no_instrument_function));

  void __cyg_profile_func_enter(void *func, void *callsite)
  {
    printf("enter %p\n", func);
  }
  void __cyg_profile_func_exit( void *, void * ) __attribute__ ((no_instrument_function));

  void __cyg_profile_func_exit(void *func, void *callsite)
  {
    printf("exit %p\n", func);
  }

}
  void func_c( void )
  {
    return;
  }

  void func_b( void )
  {
    func_c();

    return;
  }

  void func_a( void )
  {
    func_b();
    return;
  }


  int main()
  {
    func_a();
    func_c();
  }
#包括
外部“C”{
void uuu cyg u profile u func u enter(void*,void*)uuu属性uuu((无工具函数));
void\uuu cyg\u profile\u func\u enter(void*func,void*callsite)
{
printf(“输入%p\n”,func);
}
void uuu cyg u profile u func u exit(void*,void*)uuu属性uuu((无工具函数));
void\uuu cyg\u profile\u func\u退出(void*func,void*callsite)
{
printf(“退出%p\n”,func);
}
}
无效函数(无效)
{
返回;
}
无效函数b(无效)
{
func_c();
返回;
}
无效函数a(无效)
{
func_b();
返回;
}
int main()
{
func_a();
func_c();
}

您需要为u cyg*函数指定“C”链接。C++中定义的函数通常会被损坏的名称无法从C++中使用的库中使用。您可以要求编译器通过使用`extern“C{}块为函数命名为C。下面的代码应该可以编译

#include <stdio.h>

extern "C" {
  void __cyg_profile_func_enter( void *, void * ) __attribute__ ((no_instrument_function));

  void __cyg_profile_func_enter(void *func, void *callsite)
  {
    printf("enter %p\n", func);
  }
  void __cyg_profile_func_exit( void *, void * ) __attribute__ ((no_instrument_function));

  void __cyg_profile_func_exit(void *func, void *callsite)
  {
    printf("exit %p\n", func);
  }

}
  void func_c( void )
  {
    return;
  }

  void func_b( void )
  {
    func_c();

    return;
  }

  void func_a( void )
  {
    func_b();
    return;
  }


  int main()
  {
    func_a();
    func_c();
  }
#包括
外部“C”{
void uuu cyg u profile u func u enter(void*,void*)uuu属性uuu((无工具函数));
void\uuu cyg\u profile\u func\u enter(void*func,void*callsite)
{
printf(“输入%p\n”,func);
}
void uuu cyg u profile u func u exit(void*,void*)uuu属性uuu((无工具函数));
void\uuu cyg\u profile\u func\u退出(void*func,void*callsite)
{
printf(“退出%p\n”,func);
}
}
无效函数(无效)
{
返回;
}
无效函数b(无效)
{
func_c();
返回;
}
无效函数a(无效)
{
func_b();
返回;
}
int main()
{
func_a();
func_c();
}