473,770 Members | 4,544 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

undefined symbol yylex

Hello,
Please excuse me as Iam not posting this to correct group. I
have a parser code obtained from flex command. I have many other files.
When I compile them Iam getting a message like: undefined symbol yylex.
What might have went wrong?

Jul 14 '06 #1
8 18051
pa******@gmail. com wrote:
Hello,
Please excuse me as Iam not posting this to correct group. I
have a parser code obtained from flex command. I have many other files.
When I compile them Iam getting a message like: undefined symbol yylex.
What might have went wrong?
Two things to check spring to mind:
- Ensure that you are incorporating the generated lex.yy.c file into
your build
- If you are invoking yylex from a C++ file, make sure you use extern
"C" when declaring it.
You'll probably also get a link error for a missing yywrap. If so write
a simple C file with this in it:
int yywrap()
{ return 1; }

HTH.

Jul 14 '06 #2
<pa******@gmail .comwrote in message news:11******** **************@ m73g2000cwd.goo glegroups.com.. .
Hello,
Please excuse me as Iam not posting this to correct group. I
have a parser code obtained from flex command. I have many other files.
When I compile them Iam getting a message like: undefined symbol yylex.
What might have went wrong?
Compilers don't give error messages like that. That's a linker
error. Your files all compiled fine, but the linker couldn't
find something to link symbol yylex to. This can occur if you
list the flex library on the gcc command line, even if you're
not actually using flex in program. One thing that can cause
that is, you tell gcc to compile and link a bunch of modules
to an executable, but forget to include the module with main().

For example, when I try to make an exe file out of a blank cpp
file, like so:

// Begin blank.cpp
// (no content)
// End blank.cpp

gpp blank.cpp -lfl -o blank.exe

Error: in function "_main": libmain.c:11: Undefined reference
to symbol "_yylex". Collect2: ld returned 1 exit status.

What happened is, gcc sees that you mentioned the flex library,
so it assumes you want main() generated for you, and a reference
in main to a (non-existant) yylex funtion. Since you never
provided an actual flex file, there IS NO SUCH FUNCTION. So,
you get that error.

So, look to make sure you actually do have a main() function.
More generally, look for files you may have forgotten to include
in the build.

--
Cheers,
Robbie Hatley
East Tustin, CA, USA
lone wolf intj at pac bell dot net
(put "[usenet]" in subject to bypass spam filter)
http://home.pacbell.net/earnur/
Jul 14 '06 #3
Thank you very much. I now used extern "C" and I got rid of the error.
tragomaskhalos wrote:
pa******@gmail. com wrote:
Hello,
Please excuse me as Iam not posting this to correct group. I
have a parser code obtained from flex command. I have many other files.
When I compile them Iam getting a message like: undefined symbol yylex.
What might have went wrong?

Two things to check spring to mind:
- Ensure that you are incorporating the generated lex.yy.c file into
your build
- If you are invoking yylex from a C++ file, make sure you use extern
"C" when declaring it.
You'll probably also get a link error for a missing yywrap. If so write
a simple C file with this in it:
int yywrap()
{ return 1; }

HTH.
Jul 14 '06 #4
Thank you for your kind information. I came to knew much about flex.
Robbie Hatley wrote:
<pa******@gmail .comwrote in message news:11******** **************@ m73g2000cwd.goo glegroups.com.. .
Hello,
Please excuse me as Iam not posting this to correct group. I
have a parser code obtained from flex command. I have many other files.
When I compile them Iam getting a message like: undefined symbol yylex.
What might have went wrong?

Compilers don't give error messages like that. That's a linker
error. Your files all compiled fine, but the linker couldn't
find something to link symbol yylex to. This can occur if you
list the flex library on the gcc command line, even if you're
not actually using flex in program. One thing that can cause
that is, you tell gcc to compile and link a bunch of modules
to an executable, but forget to include the module with main().

For example, when I try to make an exe file out of a blank cpp
file, like so:

// Begin blank.cpp
// (no content)
// End blank.cpp

gpp blank.cpp -lfl -o blank.exe

Error: in function "_main": libmain.c:11: Undefined reference
to symbol "_yylex". Collect2: ld returned 1 exit status.

What happened is, gcc sees that you mentioned the flex library,
so it assumes you want main() generated for you, and a reference
in main to a (non-existant) yylex funtion. Since you never
provided an actual flex file, there IS NO SUCH FUNCTION. So,
you get that error.

So, look to make sure you actually do have a main() function.
More generally, look for files you may have forgotten to include
in the build.

--
Cheers,
Robbie Hatley
East Tustin, CA, USA
lone wolf intj at pac bell dot net
(put "[usenet]" in subject to bypass spam filter)
http://home.pacbell.net/earnur/
Jul 14 '06 #5
What is the significance of using extern "C". What makes using it to
avoid link error

tragomaskhalos wrote:
pa******@gmail. com wrote:
Hello,
Please excuse me as Iam not posting this to correct group. I
have a parser code obtained from flex command. I have many other files.
When I compile them Iam getting a message like: undefined symbol yylex.
What might have went wrong?

Two things to check spring to mind:
- Ensure that you are incorporating the generated lex.yy.c file into
your build
- If you are invoking yylex from a C++ file, make sure you use extern
"C" when declaring it.
You'll probably also get a link error for a missing yywrap. If so write
a simple C file with this in it:
int yywrap()
{ return 1; }

HTH.
Jul 14 '06 #6

pa******@gmail. com wrote:
What is the significance of using extern "C". What makes using it to
avoid link error
Basically whenever you call C functions from C++ you must declare them
as extern "C".
Easiest explanation is to first Google for "C++ name mangling" and read
up on that. Now, using extern "C" tells the compiler that the symbols
in question (in this case yylex) come from C and have therefore not
been mangled. I think there may be other ramifications to do with
calling conventions but that's the gist of it.

Jul 14 '06 #7

"Robbie Hatley" <bo***********@ no.spamwrote in message
news:xF******** ***********@new ssvr12.news.pro digy.com...
<pa******@gmail .comwrote in message
news:11******** **************@ m73g2000cwd.goo glegroups.com.. .
>Hello,
Please excuse me as Iam not posting this to correct group. I
have a parser code obtained from flex command. I have many other files.
When I compile them Iam getting a message like: undefined symbol yylex.
What might have went wrong?

Compilers don't give error messages like that. That's a linker
error. Your files all compiled fine, but the linker couldn't
find something to link symbol yylex to. This can occur if you
list the flex library on the gcc command line, even if you're
not actually using flex in program. One thing that can cause
that is, you tell gcc to compile and link a bunch of modules
to an executable, but forget to include the module with main().

For example, when I try to make an exe file out of a blank cpp
file, like so:

// Begin blank.cpp
// (no content)
// End blank.cpp

gpp blank.cpp -lfl -o blank.exe

Error: in function "_main": libmain.c:11: Undefined reference
to symbol "_yylex". Collect2: ld returned 1 exit status.

What happened is, gcc sees that you mentioned the flex library,
so it assumes you want main() generated for you, and a reference
in main to a (non-existant) yylex funtion. Since you never
provided an actual flex file, there IS NO SUCH FUNCTION. So,
you get that error.

So, look to make sure you actually do have a main() function.
More generally, look for files you may have forgotten to include
in the build.
You've shown an "undefined reference" error, which is indeed a linker error.
But compilers do issue "undefined symbol" errors, which is what the OP said
it was. They occur when the symbol (such as a variable name) hasn't been
declared in the current scope. Different compilers may describe that
differently ("undeclared ", "undefined" , "unknown", whatever), of course, but
they do occur.

You may be right that it was a linker error, but from the original post,
there's no way to be sure of that (without some prior knowledge of that lex
stuff). Which is just another reason why posters should include the text of
the error message, and if it's a compile error, then the line(s) of code
referred to as well.

-Howard


Jul 14 '06 #8
pa******@gmail. com wrote:
Thank you for your kind information. I came to knew much about flex.
Robbie Hatley wrote:


Please don't top-post. Your replies belong following or interspersed
with properly trimmed quotes. See the newsgroup FAQ:
<http://www.parashift.c om/c++-faq-lite/how-to-post.html#faq-5.4>


Brian
Jul 14 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1770
by: pervinder | last post by:
Hi, I have a c++ application which depends on some other libs which uses stlport When i build the application, it works fine on sun/linux/hp platform. (provided the .a for the dependency libs) But it errors out on AIX ( xlC va6) with below errors:- ld: 0711-317 ERROR: Undefined symbol: ._STL::ios_base::_Loc_init::_Loc_init() ld: 0711-317 ERROR: Undefined symbol: ._STL::ios_base::Init::Init() ld: 0711-317 ERROR: Undefined symbol:...
0
1688
by: John Graat | last post by:
Hi all, I've built the STLport-462 library on AIX-4.3.3 using gcc-3.3.2. No errors during compilation. However, during linking the following error occurs: ld: 0711-317 ERROR: Undefined symbol: _STL::_Node_Alloc_Lock<(bool)1, (int)0>::_S_lock Besides this error, the following warnings are given: ld: 0711-224 WARNING: Duplicate symbol: _STL::money_get<char,
10
8058
by: eugene | last post by:
I'm trying to compile and run some c++ code to be called from Matlab (mex file) and I'm getting "Invalid MEX-file ... undefined symbol" error. Anybody knows where to look for solution? >>mex -v abc.cpp //that's how you "make" in Matlab, and that's what was called: -> g++ -c ... abc.cpp -> gcc -c ... /usr/local/matlab701/extern/src/mexversion.c
4
5731
by: r.nikhilk | last post by:
Hi, We are porting C++ applications from 32 bit to 64 bit on AIX platform. (The current version of AIX is 5.3 and xlC verison is 8.0). We are able to compile the applications by including the -q64 option in xlC compiler. But, when we link all these libraries to one of the main applications, we are getting the following errors: ld: 0711-317 ERROR: Undefined symbol: .FxCharFile::good() const ld: 0711-317 ERROR: Undefined symbol:...
3
19314
by: Kenneth Kahl | last post by:
Hello, I would like to call a C++ programm out of Java with help of JNI. By the followed command I created a "shared library": g++ -shared -o libcalculate.so rechner.cpp When I create an object from the existing program inside a method of my class rechner.cpp, and then call the method out of java, a following
1
5548
by: yamitmehta | last post by:
When I compile to code using g++arm of VxWorks 5.5 and put it on my board i get the follwing undefined symbols:- Cpool and Csingleton are template classes. CPool has the static member variables:-ms_uCapacity ,ms_uAllocatedCount , ms_uLockCapacity ,ms_pmutex -ld < yamit/apps1.out Undefined symbol: _Q23m5tt5CPool1ZQ23m5t10CMarshaler$ms_uCapacity (binding 1 type 0) Undefined symbol: _Q23m5tt5CPool1ZQ23m5t10CMarshaler$ms_uAllocatedCount
1
4912
by: Justin Johnson | last post by:
Hello, I'm trying to build Python 2.5.0 on AIX 5.3 using IBM's compiler (VisualAge C++ Professional / C for AIX Compiler, Version 6). I run configure and make, but makes fails with undefined symbols. See the output from configure and make below. svnadm /svn/build/python-2.5.0>env CC=cc CXX=xlC ./configure --prefix=$base_dir \ checking MACHDEP... aix5
3
5344
by: sdeathstar | last post by:
I am working on IBM AIX machine and using XLC C++ complier version 8.0. 1) Able to compile the objects on AIX from C and C++ source code. 2) Able to create the libraries (combination of C & C++, Proc*C objects) 3) Finally trying to create a run time executable, it's not recognizing the libraries created at step 2. Basically linking user defined libraries is an issue /risk/riskdev/risk_src/cpp/CurveSimu/src > make mainCrvSimu ...
1
6061
by: Michel Esber | last post by:
People, Environment: Linux AS4 I have just installed db2 v9.5 + Fixpak 2 on a machine that has db2 v8 up and running, but I am unable to create and instance: # ./db2icrt -a SERVER -p 50002 -s wse - u db2inst2 db2inst2 /opt/ibm/db2/V9.5/bin/db2greg: symbol lookup error: /opt/ibm/db2/V9.5/
0
9591
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9425
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10228
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10002
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7415
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6676
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5312
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3970
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2816
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.