473,399 Members | 2,774 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Problem using static library

Hi, I'm having trouble executing the following line of code:
Tokeniser tokeniser(cin);

The compiler complains thats i have a undefined reference to Tokeniser::Tokeniser(std::basic_istream(char, std::char_traits(char))&)

The line Test tester(cin) works as since it was written by myself.
However, whenever i try executing Tokeniser tokeniser(cin) i get the compilation error.

I am given Tokeniser.h with various other header files and a libparser.a as part of the assignment

My makefile includes:
//START OF MAKE FILE

HEADER_PATH = ass3/parser/
LIB_PATH = ass3/parser/
LIB_NAME = parser

search.exe: main.o test.o
g++ -g -Wall -o search.exe main.o test.o -L$(LIB_PATH) -l$(LIB_NAME) -static
rm main.o
rm test.o

main.o: main.cc
g++ -c -O -Wall -I$(HEADER_PATH) main.cc

test.o: test.cc
g++ -c -O -Wall test.cc
// END OF MAKEFILE

//main.cc start
#include <iostream>
#include "Tokeniser.h"
#include "Test.h"

using namespace std;

int main(){
//Test tester(cin); //this line works
Tokeniser tokeniser(cin);
return 0;
}
//main.cc end

//parts of tokeniser header file given
class Tokeniser {
// Since our queries are short, internally the Tokeniser pretokenises
// the whole stream. In other situations this may not be wise.
std::vector<std::string> tokens;
std::vector<std::string>::iterator tokenIndex;
public:
// This is not a Singleton because each tokeniser wraps an istream
// and must have its own state: the number of tokens consumed so far
Tokeniser(std::istream&);

// Routines to peek ahead at and extract tokens
std::pair<Token, std::string> lookahead(bool phrase = false);
std::pair<Token, std::string> next(bool phrase = false);

// Defining this means we can use constructs like 'while (tokeniser)'
// It is defined to return NULL (effectively false) when there are
// no tokens left and this otherwise.
operator void *();
};

Thank you in advance
Jun 3 '07 #1
8 2162
weaknessforcats
9,208 Expert Mod 8TB
The compiler complains thats i have a undefined reference to Tokeniser::Tokeniser(std::basic_istream(char, std::char_traits(char))&)

The line Test tester(cin) works as since it was written by myself.
However, whenever i try executing Tokeniser tokeniser(cin) i get the compilation error.
I'm a little confused here.

First, you don't get a compilation error when you execute a function. I suspect your wording is not accurate.

Second, I do see the Tokeniser(instream&) in the class definition, but I do not see that you ever coded the function. Could you supply the test.cc??

I expect you have a link error rather than a compile error since it is linkers that usually produce the "unresolved external reference" errors.
Jun 3 '07 #2
the implementation of the Tokeniser was never given
All that was given was the header file Tokeniser.h and libparser.a which is a static library that contains the Tokeniser class...thats how i have interpreted it.

//START OF TEST CLASS
#include <string>
#include <iostream>
#include "Test.h"

using namespace std;

Test::Test(istream& in)
{
string test;
in >> test;
cout << test;
}
//END OF TEST CLASS

g++ -c -O -Wall -I/usr/cs3/cs3/soft3301/ass3/parser/ main.cc
g++ -c -O -Wall test.cc
g++ -g -Wall -o search.exe main.o test.o -L/usr/cs3/cs3/soft3301/ass3/parser/ -l
parser -static
main.o:main.cc:(.text+0x102): undefined reference to `Tokeniser::Tokeniser(std::
basic_istream<char, std::char_traits<char> >&)'
collect2: ld returned 1 exit status
make: *** [search.exe] Error 1
Jun 3 '07 #3
weaknessforcats
9,208 Expert Mod 8TB
I think I found your problem right here:

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include "Tokeniser.h"
  3. #include "Test.h"
  4.  
  5. using namespace std;
  6.  
At the time Tokeniser.h is included the using namespace std has not occurred. That means there is no std::istream.

Change you code to:

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. #include "Tokeniser.h"
  5. #include "Test.h"
  6.  
  7.  
and it should work.
Jun 3 '07 #4
I think I found your problem right here:

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include "Tokeniser.h"
  3. #include "Test.h"
  4.  
  5. using namespace std;
  6.  
At the time Tokeniser.h is included the using namespace std has not occurred. That means there is no std::istream.

Change you code to:

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. #include "Tokeniser.h"
  5. #include "Test.h"
  6.  
  7.  
and it should work.
nope...not working..I'm still getting the same error
Jun 3 '07 #5
weaknessforcats
9,208 Expert Mod 8TB
The using namespace std was outof place.

However, I am not really versed in makefiles but in the one below I don't where libparser.a is ever used.

g++ -g -Wall -o search.exe main.o test.o -L/usr/cs3/cs3/soft3301/ass3/parser/ -l
parser -static
Jun 3 '07 #6
The using namespace std was outof place.

However, I am not really versed in makefiles but in the one below I don't where libparser.a is ever used.
I have tried placing using namespace std above Tokeniser.h but it does not seem to work

libparser.a is called in -lparser

lib and the extension .a is dropped according to the syntax given on other websites

library location is given in -L[directory]
Jun 3 '07 #7
weaknessforcats
9,208 Expert Mod 8TB
Then you are down to Tokeniser::Tokeniser(std::istream&) is not in your library.
Jun 3 '07 #8
Then you are down to Tokeniser::Tokeniser(std::istream&) is not in your library.
It should be according to the assignment specs below =/
Or have i misinterpreted it

You will be provided with a parser to build a query expression tree from input. The parser is
provided in the directory ~cs3/soft3301/ass3/parser which contains header files and the file
libparser.a which you should link against. Do not copy the header files contained in this
directory or libparser.a into your project but instead make sure you compile with (and
your Makefile includes) the appropriate –I –L and –l options.
The parser suite is comprised of a Tokeniser class, a Parser class and a NodeFactory class. The
Tokeniser class takes an istream and produces a token stream. The Parser take a Tokeniser and
returns a Node which is the root of the expression tree. The Parser creates the Node elements of
the query tree using the NodeFactory. You must implement a NodeFactory and the various
different types of Node subclasses.
A tokeniser/parser pair should be constructed and used as follows.
Tokeniser tokeniser(cin);
Parser& parser = Parser::getParser(NodeFactory::getNodeFactory());
Node *query = parser.query(tokeniser);
Thank you for your help so far...I really appreciate it =)
Jun 3 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: adeht | last post by:
In his book, "Modern C++ Design", Andrei Alexandrescu presents a Generic Object Factory class (Loki::Factory). One of its advantages (also mentioned in the book) is being able to register the...
4
by: Leslaw Bieniasz | last post by:
Cracow, 20.09.2004 Hello, I need to implement a library containing a hierarchy of classes together with some binary operations on objects. To fix attention, let me assume that it is a...
4
by: eap90210 | last post by:
Hi to all ng I 'm a non expert user og db2 and i made a program that it connect to db2 and after goes to a table, verify that exists a value and after return success or not. My problem is...
1
by: Peetah_junkmail | last post by:
Hi, I'm not sure this is completely a C related question since it's more about linking problems, so don't hesitate to redirect me to a more appropriate NG. I have a set of useful functions...
0
by: Shashank Date | last post by:
/* C# Gurus, I am trying to use interop marshalling to call SetCommTimeouts win32 API. But I keep getting the "Object reference not set to an instance of an object" error. Can anybody help...
26
by: CKR Rajesh | last post by:
Hi, I have 2 dlls on which i have the same class MyClass defined. Say A.dll and B.dll The classes have a function (but different functionality) void f(); I use .Net late binding using...
2
by: Joske | last post by:
Hi, I'm having a similar problem as Scott. A static library with managed C++ functions fails to link in. See http://groups.google.be/groups?q=managed+C%2B%...
1
by: Bruno van Dooren | last post by:
Hi, i am using a third party static library (.lib) that wraps a class interface around an old C-style dll. in the static library they use the STL for some stuff i don't know about. in my own...
5
by: Harold Howe | last post by:
I am having a problem deserializing objects from a library when the following conditions exist: 1- The library is strongly named 2- The serialized file was created with version 1.0 of the...
3
by: JDeats | last post by:
I have some .NET 1.1 code that utilizes this technique for encrypting and decrypting a file. http://support.microsoft.com/kb/307010 In .NET 2.0 this approach is not fully supported (a .NET 2.0...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.