mE.cpp 845 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #include <cstdlib>
  2. #include <cstdio>
  3. #include <iostream>
  4. static void
  5. bye_setup()
  6. {
  7. std::cout << "mE " << __FUNCTION__ << std::endl;
  8. }
  9. static void
  10. bye_func()
  11. {
  12. std::cout << "mE " << __FUNCTION__ << std::endl;
  13. }
  14. __attribute__((constructor)) void
  15. setup()
  16. {
  17. std::cout << "mE " << __FUNCTION__ << std::endl;
  18. if (std::atexit(bye_setup) != 0) {
  19. std::perror("register an atexit handler failed");
  20. }
  21. }
  22. __attribute__((destructor)) void
  23. teardown()
  24. {
  25. std::cout << "mE " << __FUNCTION__ << std::endl;
  26. }
  27. __attribute__((export_name("func1"))) void
  28. func1()
  29. {
  30. std::cout << "mE " << __FUNCTION__ << std::endl;
  31. if (std::atexit(bye_func) != 0) {
  32. std::perror("register an atexit handler failed");
  33. }
  34. }
  35. __attribute__((export_name("func2"))) void
  36. func2()
  37. {
  38. std::cout << "mE " << __FUNCTION__ << std::endl;
  39. }