[LC++]Linkinkg with my own library

Erik Mouw J.A.K.Mouw at ITS.TUDelft.NL
Wed Aug 1 22:33:30 UTC 2001


On Wed, Aug 01, 2001 at 01:57:30PM +0200, Laszlo Boszormenyi wrote:
> I have a small library as follows:
> class Webhelper {
> public:
> 	Webhelper(void) {
> 		[...]
> 	}
> 	~Webhelper(void) {
> 		[...]
> 	}
> 	vector<string> parseQuery(void) {
> 		[...]
> 	}
> };
> compiled with g++ 2.95.4, switches: -Wall -shared -fPIC -o libWebhelper.so Webhelper.cpp
> I think this where I make my mistake. As I can not compile the lines:
> Webhelper parser;
> parser.parseQuery();
> because all the symbols related to the lib can not be found. I have tried
> a lot of things, set LD_LIBRARY_PATH, put my lib into /usr/lib and
> ldconfig etc. Still, during linking I get unresolved symbols. At last I
> have tried ld --library Webhelper and this said:
> ld: warning: cannot find entry symbol _start; not setting start address
> Thus ld sees my lib, but can not handle it or something. Please give me
> some idea what is wrong. Thanks!

Don't try to reinvent the way to create shared libraries, but use the
knowledge of the people who created libtool. This should do the trick:

  libtool --mode=compile g++ -O2 -Wall -c foo.cc
  libtool --mode=link g++ -O2 -o libfoo.la -rpath /tmp foo.lo

After that your library can be found in the .libs firectory.

> Second: how can I get the position of a character I search
> for in a string? strstr and others give me a pointer to that char, but not
> the position.

	char *str = "Hello, world!\n";
	char *p;
	int position;

	p = strstr(str, " ");
	position = p - str;

Proper error checking left as an excersise to the reader.


Erik	

-- 
J.A.K. (Erik) Mouw, Information and Communication Theory Group, Department
of Electrical Engineering, Faculty of Information Technology and Systems,
Delft University of Technology, PO BOX 5031,  2600 GA Delft, The Netherlands
Phone: +31-15-2783635  Fax: +31-15-2781843  Email: J.A.K.Mouw at its.tudelft.nl
WWW: http://www-ict.its.tudelft.nl/~erik/



More information about the tuxCPProgramming mailing list