lundi 23 octobre 2023

Multiple definitions of ... first defined here

When I compile the program:

g++ -std=c++11 SpringMass.cpp SpringDamperMass.cpp main.cpp -o main

...I get multiple errors with the same pattern:

usr/bin/ld: /tmp/cciHWp7J.o:(.bss+0x0): multiple definition of `vec'; /tmp/ccicqdBO.o:(.bss+0x0): first defined here
/usr/bin/ld: /tmp/cciHWp7J.o:(.bss+0x40): multiple definition of `tes'; /tmp/ccicqdBO.o:(.bss+0x40): first defined here
/usr/bin/ld: /tmp/cciHWp7J.o:(.rodata+0x8): multiple definition of `SpringMass::GRAVITY'; /tmp/ccicqdBO.o:(.rodata+0x8): first defined here
/usr/bin/ld: /tmp/cciHWp7J.o:(.rodata+0x10): multiple definition of `SpringMass::SPRING_CONST'; /tmp/ccicqdBO.o:(.rodata+0x10): first defined here
/usr/bin/ld: /tmp/cciHWp7J.o:(.rodata+0x18): multiple definition of `SpringMass::MASS'; /tmp/ccicqdBO.o:(.rodata+0x18): first defined here
/usr/bin/ld: /tmp/cciHWp7J.o:(.rodata+0x20): multiple definition of `SpringMass::x_0'; /tmp/ccicqdBO.o:(.rodata+0x20): first defined here
/usr/bin/ld: /tmp/cc92aQWL.o:(.bss+0x0): multiple definition of `vec'; /tmp/ccicqdBO.o:(.bss+0x0): first defined here
/usr/bin/ld: /tmp/cc92aQWL.o:(.bss+0x40): multiple definition of `tes'; /tmp/ccicqdBO.o:(.bss+0x40): first defined here
/usr/bin/ld: /tmp/cc92aQWL.o:(.bss+0x60): multiple definition of `vec_damp'; /tmp/cciHWp7J.o:(.bss+0x60): first defined here
/usr/bin/ld: /tmp/cc92aQWL.o:(.bss+0xa0): multiple definition of `time_damp'; /tmp/cciHWp7J.o:(.bss+0xa0): first defined here
/usr/bin/ld: /tmp/ccicqdBO.o: in function `SpringMass::SpringMass(double, double, double, double)':
SpringMass.cpp:(.text+0x23): undefined reference to `vtable for SpringMass'
/usr/bin/ld: /tmp/cciHWp7J.o: in function `SpringDamperMass::SpringDamperMass(double, double, double, double, double)':
SpringDamperMass.cpp:(.text+0x5c): undefined reference to `vtable for SpringDamperMass'
/usr/bin/ld: /tmp/cc92aQWL.o: in function `main':
main.cpp:(.text+0x222): undefined reference to `SpringMass::~SpringMass()'
/usr/bin/ld: main.cpp:(.text+0x478): undefined reference to `SpringDamperMass::~SpringDamperMass()'
/usr/bin/ld: main.cpp:(.text+0x4ed): undefined reference to `SpringMass::~SpringMass()'
/usr/bin/ld: main.cpp:(.text+0x532): undefined reference to `SpringDamperMass::~SpringDamperMass()'
collect2: error: ld returned 1 exit status

How can I solve this issue?

The idea is to simulate spring-mass system.

Aucun commentaire:

Enregistrer un commentaire