File tree Expand file tree Collapse file tree 5 files changed +94
-0
lines changed Expand file tree Collapse file tree 5 files changed +94
-0
lines changed Original file line number Diff line number Diff line change 1+ build /
2+ nuttx-export * 
Original file line number Diff line number Diff line change 1+ cmake_minimum_required (VERSION  3.12...3.31)
2+ 
3+ project (OOTCpp
4+     VERSION  1.0
5+     DESCRIPTION "Out Of Tree Build C++ NuttX" 
6+ )
7+ 
8+ set (CMAKE_CXX_STANDARD 17)
9+ set (CMAKE_CXX_STANDARD_REQUIRED ON )
10+ 
11+ # Use CMAKE_SOURCE_DIR for source files 
12+ set (SOURCE_FILES 
13+     ${CMAKE_SOURCE_DIR} /src/HelloWorld.cpp
14+     ${CMAKE_SOURCE_DIR} /src/main.cpp
15+ )
16+ 
17+ set (EXE_NAME oot)
18+ 
19+ add_executable (${EXE_NAME}  ${SOURCE_FILES} )
20+ 
21+ # Add include directory so you can #include "..." from include/ 
22+ target_include_directories (${EXE_NAME} 
23+         PRIVATE 
24+         ${CMAKE_SOURCE_DIR} /include 
25+ )
26+ 
27+ # Generate a .bin file from the ELF after build 
28+ add_custom_command (
29+     TARGET  ${EXE_NAME} 
30+     POST_BUILD
31+     COMMAND  ${CMAKE_OBJCOPY}  -S -O binary
32+             ${CMAKE_BINARY_DIR} /${EXE_NAME} 
33+             ${CMAKE_BINARY_DIR} /${EXE_NAME} .bin
34+     COMMENT  "Generating binary image ${EXE_NAME} .bin" 
35+ )
Original file line number Diff line number Diff line change 1+ #pragma  once
2+ 
3+ class  CHelloWorld 
4+ {
5+ public: 
6+     CHelloWorld ();
7+     ~CHelloWorld () = default ;
8+ 
9+     bool  HelloWorld ();
10+ 
11+ private: 
12+     int  mSecret ;
13+ };
Original file line number Diff line number Diff line change 1+ #include  < cstdio> 
2+ #include  < string> 
3+ 
4+ #include  " HelloWorld.hpp" 
5+ 
6+ CHelloWorld::CHelloWorld ()
7+ {
8+     mSecret  = 42 ;
9+     std::printf (" Constructor: mSecret=%d\n "  ,mSecret );
10+ }
11+ 
12+ 
13+ bool  CHelloWorld::HelloWorld ()
14+ {
15+     std::printf (" HelloWorld: mSecret=%d\n "  ,mSecret );
16+ 
17+     std::string sentence = " Hello"  ;
18+     std::printf (" TEST=%s\n "  ,sentence.c_str ());
19+ 
20+     if  (mSecret  == 42 )
21+     {
22+             std::printf (" CHelloWorld: HelloWorld: Hello, world!\n "  );
23+             return  true ;
24+     }
25+     else 
26+     {
27+             std::printf (" CHelloWorld: HelloWorld: CONSTRUCTION FAILED!\n "  );
28+             return  false ;
29+     }
30+ }
Original file line number Diff line number Diff line change 1+ #include  < memory> 
2+ 
3+ #include  " HelloWorld.hpp" 
4+ 
5+ int  main (int , char *[])
6+ {
7+     auto  pHelloWorld = std::make_shared<CHelloWorld>();
8+     pHelloWorld->HelloWorld ();
9+ 
10+     CHelloWorld helloWorld;
11+     helloWorld.HelloWorld ();
12+ 
13+     return  0 ;
14+ }
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments