Thread: error: ld returned 1 exit status

  1. #1
    Registered User
    Join Date
    Oct 2022
    Posts
    99

    error: ld returned 1 exit status

    why code show error
    error: ld returned 1 exit status

    Code:
    #include <stdio.h>
    
    void myFunction() {
        #ifdef DEBUG
            printf("Debugging mode is on.\n");
        #endif
        
    }
    
    
    int main() {
        myFunction();
        return 0;
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,675
    Maybe post your actual linker error message, because there's nothing obvious from the code so far.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Oct 2022
    Posts
    99
    Quote Originally Posted by Salem View Post
    Maybe post your actual linker error message, because there's nothing obvious from the code so far.
    This is a simple C program that defines a function myFunction() and calls it from main(). The function myFunction() contains a preprocessordirective #ifdef that checksif the DEBUG macro has beendefined. If it has, the function prints the message "Debugging mode ison." to the console using printf(). . If it is not defined, the message will not be printed.



    Code:
     #define DEBUG#include <stdio.h>
    
    
    void myFunction() {
        #ifdef DEBUG
            printf("Debugging mode is on.\n");
        #endif
    }
    
    
    int main() {
        myFunction();
        return 0;
    }
    I don't understand what would be benefit of checking define macro

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,675
    And what exactly does that have to do with linker error messages.

    It's a completely different question.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Oct 2022
    Posts
    99
    Quote Originally Posted by Salem View Post
    And what exactly does that have to do with linker error messages.

    It's a completely different question.
    I don't know exact problem but if I am currently compile and run I don't get any error

    My main question was what would be benefit of checking define macro as shown in code ?

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,675
    > My main question was what would be benefit of checking define macro as shown in code ?
    The code you compile for yourself:
    gcc -DDEBUG prog.c
    It contains diagnostic information that you find useful for general debugging and knowing that things are as they should be.

    You wouldn't have "#define DEBUG" in the code, you'd control it from the command line as shown.

    The code you compile to give to other people:
    gcc -O2 prog.c
    End users don't care about what you see, they just want a program that does what it says.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. error: ld returned 1 exit status
    By abhi143 in forum C++ Programming
    Replies: 2
    Last Post: 10-31-2019, 12:06 AM
  2. error: Id returned 5 exit status
    By Quang-vip in forum C++ Programming
    Replies: 5
    Last Post: 05-23-2018, 04:08 AM
  3. error: ld returned 1 exit status
    By vead in forum C Programming
    Replies: 6
    Last Post: 01-19-2018, 11:38 AM
  4. [Error] Id returned 1 exit status
    By iyilikpenisi in forum C Programming
    Replies: 6
    Last Post: 09-16-2016, 02:28 PM
  5. collect2: ld returned 1 exit status error??
    By blindchicken11 in forum C Programming
    Replies: 11
    Last Post: 11-07-2011, 08:38 PM

Tags for this Thread