Hi,

I'm still a beginner for C programming. In my assignment I've encountered this problem and I know is a linker problem but I'm not sure how to solve it. I'm trying to link 3 files which 2 .c files and 1 .h file. Below are the codes for my file:

/*File driver.c (main file)*/
#include <stdio.h>
#include "MDAnalysis.h"
#include "MDAnalysis.c"


int main()
{

printScreen();

return 0;

}
/*File MDAnalysis.c*/
#include <stdio.h>
#include "MDAnalysis.h"
#include <stdlib.h>


void printScreen(void)
{
printf("Help me");
}
/*File: MDAnalysis.h*/

#ifndef _MDAnalysis_h
#define _MDAnalysis_h

/*Function prototypes*/

void printScreen(void);

#endif

These 3 files are my codings. I hope someone can help me out. I'm stuck at his problem for long time. Thanks in advance. Appreciate your help.

I think you mean Ld returned 1 exit status.

Do you really mean you tried to link the 2 c files and the h file or do you mean you compiled the c files and tried to link the resulting objects?

The processor of building a program is

  • Compile each individual source (.c) file producing an object file (.o or .obj)
  • Link all the object files produced in stage 1 with any require libraries

NOTE 1: you neither compile or link header (.h) files, they are included into source (.c) files and the code the contain is compiled in that manner.

NOTE 2: It is very poor practice to #include source files (.c) into other source files (.c) as you have done in your driver.c listing. However if you must/do do that then you should not separately compile the source (.c) that you included.

Normally the IDE handles the build process for you so it would help us to know what tools, compiler tool-chain and/or IDE you are using.

Why don't you take the printScreen function out of MDAnalysis.c and move it into driver.c after the main function. It could fix your problem perhaps.

Just want to offer another perspective for you and for those who are haunted by bug message "[Error] Id returned 1 exist status ".

So here it is:

If you compile a C/C++ source file with no main function to execute,
there will definitely be a bug message saying: "[Error] Id returned 1 exist status".

In your case,
the bug reporting files are MDAnalysis.c (for it is a C source file with no main function)
but neither MDAnalysis.h (for it is not a C/C++ source file but a Header file)
nor driver.c (for it has main funcion to execute)

However,
please do remember,
when we just don't need main function in a C/C++ source file, it's totally fine to leave main function absent.
In such a case, bug message "[Error] Id returned 1 exist status" means nothing.

To sum up,
whenever you see "[Error] Id returned 1 exist status",
just ask yourself:
1. Is the compiled file a C/C++ source file?
2. Does the file have main function?
3. Do I deliberately leave main function absent for some reason?

If the answers are Yes, No, and Yes respectively,
which means
"Yes, it is a C/C++ source file.",
"No, it does not have main function.",
and "Yes, I do deliberately leave main function absent for some reason."
it will be 100% fine to ignore the bug message "[Error] Id returned 1 exist status".

Can someone help me to create an inventory, and then save purchases made from the inventory and print it out in a receipt. And also the receipt should be in a file

Comments
This should be in a new post. Avoid 5 year old discussions.
This article has been dead for over six months. Start a new discussion instead.