0

I tried compiling my program named 1-print_rev_recursion.c using this command gcc -o 1-print_rev_recursion.c recursion.o

#include "main.h"
#include "main.c"
/**
  * _print_rev_recursion - Print a string in reverse
  * @s: the string to reverse
  *
  * Return: void.
  */
void _print_rev_recursion(char *s)
{
        if (*s == '\0')
        {
                return;
        }

        s++;
        _print_rev_recursion(s);
        s--;
        _putchar(*s);
}

Here's my file main.c

#include <unistd.h>                                                                                                     
#include "main.h"                                                                                                                                                                                                                               
/**                                                                                                                      
 * _putchar - writes the character c to stdout                                                                        
 * @c: The character to print                                                                                        
 *                                                                                                                 
 * Return: On success 1.                                                                                           
 * On error, -1 is returned, and errno is set appropriately.                                                      
 */                                                                                                             
int _putchar(char c)                                                                                                    
{                                                                                                                                       
     return (write(1, &c, 1));                                                                               
} 

And my header file main.h

#ifdef MAIN_H                                                                                                                       
#define MAIN_H                                                                                                                                                                                                                                  
int _putchar(char);                                                                                                     
void _puts_recursion(char *s);                                                                                          
void _print_rev_recursion(char *s);                                                                                     
int _strlen_recursion(char *s);                                                                                         
int factorial(int n);                                                                                                   
int _pow_recursion(int x, int y);                                                                                       
int _sqrt_recursion(int n);                                                                                             
int is_prime_number(int n);                                                                                             
int is_palindrome(char *s);                                                                                             
int wildcmp(char *s1, char *s2);                                                                                        
#endif 

But I got this error

/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o: in function `_start': (.text+0x24): undefined reference to `main' collect2: error: ld returned 1 exit status

  • It looks like you don't have the entry point function `main()`. Use `-c` option to do compile only (no linking to executable). Also note that using `.c` file for `#include` looks unusual. – MikeCAT Jul 22 '22 at 22:21
  • @MikeCAT I must say that I'm a bit confused about this question. It's like, anyone who would write code like this would also know what the problem is. – klutt Jul 22 '22 at 22:29

0 Answers0