Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hi all, i wrote one code like th

Status
Not open for further replies.

amarg

Programmer
Nov 19, 2002
106
IN
Hi all,

i wrote one code like this

File1.c

_____________________________________________

void f1() {
printf("From f1()\n");
}

int main() {
printf("Frim main() File1.c\n");
f1();
f2();
}
_____________________________________________


File2.c

_____________________________________________

void f2() {
printf("From f1()\n");
}

int main() {
printf("Frim main() File2.c\n");
f1();
f2();
}
_____________________________________________


As you can guess at the time of compilation i am getting
the error main muliple define.

Is it any way to add some directive in the code to make
two different exe, one from file1 and one from file2.

I don't want to change the code for each compilation.


Regards,
Amar
 

File1.c

_____________________________________________

void f1() {
printf("From f1()\n");
}

#ifdef _USE_FILE1_MAIN_

int main() {
printf("Frim main() File1.c\n");
f1();
f2();
}

#endif
_____________________________________________


File2.c

_____________________________________________

void f2() {
printf("From f1()\n");
}

#ifndef _USE_FILE1_MAIN_
int main() {
printf("Frim main() File2.c\n");
f1();
f2();
}
#endif
_____________________________________________



and compile with -D directive.

Say you want to use the file1 main for exe,
gcc -D_USE_FILE1_MAIN_ in your make file.
If you want to use the other one dont use
-D_USE_FILE1_MAIN_


Hope this helps
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top