Hello everyone,

I am a student working on interfacing a firewire camera with a linux machine. I am able to successfully compile my files (timer.cpp and test_timer.cpp) (they are called timers because i am testing the latency of the camera). Anyways, my problem is that I first type in:
g++ -c -lrt timer.cpp test_timer.cpp
then:
g++ -lrt -o -lrt test_timer timer.o test_timer.o -lraw1394 -ldc1394

which results in the following errors/messages:

test_timer: In function `_start':
/build/buildd/glibc-2.9/csu/../sysdeps/x86_64/elf/start.S:65: multiple definition of `_start'
/usr/lib/gcc/x86_64-linux-gnu/4.3.3/../../../../lib/crt1.o:/build/buildd/glibc-2.9/csu/../sysdeps/x86_64/elf/start.S:65: first defined here
test_timer: In function `_fini':
/build/buildd/glibc-2.9/build-tree/amd64-libc/csu/crti.S:37: multiple definition of `_fini'
/usr/lib/gcc/x86_64-linux-gnu/4.3.3/../../../../lib/crti.o:/build/buildd/glibc-2.9/build-tree/amd64-libc/csu/crti.S:37: first defined here
test_timer:(.rodata+0x0): multiple definition of `_IO_stdin_used'
/usr/lib/gcc/x86_64-linux-gnu/4.3.3/../../../../lib/crt1.o:(.rodata.cst4+0x0): first defined here
test_timer: In function `__data_start':
(.data+0x0): multiple definition of `__data_start'
/usr/lib/gcc/x86_64-linux-gnu/4.3.3/../../../../lib/crt1.o:(.data+0x0): first defined here
test_timer: In function `__data_start':
(.data+0x8): multiple definition of `__dso_handle'
/usr/lib/gcc/x86_64-linux-gnu/4.3.3/crtbegin.o:(.data+0x0): first defined here
test_timer: In function `_init':
/build/buildd/glibc-2.9/build-tree/amd64-libc/csu/crti.S:25: multiple definition of `_init'
/usr/lib/gcc/x86_64-linux-gnu/4.3.3/../../../../lib/crti.o:/build/buildd/glibc-2.9/build-tree/amd64-libc/csu/crti.S:25: first defined here
/tmp/ccoK6khH.o: In function `Timer::toc(int)':
timer.cpp:(.text+0x0): multiple definition of `Timer::toc(int)'
test_timer:(.text+0xf0): first defined here
/tmp/ccoK6khH.o: In function `Timer::toc()':
timer.cpp:(.text+0xd0): multiple definition of `Timer::toc()'
test_timer:(.text+0x160): first defined here
/tmp/ccoK6khH.o: In function `Timer::tic(int)':
timer.cpp:(.text+0xfe): multiple definition of `Timer::tic(int)'
test_timer:(.text+0x170): first defined here
/tmp/ccoK6khH.o: In function `Timer::tic()':
timer.cpp:(.text+0x12e): multiple definition of `Timer::tic()'
test_timer:(.text+0x190): first defined here
/tmp/ccoK6khH.o: In function `curTime()':
timer.cpp:(.text+0x14a): multiple definition of `curTime()'
test_timer:(.text+0x1a0): first defined here
/tmp/ccoK6khH.o: In function `Timer::~Timer()':
timer.cpp:(.text+0x178): multiple definition of `Timer::~Timer()'
test_timer:(.text+0x1c0): first defined here
/tmp/ccoK6khH.o: In function `Timer::~Timer()':
timer.cpp:(.text+0x1ba): multiple definition of `Timer::~Timer()'
test_timer:(.text+0x200): first defined here
/tmp/ccoK6khH.o: In function `Timer::Timer(int)':
timer.cpp:(.text+0x1fc): multiple definition of `Timer::Timer(int)'
test_timer:(.text+0x240): first defined here
/tmp/ccoK6khH.o: In function `Timer::Timer(int)':
timer.cpp:(.text+0x2aa): multiple definition of `Timer::Timer(int)'
test_timer:(.text+0x2b0): first defined here
/tmp/ccuPffNU.o: In function `cleanup_and_exit(__dc1394_camera*)':
test_timer.cpp:(.text+0x0): multiple definition of `cleanup_and_exit(__dc1394_camera*)'
test_timer:(.text+0x320): first defined here
/tmp/ccuPffNU.o: In function `main':
test_timer.cpp:(.text+0x36): multiple definition of `main'
test_timer:(.text+0x350): first defined here
/usr/lib/gcc/x86_64-linux-gnu/4.3.3/crtend.o:(.dtors+0x0): multiple definition of `__DTOR_END__'
test_timer:(.dtors+0x8): first defined here
/usr/bin/ld: warning: Cannot create .eh_frame_hdr section, --eh-frame-hdr ignored.
/usr/bin/ld: error in test_timer(.eh_frame); no .eh_frame_hdr table will be created.
collect2: ld returned 1 exit status

I've been looking around on the internet for a solution and the problem is quite common but I am for lack of a better word a noob times 2 when it comes to programming and don't really understand how to fix this issue. Most of the above functions are declared once and my header file is simply:

#ifndef TIMER_H_
#define TIMER_H_

#include <string> // Required for clock access
#include <time.h>
#include <unistd.h>
#include <signal.h>

double curTime();

class Timer {
  public:
    Timer(const int numberOfTimers);
    ~Timer();
    void tic();
    double toc();
    void tic(int timernum);
    double toc(int timernum);
  private:
    int nTimers;
    timespec *ts0, *ts1;
};

#endif /*TIMER_H_*/

Any help you could give me is much appreciated as I am already a month behind in my work....

Thanks in advance.

Ignore the smiley faces.. I didn't know what [tex] tags did. I've tried to make some changes.

Try using code tags then.

> g++ -c -lrt timer.cpp test_timer.cpp
Why are you passing linker flags here?

thats a good question. I'm not sure why I'm using it for the first step. It doesnt really make much of a difference with regards to the errors I'm getting.

No it doesn't.

I managed to get it to work but I'm still unsure why it is working since I didn't even change anything obvious.

Thanks for your help everyone.

This question has already been answered. Start a new discussion instead.