Guest User

Untitled

a guest
Dec 14th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. #include "misc.h"
  2.  
  3. int main(){
  4. say_hello();
  5. return 0;
  6. }
  7.  
  8. #ifndef _MISC_H_
  9. #define _MISC_H_
  10.  
  11. /**
  12. * brief Prints hello to stdout
  13. */
  14. void say_hello();
  15.  
  16. #endif /* _MISC_H_ */
  17.  
  18. /* C++ implementation */
  19. #include <iostream>
  20.  
  21. using namespace std;
  22.  
  23. void cpp_say_hello(){
  24. cout << "Hello world!" << endl;
  25. }
  26.  
  27. /* C wrapper */
  28. extern "C"{
  29. #include "misc.h"
  30.  
  31. void say_hello(){
  32. cpp_say_hello();
  33. }
  34. }
  35.  
  36. CFLAGS += -lstdc++
  37. CXXFLAGS += -c
  38.  
  39. hello_world_mix: misc.o main.c
  40. $(CC) $(CFLAGS) $^ -o $@
  41.  
  42. misc.o: misc.cpp
  43. $(CXX) $(CXXFLAGS) $^ -o $@
  44.  
  45. clean:
  46. rm -f *.o
  47. rm -f *~
  48.  
  49. CC=arm-none-eabi-gcc CXX=arm-none-eabi-g++ CFLAGS=--specs=nosys.specs make
  50.  
  51. arm-none-eabi-gcc --specs=nosys.specs -lstdc++ misc.o main.c -o hello_world_mix
  52. /usr/lib/gcc/arm-none-eabi/8.2.0/../../../../arm-none-eabi/bin/ld: misc.o: in function `cpp_say_hello()':
  53. misc.cpp:(.text+0x34): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
  54. /usr/lib/gcc/arm-none-eabi/8.2.0/../../../../arm-none-eabi/bin/ld: misc.cpp:(.text+0x44): undefined reference to `std::ostream::operator<<(std::ostream& (*)(std::ostream&))'
  55. /usr/lib/gcc/arm-none-eabi/8.2.0/../../../../arm-none-eabi/bin/ld: misc.cpp:(.text+0x5c): undefined reference to `std::cout'
  56. /usr/lib/gcc/arm-none-eabi/8.2.0/../../../../arm-none-eabi/bin/ld: misc.cpp:(.text+0x60): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)'
  57. /usr/lib/gcc/arm-none-eabi/8.2.0/../../../../arm-none-eabi/bin/ld: misc.o: in function `__static_initialization_and_destruction_0(int, int)':
  58. misc.cpp:(.text+0xb4): undefined reference to `std::ios_base::Init::Init()'
  59. /usr/lib/gcc/arm-none-eabi/8.2.0/../../../../arm-none-eabi/bin/ld: misc.cpp:(.text+0xe4): undefined reference to `std::ios_base::Init::~Init()'
  60. collect2: error: ld returned 1 exit status
  61. make: *** [Makefile:5: hello_world_mix] Error 1
  62.  
  63. hello_world_mix: misc.o main.o
  64. $(CC) $(CFLAGS) $^ -o $@
  65.  
  66. main.o: main.c
  67. $(CC) -c $(CFLAGS) $^ -o $@
  68.  
  69. misc.o: misc.cpp
  70. $(CXX) -c $(CXXFLAGS) $^ -o $@
  71.  
  72. clean:
  73. rm -f *.o
  74. rm -f *~
Add Comment
Please, Sign In to add comment