2014-09-24 3 views
2

내가/컴파일 리눅스에서 실행하려고 할 때 나는 내 프로그램이 컴파일 오류가납니다 .. 나도 몰라C 리눅스 오류 - conio.h와 : 해당 파일이나 디렉토리

program7.c:9:18: conio.h: No such file or directory 
make: *** [program7] Error 1 

Linux에서이 오류를 일으키는 기능은 무엇입니까? conio.h가 C 표준 라이브러리의 일부가 아닌 것에 대한 자세한 내용을 읽었습니다.

내 코드 : 나는 모두 함께 conio.h와 헤더를 제거하려고

#include<stdio.h> 
#include<conio.h> 
#include<math.h> 

int add(int a,int b); // declaration of add function              
int multiply(int a,int b); // Prototype of multiply function            
long int power(int num,int pow); // Prototype of power function            
int sumOfPowers(int z, int y); // Prototype of Sum of power function          
int calculateGcd(int x,int y); // Prototype of GCD function             

int main(){ 
     int num1,num2; 
     int sum,mul,total,gcd; 
     long int pow; 

     printf("Enter two positive integers, separated by a space, the first smaller than the second: "); 
    scanf("%d %d",&num1,&num2); 

     // Get Calculated sum from add function and assign to sum           
     sum = add(num1,num2); 
     printf("\nThe sum of %d to %d = %d\n",num1,num2,sum); // print sum output       

     // Get Calculated multiplication from multiply function and assign to mul       
     mul = multiply(num1,num2); 
     printf("\nThe product of %d to %d = %d\n",num1,num2,mul); // print multiply output     

     // Get power from power function and assign to pow             
     pow = power(num1,num2); 
     printf("\n%d to power of %d = %ld \n",num1,num2,pow); // print pow output       



     total = sumOfPowers(1,num2); 
     printf("\n The sum of powers of 2 from 1 to 2^%d = %d\n",num2,total); // print total output 
// Get gcd value from calculateGcd function and assign to gcd          
     gcd = calculateGcd(num1,num2); 
     printf("\nThe GCD of %d and %d = %d\n",num1,num2,gcd); // print pow output       

} 

// Add function to add two number                   
int add(int a,int b){ 
     if(b<=a){ 
       return; 
     } 
       while(b>=a){ 
       return b+add(a,b-1); 
       } 
} 

// Multiply function to multiply two number                 
int multiply(int a,int b){ 
     if(a>b){ 
       return; 
     } 
       while(a<b){ 
       return a*multiply(a+1,b); 
       } 
} 

// Powet function to calculate power of two numbers               

int i=1; 
long int cal=1; 
long int power(int num,int pow){ 
     if(i<=pow){ 
      cal=cal*num; 
      power(num,pow-1); 
     } 
     else 
     return cal; 
    } 

int calculateGcd(int x,int y){ 
    while (x != y) 
    { 
     if (x > y) 
     { 
      return calculateGcd(x - y, y); 
     } 
     else 
     { 
      return calculateGcd(x, y - x); 
     } 
    } 
    return x; 
} 

// Calculate the sum of powers from x to y                 
int total = 1; 
int sumOfPowers(int z, int y){ 
     int new; 

     while(z<=y){ 
     new = pow(2,z); 
     total = total + new; 
     z++; 
     } 

     return total; 
} 

편집 할 수 있습니다.

Undefined      first referenced 
symbol        in file 
pow         /var/tmp//cc6jlZ6f.o 
ld: fatal: Symbol referencing errors. No output written to program7 
collect2: ld returned 1 exit status 
make: *** [program7] Error 1 

내 메이크 :

program7: program7.c 
     gcc -o program7 program7.c 

답변

3

conio.h 실제로 표준 C 헤더 아닙니다 그러나 나는 다음과 같은 오류가 발생했습니다. 나는 당신이 그것을 필요로한다고 생각하지 않습니다. 그냥 제거하십시오.

또한 pow()과 같은 함수를 사용하려면 표준 수학 라이브러리를 연결해야합니다. 컴파일러 명령 줄에 -lm을 추가하십시오 (예, libm이라고 함).

+0

안녕하세요 Matti, 실제로 모두 함께 conio.h 헤더를 제거하고 다음과 같은 오류가 발생했습니다 (원래 게시물 편집) –

관련 문제