Skip to contentSkip to conversation

Linking archive to hello_world in standalone

DISCUSSION Lists Nick Betteridge 1 participant 1 message Apr 22, 2022

lore
Share & tools
lore
#0 lore raw

Hi!

Apologies for this beginner question! I'm trying to reference an archive from the hello_world example in standalone.

The archive contains one object file - mystart_up.c:

int printf(const char* fmt, ...);

int my_hello_world(int argc, char *const argv[])
{
        printf ("Hello World\n");
        return (0);
}

The compiled archive is libmy.a and 'ar -t libmy.a' gives 'my_startup.o'.

The new version of hello_world.c is:

#include <stdint.h>
#include <stddef.h>

extern void app_startup (char *const argv[]);

extern int my_hello_world(int argc, char *const argv[]);

int startup(int argc, char *const argv[])
{

  app_startup(argv);

  my_hello_world(argc, argv);

  return (0);

}

So, I've added libmy.a to the standalone directory and updated Makefile with 'LDFLAGS_STANDALONE += -L $(obj) -lmy'

When I do a 'make', I get the error: undefined reference to `my_hello_world'

The position of the failure in the Makefile is:

$(ELF): $(obj)/%: $(obj)/%.o $(LIB) FORCE
        $(call if_changed,link_elf)

Could anyone possibly suggest where I could fix this? Again, apologies for such a basic question.

Best wishes

Nick