How to re-solve 'multiple main definitions' error ?

V

vsk

Hai all,
I have written a parser in lex. I hope most of you know that lex, a
command line utility available in linux
will take .lex file as input and it will produce .c file as output. Now
i need to make this file as a library such that
it could be used in another c-file. Thing here is, .c file produced by
lex will have a 'main' function.I renamed the main function into an
other name say 'parse' and i converted this into a library. When i
tried to use this in another c-file, it gives me the erroe as multiple
mail definitions.
Can anyne help me in this regard ?.
Thanks in advance,
 
W

Walter Roberson

:I have written a parser in lex.

:i need to make this file as a library such that
:it could be used in another c-file. Thing here is, .c file produced by
:lex will have a 'main' function.

Do not put in a main() yourself, and do not link against the lex library
(usually -ll ) before putting the output object into a library.

Calling a lex output that has no main() is commonplace: it is the
normal way that one uses lex as the tokenizer for yacc. If you search
for examples of using yacc and lex together, then you should be able to get
a fair idea of what initialization you need to do and so on.
 
V

Vinod Patel

Hi VSK,
I suppose you are creating static library. Instead you can create a
shared library (.so) file. Link it dynamically with your program and
you will not find the "multiple main" error (even though you library
contains main).

Rgds,
Vinod Patel
 
V

vsk

Hai Vinod,
I have created shared library only. First , i got the .o file and
using that i created the shared library. I am in urgent need of this
solution.

Can anyone help me in this regard .?
Thanks,
Saravanakumar V
 
V

vsk

Hai Rober,
If i dont have any code except yylex () call in main , I need not
put main in my lex program. But i have done some input validation in
the main function , So main will be there. That is why , i just renamed
the main into another name and i tried.

Still i m trying to resolve the same problem. I am in urgent need of
this solution.
Any help in this regard will be greatful .

Thanks,
 
J

Jens.Toerring

vsk said:
If i dont have any code except yylex () call in main , I need not
put main in my lex program. But i have done some input validation in
the main function , So main will be there. That is why , i just renamed
the main into another name and i tried.
Still i m trying to resolve the same problem. I am in urgent need of
this solution.

Unless you put it in there yourself (or when the 'main' option is
used) the output of lex doesn't contain a main() function, so your
problem may have some other reasons. Why don't you just post your
code in a newsgroup where it would be more on-topic like for example
comp.unix.programmer? Giving only a very vague descriptions of what
you are doing won't help you much in getting useful answers...

Regards, Jens
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,189
Members
46,735
Latest member
HikmatRamazanov

Latest Threads

Top