Page 1 of 1

Static library - call target out of range

Posted: Wed Nov 23, 2016 10:05 am
by lchazall
Hi,

I am having trouble compiling a project which is including a static library (a ".a" file).

When I make the project I get those two errors :

Code: Select all

componentpath/lib/xtensa-esp32-elf/mylib.a(user.o): In function `delete_user':
user.c:(.text.delete_user+0x5): dangerous relocation: call8: call target out of range: free
componentpath/lib/xtensa-esp32-elf/mylib.a(user.o): In function `user_create':
user.c:(.text.user_create+0x5): dangerous relocation: call8: call target out of range: malloc
But in the make stdout, I can see that the "-mlongcalls" option is enabled, so why would malloc and free be out of range ? xtensa should link them, am I wrong ?

Here is my project tree.
  • components
    • MyComponent
      • include
        • library headers
      • lib
        • xtensa-esp32-elf
          • mylib.a
      • component.mk
        • COMPONENT_ADD_LDFLAGS=$(COMPONENT_PATH)/lib/xtensa-esp32-elf/mylib.a -l$(COMPONENT_NAME)
        • include $(IDF_PATH)/make/component_common.mk
      • mycomp.c
  • main
    • main.c
    • component.mk => include $(IDF_PATH)/make/component_common.mk
  • Makefile => include $(IDF_PATH)/make/project.mk

Re: Static library - call target out of range

Posted: Wed Nov 23, 2016 11:03 am
by ESP_Sprite
Do you compile the lib from source? If you add the source as a component to your esp-idf project, it should work just fine. If not, maybe whatever C-flags you use aren't compatible with what esp-idf expects.

Re: Static library - call target out of range

Posted: Wed Nov 23, 2016 11:47 am
by lchazall
Thank you for your answer.

The lib is provided by a third party.
Do they have to recompile with specific options ? if so, which ones ?
Or how can I compile my project without recompiling this lib ?

Re: Static library - call target out of range

Posted: Wed Nov 23, 2016 3:58 pm
by ESP_igrr
This error would happen if the static library is compiled without mlongcalls. Check with the third party about the flags they are using to compile the lib.

Re: Static library - call target out of range

Posted: Fri Dec 02, 2016 9:43 am
by lchazall
Hi,

Compiling the third party lib with the "-mlongcalls" option did the job.
Thank you for your help.

Re: Static library - call target out of range

Posted: Sat Nov 11, 2017 5:54 am
by pratik.yadav.455
Hello,

I am porting libxml in esp-idf i did same as you did, but i have not added source code, because i want to use lib file when ever my library is needed.
my component folder is structured as follow:

component
--libmxml
--include
(Contain Header file)
--lib
(contain libmxml.a file)
--component.mk
COMPONENT_ADD_LDFLAGS=$(COMPONENT_PATH)/lib/libmxml.a -l$(COMPONENT_NAME)
include $(IDF_PATH)/make/component_common.mk
--main
--main.c
contain Application Code
--component.mk
include $(IDF_PATH)/make/component_common.mk


When I compile this , I got following error

user/esp-idf-v2.1/components/libmxml/lib/libmxml.a: error adding symbols: File format not recognized
collect2: error: ld returned 1 exit status

What i am doing wrong? What i should do?
Can anyone give me any suggestion ?