Page 1 of 1

Can't tell linker to exclude stripping several functions

Posted: Thu Jun 04, 2020 10:17 am
by julienD
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

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

Posted: Thu Jun 04, 2020 10:45 pm
by ESP_renz
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.

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

Posted: Mon Jun 08, 2020 1:20 pm
by julienD
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...

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

Posted: Tue Jun 09, 2020 12:01 am
by ESP_renz
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?