How can I add LDFLAGS for bsp build?
Joel Sherrill
joel at rtems.org
Fri Jul 22 16:07:05 UTC 2022
On Fri, Jul 22, 2022 at 10:12 AM DAVE ERICKSON <daveerickson at shaw.ca> wrote:
> Thanks for stepping on my point, Joel. :)
>
Sorry if I said something that contradicted you.
>
> ( I attended the RTEMS Open course instructed by Joel many years ago... )
>
Thanks. :)
>
> Joel's comments on
>
> CFLAGS += -Og -g -Wall
> CXXFLAGS += -Og -g -Wall
>
> will NOT solve your gcc "can't find library problem" since these are
> tangential to your problem and are compiler flags. Compiler flags don't
> affect linking which is the stage where gcc/ar/ld programs create the code
> archive.
>
> If you want to express exactly which library to use then specify in the
> LDFLAGS environment variable in the folder where gcc is configured to
> "build from" in bsps/arm/tms570/config/xxx.cfg
>
> LDFLAGS += ~/ ...rest of explicit path... /arm-rtems5/lib/libm.a
>
> (NOTICE NO FLAG PREFIX ON EXPLICIT PATH)
>
libm.a should be implicitly along the search path. If it isn't, then
something isn't right with the tool chain.
Test case based on /tmp/t.c with the sparvc/leon3 bsp on the master:
============
int main(void)
{
return 0;
}
===========
===============================
BSPDIR=/home/joel/rtems-work/tools/6/bsp-install/sparc-rtems6/leon3/
ABI_FLAGS=-mcpu=leon3
CFLAGS="-Og -g -Wall"
sparc-rtems6-gcc ${ABI_FLAGS} ${CFLAGS} \
-B ${BSPDIR}/lib/ -qrtems t.c -o t \
-lrtemsdefaultconfig -lm
===============================
Since t.c is a stub main(), there is no RTEMS configuration and you need
the -lrtemsdefaultconfig.
-lm is in the same directory as libc.a and implicitly part of the library
search path. Every library provided by gcc, newlib, or RTEMS will be on the
search path.
If you follow the normal instructions for libbsd or lwip, they will be laid
into the BSP install directory and also available.
>
> Will instruct gcc/ar/ld to do exactly what you want, which is include
> EXACTLY that library at EXACTLY that location.
>
If you do it manually, you have to be careful to pick the right multilib
variant.
>
> The explicit library path can be used to check and see if it's a location
> problem before a library internals problem.
>
> nm -D or nm to find the missing symbol inside a library.
>
>
> BTW RTEMS uses GNU autotools differently in that it configures in one
> folder/directory and the builds targets into another folder is a very rare
> way of using autotools. I know this because I have downloaded and reviewed
> over 5000 open source projects for my new book.
>
Funny because the core GNU tools like gcc, binutils, gdb plus newlib all
allow out of tree builds.
It may be rare to use it this way but it works and leaves your source
directory with no build artifacts.
It also allows having multiple builds from the same source tree
simultaneously.
>
> Most GNU autotools projects configure IN THE FOLDER that they want to
> compile and archive source code. That's one reason why the problems of
> diagnosing RTEMS build configurations are harder.
>
This is not required for autotools. It is just the default instructions.
>
> Setting explicit file locations with absolute directories is a way to
> workaround the problems.
>
>
> Cheers!
>
> Daemondave on github
>
> Check out my new book Untrapped Value on LeanPub:
> https://leanpub.com/untrappedvalue
>
>
>
>
> ------------------------------
> *From: *"Joel Sherrill" <joel at rtems.org>
> *To: *"DAVE ERICKSON" <daveerickson at shaw.ca>
> *Cc: *"Y. HB" <sprhawk at gmail.com>, "rtems-users at rtems.org" <
> users at rtems.org>
> *Sent: *Friday, July 22, 2022 8:42:49 AM
> *Subject: *Re: How can I add LDFLAGS for bsp build?
>
> This is an application matter and it all depends on what build system you
> are using.
> If your build system is make, then something like this will probably work.
>
> LDFLAGS += -lm
>
> You may also want to ensure that the CFLAGS has the desired optimization,
> debug, and warning levels selected:
>
> CFLAGS += -Og -g -Wall
> CXXFLAGS += -Og -g -Wall
>
> If using waf, cmake, etc, etc, you ultimately want to produce the same
> invocations of gcc but the mechanics are different.
>
> --joel
>
> On Fri, Jul 22, 2022 at 9:09 AM DAVE ERICKSON <daveerickson at shaw.ca>
> wrote:
>
>> Hi Y.HB
>>
>> LDFLAGS sets both the library kind to include in the archive build but it
>> also uses the -L flags to know where to look for it. The -lm can mean the
>> libm.a. libm.so libm.la so it searches the LD_LIBRARY_PATH environment
>> variable to find one that fits. If you want expressly to include the libm.a
>> you should specify it instead of -lm. The first thing I recommend is find
>> the symbols inside the Makefile configured for the . Look for the LDFLAGS
>> and then your LD_LIBRARY_PATH to see if it matches where that
>> arm-rtems5/lib/libm.a is.
>>
>> You can even use the flag argument: arm-rtems5/lib/libm.a or
>> ./arm-rtems5/lib/libm.a to express the precise library and location to use.
>>
>> This is one important distinction that many people confuse about how
>> automake and autoconf work: There is no "internal logic" in the autotools
>> way of creating recipes for Makefiles. m4 is used for pattern processing.
>> You must express what you want it to make, it won't go looking anywhere
>> else than what is specified.
>>
>> It's not cmake, scons, or raw make. GNU Autotools creates recipe files,
>> like config.status, that just hold environmental variables.
>>
>> DaemonDave on github.
>>
>> ------------------------------
>> *From: *"Y. HB" <sprhawk at gmail.com>
>> *To: *"rtems-users at rtems.org" <users at rtems.org>
>> *Sent: *Friday, July 22, 2022 12:11:38 AM
>> *Subject: *Re: How can I add LDFLAGS for bsp build?
>>
>> I added -lm in LDFLAGS in my custom bsps/arm/tms570/config/xxx.cfg
>>
>> the flag is added to compiling arguments, but it still reported undefined
>> reference to 'floor', but I see there is floor symbols in the
>> arm-rtems5/lib/libm.a
>>
>> Why is it?
>>
>> Thanks
>>
>> On Fri, Jul 22, 2022 at 1:43 PM Y. HB <sprhawk at gmail.com> wrote:
>>
>>> Hello
>>>
>>> I'm working on a custom tms570 bsp upon RTEMS 5.1, but it depends on
>>> math lib (-lm), how can I add this flag to the bsp build?
>>>
>>> Shall I add LDFLAGS="-lm" during configure or shall I change some
>>> variables in c/src/lib/libbsp/arm/xxxx/Makefile.am?
>>>
>>> Thanks
>>>
>>
>> _______________________________________________
>> users mailing list
>> users at rtems.org
>> http://lists.rtems.org/mailman/listinfo/users
>>
>> _______________________________________________
>> users mailing list
>> users at rtems.org
>> http://lists.rtems.org/mailman/listinfo/users
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rtems.org/pipermail/users/attachments/20220722/380689f7/attachment.htm>
More information about the users
mailing list