[LC++]How to link

Laszlo Boszormenyi boszorme at mazsola.iit.uni-miskolc.hu
Tue Aug 28 23:19:14 UTC 2001


Hi!

I have these files, but I can not link them together. What I do:
g++ -c My.cpp
g++ -c caller.cpp
g++ My.o caller.o -o caller

I get:
caller.o: In function `main':
caller.o(.text+0xe): undefined reference to `My::My(void)'
caller.o(.text+0x6f): undefined reference to `My::~My(void)'
caller.o(.text+0x9a): undefined reference to `My::~My(void)'
collect2: ld returned 1 exit status

My g++ version is 2.95.4. Thanks in advance, Laszlo
-------------- next part --------------
#include <iostream>

#include "My.h"

int main(void) {
	My my;
	cout << "Starts..." << endl;
	cout << "...ends" << endl;
	return 0;
}
-------------- next part --------------
#include <iostream>

class My {
public:
	My(void) {
		cout << "Constructed" << endl;
	}
	~My(void) {
		cout << "Destructed" << endl;
	}
};
-------------- next part --------------
#ifndef __MY_H
#define __MY_H

class My {
public:
	My(void);
	~My(void);
};

#endif


More information about the tuxCPProgramming mailing list