Can't tell linker to exclude stripping several functions

julienD
Posts: 32
Joined: Fri Sep 13, 2019 12:38 pm

Can't tell linker to exclude stripping several functions

Postby julienD » Thu Jun 04, 2020 10:17 am

Hello,

I have several components in my project. Some of them are using functions from others.

In order to avoid compiler to strip the functions that are not used by the main component, I use the -u option like this:


main's CMakeLists.txt :

Code: Select all

<snip>

target_link_options(
	${COMPONENT_LIB} 
	PUBLIC
	-u SpiInOut
	)
and this works as expected, no more "undefined reference".

Now, if I want to add several functions, I do something like this :

Code: Select all

target_link_options(
	${COMPONENT_LIB} 
	PUBLIC
	-u SpiInOut 
        -u memcpy1
	)
This does not work because, CMake, generates this command line :

Code: Select all

<snip> -u SpiInOut memcpy1
While it should be

Code: Select all

<snip> -u SpiInOut -u memcpy1
How should I do?

Thanks
Julien

ESP_renz
Posts: 18
Joined: Tue May 14, 2019 2:41 am

Re: Can't tell linker to exclude stripping several functions

Postby ESP_renz » Thu Jun 04, 2020 10:45 pm

Can you try enclosing them in quotes?

Code: Select all

target_link_options(
	${COMPONENT_LIB} 
	PUBLIC
	"-u SpiInOut" "-u memcpy1"
	)

P.S. Note `target_link_options` requires at least a CMake version > 3.13.

julienD
Posts: 32
Joined: Fri Sep 13, 2019 12:38 pm

Re: Can't tell linker to exclude stripping several functions

Postby julienD » Mon Jun 08, 2020 1:20 pm

It doesn't work.

Command line becomes:

Code: Select all

&& /home/ju/tools/crosstool-NG/builds/xtensa-esp32-elf/bin/xtensa-esp32-elf-g++  -mlongcalls -Wno-frame-address  "-u memcpy1" "-u SpiInOut" "-u DelayMs" CMakeFile
as a result : undefined reference to SpiInOut...

ESP_renz
Posts: 18
Joined: Tue May 14, 2019 2:41 am

Re: Can't tell linker to exclude stripping several functions

Postby ESP_renz » Tue Jun 09, 2020 12:01 am

On the contrary, it means that the `-u` argument for `SpiInOut` works, since you're forcing the linker to not drop `SpiInOut` but it is not finding it. Is the source file containing definition for `SpiInOut` is included in the build?

Who is online

Users browsing this forum: No registered users and 243 guests