CocoaDev

Edit AllPages

I’m trying to include lex.yy.c (generated by “flex”) into a Cocoa Foundation Tool Project. I get the following compile errors:

ld: multiple definitions of symbol _yy_create_buffer ld: multiple definitions of symbol _yy_delete_buffer ld: multiple definitions of symbol _yy_flush_buffer ld: multiple definitions of symbol _yy_init_buffer ld: multiple definitions of symbol _yy_load_buffer_state ld: multiple definitions of symbol _yy_scan_buffer ld: multiple definitions of symbol _yy_scan_bytes ld: multiple definitions of symbol _yy_scan_string ld: multiple definitions of symbol _yy_switch_to_buffer

Is this a problem with the source file that flex is outputing or is this a problem with how gcc is setup to build the project? In the first ld error, “_yy_creeate_buffer” is not defined in lex.yy.c.

Any ideas? –zootbobbalu

Hard to say without seeing the project. What flags are you passing to cc? – KritTer


I took this off of the Discussion page because I figured I needed to read up on the subject. Thanks for your reply KritTer. I wasn’t asking for help anymore.

All I want to do is call the scanner function “yylex()” that is generated by lex inside an Objective C method implementation. To compile the lex.yy.c file by itself from the terminal is as simple as typing “cc lex.yy.c -o myScanner”.

I’m not sure how to get the “yylex()” function to link with an Objective C object. I tried to add the -ll flag, but I really don’t know exactly how to mix C code with Objective C code.

here’s the simple lex file I used to generate the lex.yy.c file

%% /* match everything except newline / . ECHO; \n ECHO; / match newline */ %% int yywrap(void) { return 1; } int main(void) { yylex(); }

After lex generates lex.yy.c, I have to delete the main function so it doesn’t clash with the main function of the Foundation Tool.

I know this isn’t much of a scanner. I just want to include the function “yylex()” inside an Objective C Class. –zootbobbalu

C code is ObjC code. Incidentally, if you don’t want the main function, why have you written one in the lex file? Anyway, good luck. – KritTer


I got it to work by adding the linker flag “-lfl”.

–zootbobbalu

Oh. Yeah, I could have told you that :) – KritTer