|
Re: Try to compile C program [message #1810972 is a reply to message #1810847] |
Thu, 22 August 2019 19:53 |
David Vavra Messages: 1426 Registered: October 2012 |
Senior Member |
|
|
Includes such as #include <math.h> are only for the compiler.
They are source files which describe the interface to external routines.
The linker only cares about object files.
So you need to tell the linker where to find them.
They could be standalone object files (like the ones in your program)
or they could be contained in library files.
The object for cos is contained in the C Math Library.
It's name is usually libm with a .a or .so extent in Linux.
With GCC, some libraries are always searched by the linker.
libm is not one of them.
With the GCC linker, you only give the library root name m with the option -l (small L)
Go to Project --> Properties --> C/C++ Build --> Settings --> <Tool Settings tab> --> <linker> --> Libraries
Add m to the top pane.
This will cause -lm to be appended to the link command.
When cross compiling, you need to link libraries created for your target machine.
Your normal system libraries likely haven't been built for the target machine so
you will need to add the path to the target machine libraries in the bottom pane.
This will cause -L<path> to be added to the link command.
Eclipse expects that you know how to use the compiler and linker outside of Eclipse.
Here are the linker options: https://gcc.gnu.org/onlinedocs/gcc/Link-Options.html
Here's the complete option set: https://gcc.gnu.org/onlinedocs/gcc/Option-Summary.html
Google tutorial compiling and linking with gcc for more info.
[Updated on: Thu, 22 August 2019 20:06] Report message to a moderator
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04024 seconds