Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » Try to compile C program
Try to compile C program [message #1810847] Tue, 20 August 2019 14:34 Go to next message
Michel Meunier is currently offline Michel MeunierFriend
Messages: 2
Registered: August 2019
Junior Member
Hello
New in C compilation with Eclipse, I try to compile a C souce C named dcraw. I get an error.

collect2: error: ld returned 1 exit status
make: *** [makefile:32: DcRaw] Error 1

higher ld report begin with:

Invoking: Cross GCC Linker
gcc -o "DcRaw" ./src/dcraw.o
/bin/ld : ./src/dcraw.o : dans la fonction « ljpeg_idct » :
/home/michel/eclipse-workspace/DcRaw/Debug/../src/dcraw.c:1066 : référence indéfinie vers « cos »

but in the source I have::

#include <math.h>

It seems there is a problem in the link part.

Thanks for your help

Michel


Re: Try to compile C program [message #1810972 is a reply to message #1810847] Thu, 22 August 2019 19:53 Go to previous messageGo to next message
David VavraFriend
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

Re: Try to compile C program [message #1814340 is a reply to message #1810972] Mon, 09 September 2019 19:21 Go to previous messageGo to next message
Ross Gellie is currently offline Ross GellieFriend
Messages: 1
Registered: September 2019
Junior Member
It looks like you are pretty new with C language. However, if you are really serious about programming then I would suggest you to leave C and pursue Python language.
Re: Try to compile C program [message #1814341 is a reply to message #1814340] Mon, 09 September 2019 20:44 Go to previous message
Michel Meunier is currently offline Michel MeunierFriend
Messages: 2
Registered: August 2019
Junior Member
it's working now, I am a new user of Eclipse. When I programm, I use Rad Studio from Embarcadero in C++ and Pascal, I have nothing to adjust for the link.
For Python, NO, I don't find it a clean language, and also I want compiled languages.
Nevertheless, thanks for the help, now it's working.
Michel
Previous Topic:Feature request : Please add support lldb support for standard alone debugger, especially for Mac
Next Topic:Build Error with Helios
Goto Forum:
  


Current Time: Mon Nov 11 12:03:11 GMT 2024

Powered by FUDForum. Page generated in 0.04024 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top