Menu

#75 run Makefile in a modified example app

release
open
nobody
None
1
2023-12-31
2023-12-26
No

Hello,

Can the samples in the "apps" directory be compiled individually? Or how would one go about creating a custom app? Am new to this project so not a lot of wisdom here...

When I glone the repo onto raspi pi linux it compiles fine with a make clean all in the root directory of the clone project and I can run the readprop example app just fine to get a sensor reading of a device on my test bench... but when I try to modify the code or even just run make clean and then make in that same app/readprop directory i get these errors:

bbartling@benspi:~/bacnet-stack/apps/readprop $ make clean
rm -f core bacrp main.o /bacnet/basic/object/client/device-client.o /bacnet/basic/object/netport.o bacrp.map 
bbartling@benspi:~/bacnet-stack/apps/readprop $ make
cc -c  main.c -o main.o
main.c:38:10: fatal error: bacnet/bacdef.h: No such file or directory
   38 | #include "bacnet/bacdef.h"
      |          ^~~~~~~~~~~~~~~~~
compilation terminated.
make: *** [Makefile:27: main.o] Error 1

Is this a linking error? Any tips appreciated am curious to work with some existing code to get used to the project if possible... Thanks!

Discussion

  • Steve Karg

    Steve Karg - 2023-12-27

    The apps/ example projects rely on some defines in apps/Makefile and would need to 'start' there. You can see the example of this in the root Makefile:

    .PHONY: writepropm
    writepropm:
        $(MAKE) -s -C apps $@
    

    -s means 'silent'
    -C mean to run make from that folder
    $@ is shorthand for the recipe name

    The recipe for each of the apps/ is in the apps/Makefile after some common defines are configured.

    Most of the example apps rely on the library build, which simply reduces the size of the executable and makes it easier for maintaining.

    For a new apps/ project, just add a recipe into apps/Makefile to build it, and include another apps/project-name/Makefile that finishes the custom build.

    Alternately, you can create your own Makefile and add only the C files you need with the defines that you need. Most of the microcontroller ports do this.

     
  • Ben Bartling

    Ben Bartling - 2023-12-27

    Ah okay thanks Steve I think I am figuring it out now! Taking a course in C on coursera helps a bit too : )

    I ended up making a duplicate of the app/readprop and named it bensreadprop.

    Where then in the project root directory Makefile I added:
    .PHONY: bensreadprop bensreadprop: $(MAKE) -C apps bensreadprop

    And in the apps directory Makefile I added
    .PHONY: bensreadprop bensreadprop: $(BACNET_LIB_TARGET) $(MAKE) -B -C bensreadprop

    When then in the root directoy when I run a make clean and a make bensreadprop it all appeared to compile well. I also had to add my app into the SUBDIRS but I think I am good for the time being if these steps seems legit!

     
  • Ben Bartling

    Ben Bartling - 2023-12-30

    Hi Steve,

    Has anyone ever ran across a compile error undefined symbol: bip_cleanup

    Would there be a bip_cleanup.c file or something similar in the project directory I should be refencing?

    Thanks!

     
    • Steve Karg

      Steve Karg - 2023-12-31

      For the example apps, the OS datalink is chosen in apps/Makefile and the files built for the specific datalink chosen in apps/lib/Makefile.

      The datalink.h module uses C macros to redefine the datalink specific functions, most (all) of which are in ports/xyz folder for the specific OS/non-OS datalink. For example, BACDL_BIP:

      #elif defined(BACDL_BIP)
      #include "bacnet/datalink/bip.h"
      #include "bacnet/datalink/bvlc.h"
      #include "bacnet/basic/bbmd/h_bbmd.h"
      #define MAX_MPDU BIP_MPDU_MAX
      
      #define datalink_init bip_init
      #define datalink_send_pdu bip_send_pdu
      #define datalink_receive bip_receive
      #define datalink_cleanup bip_cleanup
      #define datalink_get_broadcast_address bip_get_broadcast_address
      #ifdef BAC_ROUTING
      #ifdef __cplusplus
      extern "C" {
      #endif
      BACNET_STACK_EXPORT
      void routed_get_my_address(
          BACNET_ADDRESS * my_address);
      #ifdef __cplusplus
      }
      #endif
      #define datalink_get_my_address routed_get_my_address
      #else
      #define datalink_get_my_address bip_get_my_address
      #endif
      #define datalink_maintenance_timer(s) bvlc_maintenance_timer(s)
      

      In ports/linux/bip-init.c:

      /** Cleanup and close out the BACnet/IP services by closing the socket.
       * @ingroup DLBIP
       */
      void bip_cleanup(void)
      {
          if (BIP_Socket != -1) {
              close(BIP_Socket);
          }
          BIP_Socket = -1;
      
          if (BIP_Broadcast_Socket != -1) {
              close(BIP_Broadcast_Socket);
          }
          BIP_Broadcast_Socket = -1;
      
          return;
      }
      
       

Anonymous
Anonymous

Add attachments
Cancel