GCC Compile Problem (link)

This is a discussion on GCC Compile Problem (link) within the C Programming forums, part of the General Programming Boards category; Hi all, Really to say I'm not very familar with C and esspecially with C in linux-based systems, bcz. have ...

  1. #1
    Registered User
    Join Date
    Dec 2011
    Posts
    3

    GCC Compile Problem (link)

    Hi all,
    Really to say I'm not very familar with C and esspecially with C in linux-based systems, bcz. have spent 6 years in C# programming. But now, I'm back to C . So I need your experience help.

    Here is the problem: I cannot compile the C project (DiskSim) because recieve the following error: "undefined reference to `sqrt'"
    But the main problem is that in makefile THERE IS link flag -lm to math.h

    Any ideas?

    My system:
    ubuntu 11.10 x64
    gcc, g++ 4.6
    flex, bison 2.5
    KDevelop as IDE

    I have attached the error log file, the makefile. (let me know if you need the whole project - but it is about 5 Mb)

    Thanks a lot for any help.
    Best,
    Timbuktu
    Attached Files Attached Files
    Last edited by Timbuktu; 12-07-2011 at 12:16 PM.

  2. #2
    Registered User TheBigH's Avatar
    Join Date
    May 2010
    Location
    Melbourne, Australia
    Posts
    426
    You need to link the mathematics library. Make sure you're including <math.h>, and that you compile thusly:

    Code:
    gcc -o myprog myprog.c -lm
    Code:
    while(!asleep) {
       sheep++;
    }

  3. #3
    Registered User
    Join Date
    Mar 2011
    Posts
    546
    the GNU linker doesn't do multiple passes until you tell it to. and since you linked your library mems_internals after -lm, the linker did not pull the math functions. look in the gnu linker documentation for --startgroup/--endgroup OR maybe you can just put -lm after your library.

  4. #4
    Registered User
    Join Date
    Dec 2011
    Posts
    3
    Thanks all for the replay,

    both is already done, but with no effect

    <math.h> is in the .c file
    -lm after the library also take nothing

    Another tipp?

  5. #5
    Registered User
    Join Date
    Sep 2008
    Posts
    200
    Quote Originally Posted by Timbuktu View Post
    <math.h> is in the .c file
    -lm after the library also take nothing
    Do you mean it's at the end of the line:

    Code:
    $(CC) -o $@ mems_seektest.o $(LDFLAGS) $(CFLAGS) -lmems_internals
    Because it'll need to be if libmems_internals relies on libm.

    Otherwise, please post the command-line make ends up issuing.

  6. #6
    Registered User
    Join Date
    Dec 2011
    Posts
    3
    Not sure I correct understand you.

    I have just put the -lm at the end of the line. The result is 100% the same.

    So look this line now:

    $(CC) -o $@ mems_seektest.o $(CFLAGS) -lmems_internals $(LDFLAGS)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to compile and link koolplot?
    By angela3017 in forum Linux Programming
    Replies: 4
    Last Post: 02-18-2011, 12:00 AM
  2. Compile and Link tutorials
    By tapti in forum C Programming
    Replies: 12
    Last Post: 08-04-2009, 03:23 AM
  3. Pimpl Idiom client/serve compile/link
    By George2 in forum C++ Programming
    Replies: 12
    Last Post: 03-15-2008, 06:25 AM
  4. Compile/Link errors...
    By Xenent in forum Game Programming
    Replies: 2
    Last Post: 10-23-2002, 05:39 PM
  5. Compile/Link errors...
    By Xenent in forum C++ Programming
    Replies: 2
    Last Post: 10-21-2002, 04:13 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21