help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to suppress the "multiple definitions of symbol"


From: csmgroup
Subject: How to suppress the "multiple definitions of symbol"
Date: 3 Dec 2006 15:03:43 -0800
User-agent: G2/1.0

The module includes the body of the class file in the form of .inl.

<<<<header.h>>>>
#include <iostream>
using namespace std;

class Hello {
  int i,j;
public:
  Hello(int i_,  int j_);
  void print();
};

<<<<<header.inl>>>>
Hello::Hello(int i_, int j_) {
  i = i_; j = j_;
}

void Hello::print() {
  cout << "hello, there.\n" << endl;
}

<<<<module>>>>
#include "header.h"
#include "header.inl"

using namespace std;

void a()
{
  cout << "a" << endl;
}

And the main program has the same .inl even though it doesn't use the
class.

<<<<main program>>>>
#include "header.h"
#include "header.inl"

using namespace std;

int main()
{
        cout << "Hello" << endl;
}

When I try to combine the module together with the main file.
g++ -c moduleb.cpp
g++ <<main program>>  moduleb.o -o du

There are error messages that symbols are duplicated.

/usr/bin/ld: multiple definitions of symbol Hello::Hello(int, int)
modulea.o definition of Hello::Hello(int, int)in section
(__TEXT,__text)
moduleb.o definition of Hello::Hello(int, int)in section
(__TEXT,__text)
/usr/bin/ld: multiple definitions of symbol __ZN5HelloC2Eii.eh
modulea.o definition of absolute __ZN5HelloC2Eii.eh (value 0x0)
moduleb.o definition of absolute __ZN5HelloC2Eii.eh (value 0x0)

I think there is a g++ flag that can suppress this kind of error.
Any ideas?



reply via email to

[Prev in Thread] Current Thread [Next in Thread]