Find the answer to your Linux question:
Results 1 to 4 of 4
I have Ubuntu Linux. I have just writen programm in C by Eclipse C++ but it does not work in Linux. And it works in Windows. Code: #include <stdio.h> #include ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Nov 2010
    Posts
    8

    Smile C Problems in linux, In Eclipse C


    I have Ubuntu Linux. I have just writen programm in C by Eclipse C++ but it does not work in Linux. And it works in Windows.


    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    
    int main()
    {
    float a,b;
    a=49;
    b= sqrt(a);
    printf("%f", b);
    }
    There is error:

    Code:
    make all 
    Building target: Program_Name
    Invoking: GCC C Linker
    gcc  -o"Program_Nam"  ./src/Program_Nam.o   
    ./src/Program_Nam.o: In function `main':
    /home/koro/Documents/C/Program_Nam/Debug/../src/Program_Nam.c:17: undefined reference to `sqrt'
    collect2: ld returned 1 exit status
    make: *** [Program_Nam] Error 1

    I also make the same in Windows Dev C++ and there works. Linux have probblems with this code: b= sqrt(a);

    do you Know why and what can I do?



    Also I can run this proggram with terminal by gcc. For example:
    Code:
    gcc code.c -o  code
    ./code
    if I add "-lm" to this code program will work. For exaple:
    Code:
    gcc code.c -o  code -lm
    I wont to know why is imposible to run the program without -lm? why is -lm important? what is -lm and -o?

    And how can I run the program in Eclipse C++ in linux. Because Eclipse is more comfortable than Terminal and notepad. it's comportable like Dev C++.
    Last edited by vakhoQ; 11-03-2010 at 07:25 PM.

  2. #2
    Linux Enthusiast gerard4143's Avatar
    Join Date
    Dec 2007
    Location
    Canada, Prince Edward Island
    Posts
    714
    Using the -lm switch tells the compiler to include the math library.
    Make mine Arch Linux

  3. #3
    Just Joined!
    Join Date
    Nov 2010
    Posts
    8

    -o, -lm, math.h n' Eclipse C++

    1) And what is -o? why can't link my program to the math library? I have writen in the code #include <math.h>

    2) And how can I compile my program in Eclipse C++? The program automaticly debugs my code. I dont use Termingal here.

    Thanks a lot

  4. #4
    Linux Enthusiast gerard4143's Avatar
    Join Date
    Dec 2007
    Location
    Canada, Prince Edward Island
    Posts
    714
    Quote Originally Posted by vakhoQ View Post
    1) And what is -o? why can't link my program to the math library? I have writen in the code #include <math.h>

    2) And how can I compile my program in Eclipse C++? The program automaticly debugs my code. I dont use Termingal here.

    Thanks a lot
    The -o switch tells the compiler that the following name is the name of the executable...

    Including <math.h> is just pasting the contents of the math.h header file into the said file. Using the -lm informs the compiler to use the math 'library' for name/label resolution..

    Question two? I never used Eclipse C++ so I don't know...
    Make mine Arch Linux

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •