How to create a static library on nRF Connect SDK/Zephyr

Hi,

I am using nrF52840 with nRF Connect, Visual Code Studio (Zephyr) 

Is there any guide or a tutorial with an example that shows how to create a static library on nRF Connect SDK/Zephyr?

There are some topics opened related to this, but none of them have the complete solution.

Please if you can explain in detail, it would help everyone a lot. Thanks

Parents
  • Thank you  I will continue with bash until your last solution is released.

    I have a related question. Current example only one .c and .h file. I want to create only one .a file. with multiple .c and .h files.

    Can you help on this?

    I made these changes on file but it didn't work.

    PREFIX ?= .
    OBJ_DIR ?= $(PREFIX)/obj
    LIB_DIR ?= $(PREFIX)/lib
    
    all:
    	mkdir -p $(OBJ_DIR) $(LIB_DIR)
    	$(CC) -c $(CFLAGS) -MD -Iinclude src/mylib.c src/mylib_led.c -o $(OBJ_DIR)/mylib.o $(OBJ_DIR)/mylib_led.o
    	$(AR) -rcs $(LIB_DIR)/libmylib.a $(OBJ_DIR)/mylib.o $(OBJ_DIR)/mylib_led.o
    
    clean:
    	rm -rf $(OBJ_DIR) $(LIB_DIR)

Reply
  • Thank you  I will continue with bash until your last solution is released.

    I have a related question. Current example only one .c and .h file. I want to create only one .a file. with multiple .c and .h files.

    Can you help on this?

    I made these changes on file but it didn't work.

    PREFIX ?= .
    OBJ_DIR ?= $(PREFIX)/obj
    LIB_DIR ?= $(PREFIX)/lib
    
    all:
    	mkdir -p $(OBJ_DIR) $(LIB_DIR)
    	$(CC) -c $(CFLAGS) -MD -Iinclude src/mylib.c src/mylib_led.c -o $(OBJ_DIR)/mylib.o $(OBJ_DIR)/mylib_led.o
    	$(AR) -rcs $(LIB_DIR)/libmylib.a $(OBJ_DIR)/mylib.o $(OBJ_DIR)/mylib_led.o
    
    clean:
    	rm -rf $(OBJ_DIR) $(LIB_DIR)

Children
Related