2

I'm trying to use distcc to compile C/C++ programs using more than one computer through the network. I'm using only two computers for now, but I intend to use more when it works with those two.

I'm using Gentoo, I installed distcc in both machines with the command:

[user@pc ~]$ emerge distcc

the IPs/names of the machines I'm using are: 10.0.0.47 (qc7) and 10.0.0.46 (qc6). those computers are identical, I installed exactly the same packages on them all, and I configured distcc the same way.

I set the machine names with distcc-config:

[user@pc ~]$ distcc-config --set-hosts "qc6 qc7"

and I changed the file /etc/conf.d/distcc to allow both machines:

...
DISTCCD_OPTS="${DISTCCD_OPTS} --allow 10.0.0.46 --allow 10.0.0.47"
...

after that, I just started the service:

[user@pc ~]$ /etc/init.d/distccd start

I tried to compile a simple C++ program, with one class (.h and .cc) and a file with the main function. the code is below:

person.h

#include <string>

using namespace std;

class Person {
  private:
    string name_;
    int age_;

  public:
    Person(string, int);

    string name() const { return name_; }
    int age() const { return age_; }

    void set_name(string name) { name_ = name; }
    void set_age(int age) { age_ = age; }
};

person.cc

#include "person.h"

Person::Person(string name, int age)
    : name_(name), age_(age) {}

main.cc

#include <iostream>
#include "person.h"

using namespace std;

int main() {
    Person cd1("Cristian",22);
    cout << "hi, my name is " << cd1.name() << " and I'm " << cd1.age() << " years old." << endl;
    return 0;
}

Makefile

CC=g++
CFLAGS=-Wall

person: main.o person.o
$(CC) $(CFLAGS) -o person main.o person.o

person.o: person.cc person.h
$(CC) $(CFLAGS) -c person.cc

main.o: main.cc person.h
$(CC) $(CFLAGS) -c main.cc

if I run only:

[user@pc ~]$ make

without using distcc, the code compiles fine. but if I run:

[user@pc ~]$ make CC=distcc

the linking phase gives me an error. here's the output:

distcc -Wall -c main.cc
distcc -Wall -c person.cc
distcc -Wall -o person main.o person.o
main.o: In function `global constructors keyed to main':
main.cc:(.text+0xa): undefined reference to `std::ios_base::Init::Init()'
main.cc:(.text+0x19): undefined reference to `std::ios_base::Init::~Init()'
main.o: In function `main':
main.cc:(.text+0x5a): undefined reference to `std::basic_string, std::allocator >::basic_string(char const*, std::allocator const&)'
main.cc:(.text+0x80): undefined reference to `std::basic_string, std::allocator >::_Rep::_S_empty_rep_storage'
main.cc:(.text+0xa4): undefined reference to `std::basic_string, std::allocator >::basic_string(std::basic_string, std::allocator > const&)'
main.cc:(.text+0xb3): undefined reference to `std::cout'
main.cc:(.text+0xb8): undefined reference to `std::basic_ostream >& std::__ostream_insert >(std::basic_ostream >&, char const*, long)'
main.cc:(.text+0xc5): undefined reference to `std::cout'
main.cc:(.text+0xce): undefined reference to `std::basic_ostream >& std::__ostream_insert >(std::basic_ostream >&, char const*, long)'
main.cc:(.text+0xe3): undefined reference to `std::basic_ostream >& std::__ostream_insert >(std::basic_ostream >&, char const*, long)'
main.cc:(.text+0xed): undefined reference to `std::basic_ostream >::operator<<(int)'
main.cc:(.text+0x102): undefined reference to `std::basic_ostream >& std::__ostream_insert >(std::basic_ostream >&, char const*, long)'
main.cc:(.text+0x182): undefined reference to `std::basic_ostream >::put(char)'
main.cc:(.text+0x18a): undefined reference to `std::basic_ostream >::flush()'
main.cc:(.text+0x1d9): undefined reference to `std::__throw_bad_cast()'
main.cc:(.text+0x208): undefined reference to `std::basic_string, std::allocator >::_Rep::_M_destroy(std::allocator const&)'
main.cc:(.text+0x243): undefined reference to `std::basic_string, std::allocator >::_Rep::_M_destroy(std::allocator const&)'
main.cc:(.text+0x277): undefined reference to `std::basic_string, std::allocator >::_Rep::_M_destroy(std::allocator const&)'
main.cc:(.text+0x292): undefined reference to `std::basic_string, std::allocator >::~basic_string()'
main.cc:(.text+0x2af): undefined reference to `std::basic_string, std::allocator >::~basic_string()'
main.cc:(.text+0x2bc): undefined reference to `std::basic_string, std::allocator >::~basic_string()'
main.o:(.eh_frame+0x13): undefined reference to `__gxx_personality_v0'
person.o: In function `Person::Person(std::basic_string, std::allocator >, int)':
person.cc:(.text+0x15): undefined reference to `std::basic_string, std::allocator >::basic_string(std::basic_string, std::allocator > const&)'
person.o: In function `Person::Person(std::basic_string, std::allocator >, int)':
person.cc:(.text+0x45): undefined reference to `std::basic_string, std::allocator >::basic_string(std::basic_string, std::allocator > const&)'
person.o:(.eh_frame+0x12): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
distcc[26001] ERROR: compile (null) on localhost failed
make: *** [person] Error 1

[the line in bold is the only one relevant to distcc, all the others are the compiler output.]

it's as if distcc couldn't find the basic libraries. what should I do to make distcc compile this program using several computers on the network? is it some configuration that I've missed?

2 Answers 2

1

Try not using distcc for the link phase. That is, use

LD=g++

person: main.o person.o
$(LD) $(LDFLAGS) -o person main.o person.o

in your Makefile.

0

Maybe this is a silly question, but... are you sure you put the required headers and libraries on both machines?

1
  • yes, when I run make alone, it works, on both machines. and they have exactly the same GCC package installed, to the headers and libraries are on the same path.
    – cd1
    Jul 7, 2009 at 18:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .