最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c - How do I link startup file inside of static library in GCC? - Stack Overflow

programmeradmin0浏览0评论

Clarification

I want to create static library from my code to share the artifacts (but not the code). I will call this Main_Project.

In my Main_Project, I have startup.s and flash.ld files.

startup.s:

    .section    .isr_vector,"a",%progbits
    .type   g_pfnVectors, %object


g_pfnVectors:
    .word   _estack
    .word   Reset_Handler
    .word   NMI_Handler
    .word   HardFault_Handler
    .word   MemManage_Handler
    .word   BusFault_Handler
    .word   UsageFault_Handler'
flash.ld:

/* Entry Point */
ENTRY(Reset_Handler)

/* Highest address of the user mode stack */
_estack = ORIGIN(RAM) + LENGTH(RAM); /* end of "RAM" Ram type memory */

_Min_Heap_Size = 0x200; /* required amount of heap */
_Min_Stack_Size = 0x400; /* required amount of stack */

/* Memories definition */
MEMORY
{
  RAM    (xrw)   : ORIGIN = 0x20000000,   LENGTH = 128K
  FLASH  (rx)    : ORIGIN = 0x8000000,    LENGTH = 436K
  API    (rx)    : ORIGIN = 0x806D000,    LENGTH = 32K
}

/* Sections */
SECTIONS
{
  /* The startup code into "FLASH" Rom type memory */
  .isr_vector :
  {
    . = ALIGN(4);
    KEEP(*(.isr_vector)) /* Startup code */
    . = ALIGN(4);
  } >FLASH

  /* The program code and other data into "FLASH" Rom type memory */
  .text :
  {
    . = ALIGN(4);
    *(.text)           /* .text sections (code) */
    *(.text*)          /* .text* sections (code) */
    *(.glue_7)         /* glue arm to thumb code */
    *(.glue_7t)        /* glue thumb to arm code */
    *(.eh_frame)

    KEEP (*(.init))
    KEEP (*(.fini))

    . = ALIGN(4);
    _etext = .;        /* define a global symbols at end of code */
  } >FLASH
  
  .api_section :
  {
    . = ALIGN(4);
    __api_section_start__ = .;
    *(.api_section*)
    __api_section_end__ = .;
   } > API
   
   ASSERT(LENGTH(API) >= (__api_section_end__ - __api_section_start__), "API memory overflowed !")
tx_initialize_low_leve.S:

    .global     _tx_thread_system_stack_ptr
    .global     _tx_initialize_unused_memory
    .global     _tx_timer_interrupt
    .global     __main
    .global     __tx_SVCallHandler
    .global     __tx_PendSVHandler
    .global     __tx_NMIHandler                     @ NMI
    .global     __tx_BadHandler                     @ HardFault
    .global     __tx_SVCallHandler                  @ SVCall
    .global     __tx_DBGHandler                     @ Monitor
    .global     __tx_PendSVHandler                  @ PendSV
    .global     __tx_SysTickHandler                 @ SysTick
    .global     __tx_IntHandler                     @ Int 0
    .global     __Vectors
#ifdef USE_DYNAMIC_MEMORY_ALLOCATION
    .global     Image$$RW_IRAM1$$ZI$$Limit
#endif
@
@
SYSTEM_CLOCK      =   160000000
SYSTICK_CYCLES    =   ((SYSTEM_CLOCK / 1000) -1)

    .text 32
    .align 4
    .syntax unified

I created static library named "Main_Lib.a" using all source and header files in my Main_Project.

After this point, I created an empty project is named "static_test". In this project, I added "Main_Lib.a", include files etc. After that, added static library to makefile as below but static_test can not find vector table from Main_Lib.a because I do not know how to implement that in empty project from a static library.

Makefile:

static_test.elf static_test.map: $(OBJS) $(USER_OBJS) makefile objects.list $(OPTIONAL_TOOL_DEPS)
    arm-none-eabi-gcc -o "static_test.elf" @"objects.list" $(USER_OBJS) $(LIBS) -mcpu=cortex-m4 --specs=nosys.specs -Wl,-Map="static_test.map" -Wl,--gc-sections -static -L"D:\workspace_arge\static_test\Lib" -l:Main_Lib.a -l:STL_Lib.a --specs=nano.specs -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb -Wl,--start-group -lc -lm -Wl,--end-group
    @echo 'Finished building target: $@'
    @echo ' '

Console Error:

D:/workspace_arge/static_lib_creator/Debug/../Src/tx_initialize_low_level.S:548: undefined reference to `g_pfnVectors'

How can I show or add my startup.s, tx_initialize_low_level.S and flash.ld configurations to static_test project?

Clarification

I want to create static library from my code to share the artifacts (but not the code). I will call this Main_Project.

In my Main_Project, I have startup.s and flash.ld files.

startup.s:

    .section    .isr_vector,"a",%progbits
    .type   g_pfnVectors, %object


g_pfnVectors:
    .word   _estack
    .word   Reset_Handler
    .word   NMI_Handler
    .word   HardFault_Handler
    .word   MemManage_Handler
    .word   BusFault_Handler
    .word   UsageFault_Handler'
flash.ld:

/* Entry Point */
ENTRY(Reset_Handler)

/* Highest address of the user mode stack */
_estack = ORIGIN(RAM) + LENGTH(RAM); /* end of "RAM" Ram type memory */

_Min_Heap_Size = 0x200; /* required amount of heap */
_Min_Stack_Size = 0x400; /* required amount of stack */

/* Memories definition */
MEMORY
{
  RAM    (xrw)   : ORIGIN = 0x20000000,   LENGTH = 128K
  FLASH  (rx)    : ORIGIN = 0x8000000,    LENGTH = 436K
  API    (rx)    : ORIGIN = 0x806D000,    LENGTH = 32K
}

/* Sections */
SECTIONS
{
  /* The startup code into "FLASH" Rom type memory */
  .isr_vector :
  {
    . = ALIGN(4);
    KEEP(*(.isr_vector)) /* Startup code */
    . = ALIGN(4);
  } >FLASH

  /* The program code and other data into "FLASH" Rom type memory */
  .text :
  {
    . = ALIGN(4);
    *(.text)           /* .text sections (code) */
    *(.text*)          /* .text* sections (code) */
    *(.glue_7)         /* glue arm to thumb code */
    *(.glue_7t)        /* glue thumb to arm code */
    *(.eh_frame)

    KEEP (*(.init))
    KEEP (*(.fini))

    . = ALIGN(4);
    _etext = .;        /* define a global symbols at end of code */
  } >FLASH
  
  .api_section :
  {
    . = ALIGN(4);
    __api_section_start__ = .;
    *(.api_section*)
    __api_section_end__ = .;
   } > API
   
   ASSERT(LENGTH(API) >= (__api_section_end__ - __api_section_start__), "API memory overflowed !")
tx_initialize_low_leve.S:

    .global     _tx_thread_system_stack_ptr
    .global     _tx_initialize_unused_memory
    .global     _tx_timer_interrupt
    .global     __main
    .global     __tx_SVCallHandler
    .global     __tx_PendSVHandler
    .global     __tx_NMIHandler                     @ NMI
    .global     __tx_BadHandler                     @ HardFault
    .global     __tx_SVCallHandler                  @ SVCall
    .global     __tx_DBGHandler                     @ Monitor
    .global     __tx_PendSVHandler                  @ PendSV
    .global     __tx_SysTickHandler                 @ SysTick
    .global     __tx_IntHandler                     @ Int 0
    .global     __Vectors
#ifdef USE_DYNAMIC_MEMORY_ALLOCATION
    .global     Image$$RW_IRAM1$$ZI$$Limit
#endif
@
@
SYSTEM_CLOCK      =   160000000
SYSTICK_CYCLES    =   ((SYSTEM_CLOCK / 1000) -1)

    .text 32
    .align 4
    .syntax unified

I created static library named "Main_Lib.a" using all source and header files in my Main_Project.

After this point, I created an empty project is named "static_test". In this project, I added "Main_Lib.a", include files etc. After that, added static library to makefile as below but static_test can not find vector table from Main_Lib.a because I do not know how to implement that in empty project from a static library.

Makefile:

static_test.elf static_test.map: $(OBJS) $(USER_OBJS) makefile objects.list $(OPTIONAL_TOOL_DEPS)
    arm-none-eabi-gcc -o "static_test.elf" @"objects.list" $(USER_OBJS) $(LIBS) -mcpu=cortex-m4 --specs=nosys.specs -Wl,-Map="static_test.map" -Wl,--gc-sections -static -L"D:\workspace_arge\static_test\Lib" -l:Main_Lib.a -l:STL_Lib.a --specs=nano.specs -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb -Wl,--start-group -lc -lm -Wl,--end-group
    @echo 'Finished building target: $@'
    @echo ' '

Console Error:

D:/workspace_arge/static_lib_creator/Debug/../Src/tx_initialize_low_level.S:548: undefined reference to `g_pfnVectors'

How can I show or add my startup.s, tx_initialize_low_level.S and flash.ld configurations to static_test project?

Share Improve this question edited Feb 6 at 13:40 B.Kaya asked Feb 6 at 9:04 B.KayaB.Kaya 115 bronze badges New contributor B.Kaya is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct. 1
  • Edit your question with a minimal reproducible example. We have no idea where HAL_TIM_MspPostInit and g_pfnVectors are with the information you've currently provided. – Stephen Newell Commented Feb 6 at 12:27
Add a comment  | 

1 Answer 1

Reset to default 1

I want to create static library from my code to share the artifacts (but not the code).

You can't, because an archive with the contents you describe is not a "static library" in the relevant sense.

Although you can store arbitrary files in an ar-style archive, these days that is unconventional. If you want to create a distribution package for files other than object files then it would be better to use a tar archive, possibly compressed, or maybe a ZIP archive.

Moreover, the recipient of any of these, even the ar archive, will almost certainly need to extract the files from the archive in order to use them. Build tools do not, in general, accept sources, linker scripts, or similar such files packaged in archives.

With regard to this ...

Console Error:

D:/workspace_arge/static_lib_creator/Debug/../Src/tx_initialize_low_level.S:548:

undefined reference to `g_pfnVectors'

Your startup.s is a source file, written in assembly language. I guess its name has special significance to certain IDEs. It needs to be assembled to produce an object file, and the result linked into your program. The linker cannot consume it directly, regardless of how it is packaged.

How can I show or add my startup.s, tx_initialize_low_level.S and flash.ld configurations to static_test project?

Unpack them from your archive into appropriate locations in your project's source space. If you are using an IDE (you didn't say, much less specify a particular one) then that may affect the details of which are the appropriate locations, and there may be additional, IDE-specific steps for configuring the project. Otherwise, details are driven by your makefile, build script, or intended sequence of manual build commands.

发布评论

评论列表(0)

  1. 暂无评论