mkido
asked on
Unseccessful Header file (.h) creation, what's wrong?
I wrote a Program (pro87.c), it works fine. Then I separated it into two files as a Header (pro86.h) and a Program (pro86.c). It turned error during making. Compiler said "Linker Error: Undifined symbol _main in module c0.ASM. What's wrong. It's exactly the same except as two files.
Here is as a single file. It's O.K.
/*PROGRAM pro87.c */
/* DataBase type determination */
#include<stdio.h>
#include<string.h>
#define UNKNOWN 1 //"Unknown" /* Data format type */
#define GENBANK 2 //"GenBank"
#define EMBL 3 //"EMBL"
#define PIR 4 //"PIR"
#define PRF 5 //"PRF"
#define SEQDATA 6 //"SeqData"
#define BUFLEN 256 /* maximum length of buffer for string */
char linebuf[BUFLEN];
main(int argc, char *argv[])
{
int dataType;
FILE *fp;
if(argc!=2)
printf("Usage : pro86 filename\n");
else
fp=fopen(argv[1], "r");
dataType=0;
while(fgets(linebuf, BUFLEN, fp)!=NULL)
{
if (strncmp(linebuf, "LOCUS", 5)==0){
dataType = GENBANK; break;
}else if (strncmp(linebuf, "ID ", 3)==0){
dataType = EMBL; break;
}else if (strncmp(linebuf, "ENTRY", 5)==0){
dataType = PIR; break;
}else if (strncmp(linebuf, "CODE", 4)==0){
dataType = PRF; break;
}else if (linebuf[0] == '>'){
dataType = SEQDATA; break;
}else
dataType = UNKNOWN;
}
if(dataType==1)
printf("Unknown\n");
if(dataType==2)
printf("GenBank\n");
if(dataType==3)
printf("EMBL\n");
if(dataType==4)
printf("PIR\n");
if(dataType==5)
printf("PRF\n");
if(dataType==6)
printf("SeqData\n");
fclose(fp);
return 0;
}
__________________________ __________ __________ _________
The above is OK, now separate it to two files.
/* pro86.H ; This is a header file. */
/* Data format type */
#define UNKNOWN 1 //"Unknown"
#define GENBANK 2 //"GenBank"
#define EMBL 3 //"EMBL"
#define PIR 4 //"PIR"
#define PRF 5 //"PRF"
#define SEQDATA 6 //"SeqData"
__________________________ __________ ___
AND
/* PROGRAM Pro86.c */
/* DataBase type determination */
#include<stdio.h>
#include<string.h>
#include<pro86.h>
#define BUFLEN 256 /* maximum length of buffer*/
char linebuf[BUFLEN];
main(int argc, char *argv[])
{
int dataType;
FILE *fp;
if(argc!=2)
printf("Usage : pro86 filename\n");
else
fp=fopen(argv[1], "r");
dataType=0;
while(fgets(linebuf, BUFLEN, fp)!=NULL)
{
if (strncmp(linebuf, "LOCUS", 5)==0){
dataType = GENBANK; break;
}else if (strncmp(linebuf, "ID ", 3)==0){
dataType = EMBL; break;
}else if (strncmp(linebuf, "ENTRY", 5)==0){
dataType = PIR; break;
}else if (strncmp(linebuf, "CODE", 4)==0){
dataType = PRF; break;
}else if (linebuf[0] == '>'){
dataType = SEQDATA; break;
}else
dataType = UNKNOWN;
}
if(dataType==1)
printf("Unknown\n");
if(dataType==2)
printf("GenBank\n");
if(dataType==3)
printf("EMBL\n");
if(dataType==4)
printf("PIR\n");
if(dataType==5)
printf("PRF\n");
if(dataType==6)
printf("SeqData\n");
fclose(fp);
return 0;
}
__________________________ __________ ______
These don't compile. Linker Error!! Help me.
Here is as a single file. It's O.K.
/*PROGRAM pro87.c */
/* DataBase type determination */
#include<stdio.h>
#include<string.h>
#define UNKNOWN 1 //"Unknown" /* Data format type */
#define GENBANK 2 //"GenBank"
#define EMBL 3 //"EMBL"
#define PIR 4 //"PIR"
#define PRF 5 //"PRF"
#define SEQDATA 6 //"SeqData"
#define BUFLEN 256 /* maximum length of buffer for string */
char linebuf[BUFLEN];
main(int argc, char *argv[])
{
int dataType;
FILE *fp;
if(argc!=2)
printf("Usage : pro86 filename\n");
else
fp=fopen(argv[1], "r");
dataType=0;
while(fgets(linebuf, BUFLEN, fp)!=NULL)
{
if (strncmp(linebuf, "LOCUS", 5)==0){
dataType = GENBANK; break;
}else if (strncmp(linebuf, "ID ", 3)==0){
dataType = EMBL; break;
}else if (strncmp(linebuf, "ENTRY", 5)==0){
dataType = PIR; break;
}else if (strncmp(linebuf, "CODE", 4)==0){
dataType = PRF; break;
}else if (linebuf[0] == '>'){
dataType = SEQDATA; break;
}else
dataType = UNKNOWN;
}
if(dataType==1)
printf("Unknown\n");
if(dataType==2)
printf("GenBank\n");
if(dataType==3)
printf("EMBL\n");
if(dataType==4)
printf("PIR\n");
if(dataType==5)
printf("PRF\n");
if(dataType==6)
printf("SeqData\n");
fclose(fp);
return 0;
}
__________________________
The above is OK, now separate it to two files.
/* pro86.H ; This is a header file. */
/* Data format type */
#define UNKNOWN 1 //"Unknown"
#define GENBANK 2 //"GenBank"
#define EMBL 3 //"EMBL"
#define PIR 4 //"PIR"
#define PRF 5 //"PRF"
#define SEQDATA 6 //"SeqData"
__________________________
AND
/* PROGRAM Pro86.c */
/* DataBase type determination */
#include<stdio.h>
#include<string.h>
#include<pro86.h>
#define BUFLEN 256 /* maximum length of buffer*/
char linebuf[BUFLEN];
main(int argc, char *argv[])
{
int dataType;
FILE *fp;
if(argc!=2)
printf("Usage : pro86 filename\n");
else
fp=fopen(argv[1], "r");
dataType=0;
while(fgets(linebuf, BUFLEN, fp)!=NULL)
{
if (strncmp(linebuf, "LOCUS", 5)==0){
dataType = GENBANK; break;
}else if (strncmp(linebuf, "ID ", 3)==0){
dataType = EMBL; break;
}else if (strncmp(linebuf, "ENTRY", 5)==0){
dataType = PIR; break;
}else if (strncmp(linebuf, "CODE", 4)==0){
dataType = PRF; break;
}else if (linebuf[0] == '>'){
dataType = SEQDATA; break;
}else
dataType = UNKNOWN;
}
if(dataType==1)
printf("Unknown\n");
if(dataType==2)
printf("GenBank\n");
if(dataType==3)
printf("EMBL\n");
if(dataType==4)
printf("PIR\n");
if(dataType==5)
printf("PRF\n");
if(dataType==6)
printf("SeqData\n");
fclose(fp);
return 0;
}
__________________________
These don't compile. Linker Error!! Help me.
Other than that, it looks fine. I am not sure why it would be saying main is undefined...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you, all.
I got compilation by deleting header file from the project.
Thanks.
I got compilation by deleting header file from the project.
Thanks.
#include<pro86.h>
should be
#include "pro86.h"