compiler error

This is a discussion on compiler error within the C Programming forums, part of the General Programming Boards category; Unresolved: sqrt floor collect2: ld returned 1 exit status included math.h Code: gpf = floor(sqrt(y));...

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    17

    compiler error

    Unresolved:
    sqrt
    floor
    collect2: ld returned 1 exit status

    included math.h
    Code:
    gpf = floor(sqrt(y));

  2. #2
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    code might help.

  3. #3
    Registered User
    Join Date
    Feb 2003
    Posts
    17

    snippet of prime factor

    Code:
    int PrimeFactor()
    {
      int y;
      int fact;
      int r,i;
      int num1, num2, gpf, Prime;
      y=GetNum(num1);
      
    		{
    			Prime == 1;
    	        gpf = floor(sqrt(y));
                for(fact=2; fact <= gpf; fact++)
    			{
                while( y % fact == 0)
    				{
                    if(Prime==1)
                        {
                        printf("%d = %d", y, fact);
                        Prime == 0;
    				}
                    else
    				{
    				printf(" * %d", fact);
    				y = y/fact;				}
    
    				if(Prime == 0)
    				{
    			printf("%d is a prime number.", y);
    				}
                else 
    					if(y!=1)
    					{					printf(" * %d", y);
    				printf("\n\n");
    					 }
    			else
    			{
    	printf("The Prime Factors for this number are\n");
    				printf("%d = ", y);
    			}
    				for (i=2; i <=y; i++)
    				{
    				while( y % i == 0)
    					{
    					 y = y / i;
    		
    					}	  				printf(" * %d",i);
    				}
    				
    				
    			}
    			}
    		printf("\n\n");	
    		}	
    	}

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Have you tried linking with your math library?
    What compiler are you using?
    Maybe you need to add -lm when you compile
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  5. #5
    Registered User
    Join Date
    Feb 2003
    Posts
    17
    using gcc complier in unix

  6. #6
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    So, did you try
    gcc myprog.c -lm
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  7. #7
    Registered User
    Join Date
    Feb 2003
    Posts
    17
    just needed to compile wiht -lm thanx

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how do you resolve this error?
    By -EquinoX- in forum C Programming
    Replies: 32
    Last Post: 11-05-2008, 03:35 PM
  2. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  3. error: template with C linkage
    By michaels-r in forum C++ Programming
    Replies: 3
    Last Post: 05-17-2006, 08:11 AM
  4. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 09:43 AM
  5. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM

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