Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Question

Post Timeline

added 17 characters in body
Source Link
Grinlex
  • 23
  • 1
  • 5

Here is the code:

// A.cppm
export module AMOD;
export class A {
public:
 virtual ~A() = default;
 virtual foo() = 0;
};
// B.cppm
export module BMOD;
import AMOD;
export class B : public A {
public:
 virtual void foo() override;
 virtual ~B() = default;
};
module :private;
void B::foo() {}
// C.cppm
export module CMOD;
import BMOD;
export void bar() { B Bobj; Bobj.foo(); }
// main.cpp
import BMOD;
int main() { B b; b.foo(); }

and I got a linker error:

ld.lld: error: duplicate symbol: vtable for B@BMOD
>>> defined at main.cpp
>>> CMakeFiles/test.dir/main.cpp.o:(vtable for B@BMOD)
>>> defined at CMOD.pcm
>>> CMakeFiles/test.dir/C.cppm.o:(.data.rel.ro+0x0)

as said here https://gcc.gnu.org/onlinedocs/gcc-11.1.0/gcc/Vague-Linkage.html If the class declares any non-inline, non-pure virtual functions, the first one is chosen as the "key method" for the class, and the vtable is only emitted in the translation unit where the key method is defined.

If the class declares any non-inline, non-pure virtual functions, the first one is chosen as the "key method" for the class, and the vtable is only emitted in the translation unit where the key method is defined.

then if i make first virtual method of B inline, vtable alse will be inline (or something like that) and then error is gone. but how to properly fix it? I dont want to make it inline bc it looks like crutch

Here is the code:

// A.cppm
export module AMOD;
export class A {
public:
 virtual ~A() = default;
 virtual foo() = 0;
};
// B.cppm
export module BMOD;
import AMOD;
export class B : public A {
public:
 virtual void foo() override;
 virtual ~B() = default;
};
module :private;
void B::foo() {}
// C.cppm
export module CMOD;
import BMOD;
export void bar() { B Bobj; Bobj.foo(); }
// main.cpp
import BMOD;
int main() { B b; b.foo(); }

and I got a linker error:

ld.lld: error: duplicate symbol: vtable for B@BMOD
>>> defined at main.cpp
>>> CMakeFiles/test.dir/main.cpp.o:(vtable for B@BMOD)
>>> defined at CMOD.pcm
>>> CMakeFiles/test.dir/C.cppm.o:(.data.rel.ro+0x0)

as said here https://gcc.gnu.org/onlinedocs/gcc-11.1.0/gcc/Vague-Linkage.html If the class declares any non-inline, non-pure virtual functions, the first one is chosen as the "key method" for the class, and the vtable is only emitted in the translation unit where the key method is defined. then if i make first virtual method of B inline, vtable alse will be inline (or something like that) and then error is gone. but how to properly fix it? I dont want to make it inline bc it looks like crutch

Here is the code:

// A.cppm
export module AMOD;
export class A {
public:
 virtual ~A() = default;
 virtual foo() = 0;
};
// B.cppm
export module BMOD;
import AMOD;
export class B : public A {
public:
 virtual void foo() override;
 virtual ~B() = default;
};
module :private;
void B::foo() {}
// C.cppm
export module CMOD;
import BMOD;
export void bar() { B Bobj; Bobj.foo(); }
// main.cpp
import BMOD;
int main() { B b; b.foo(); }

and I got a linker error:

ld.lld: error: duplicate symbol: vtable for B@BMOD
>>> defined at main.cpp
>>> CMakeFiles/test.dir/main.cpp.o:(vtable for B@BMOD)
>>> defined at CMOD.pcm
>>> CMakeFiles/test.dir/C.cppm.o:(.data.rel.ro+0x0)

as said here https://gcc.gnu.org/onlinedocs/gcc-11.1.0/gcc/Vague-Linkage.html

If the class declares any non-inline, non-pure virtual functions, the first one is chosen as the "key method" for the class, and the vtable is only emitted in the translation unit where the key method is defined.

then if i make first virtual method of B inline, vtable alse will be inline (or something like that) and then error is gone. but how to properly fix it? I dont want to make it inline bc it looks like crutch

added 20 characters in body
Source Link
3CEZVQ
  • 43.7k
  • 11
  • 93
  • 103

Here is the code:

// A.cppm
export module AMOD;
export class A {
public:
 virtual ~A() = default;
 virtual foo() = 0;
};
// B.cppm
export module BMOD;
import AMOD;
export class B : public A {
public:
 virtual void foo() override;
 virtual ~B() = default;
};
module :private;
void B::foo() {}
// C.cppm
export module CMOD;
import BMOD;
export void bar() { B Bobj; Bobj.foo(); }
// main.cpp
import BMOD;
int main() { B b; b.foo(); }
// B.cppm
export module BMOD;
import AMOD;
export class B : public A {
public:
 virtual void foo() override;
 virtual ~B() = default;
};
module :private;
void B::foo() {}
// C.cppm
export module CMOD;
import BMOD;
export void bar() { B Bobj; Bobj.foo(); }
// main.cpp
import BMOD;
int main() { B b; b.foo(); }

and I got a linker error:

ld.lld: error: duplicate symbol: vtable for B@BMOD
>>> defined at main.cpp
>>> CMakeFiles/test.dir/main.cpp.o:(vtable for B@BMOD)
>>> defined at CMOD.pcm
>>> CMakeFiles/test.dir/C.cppm.o:(.data.rel.ro+0x0)

as said here https://gcc.gnu.org/onlinedocs/gcc-11.1.0/gcc/Vague-Linkage.html If the class declares any non-inline, non-pure virtual functions, the first one is chosen as the "key method" for the class, and the vtable is only emitted in the translation unit where the key method is defined. then if i make first virtual method of B inline, vtable alse will be inline (or something like that) and then error is gone. but how to properly fix it? I dont want to make it inline bc it looks like crutch

Here is the code:

// A.cppm
export module AMOD;
export class A {
public:
 virtual ~A() = default;
 virtual foo() = 0;
};
// B.cppm
export module BMOD;
import AMOD;
export class B : public A {
public:
 virtual void foo() override;
 virtual ~B() = default;
};
module :private;
void B::foo() {}
// C.cppm
export module CMOD;
import BMOD;
export void bar() { B Bobj; Bobj.foo(); }
// main.cpp
import BMOD;
int main() { B b; b.foo(); }

and I got a linker error:

ld.lld: error: duplicate symbol: vtable for B@BMOD
>>> defined at main.cpp
>>> CMakeFiles/test.dir/main.cpp.o:(vtable for B@BMOD)
>>> defined at CMOD.pcm
>>> CMakeFiles/test.dir/C.cppm.o:(.data.rel.ro+0x0)

as said here https://gcc.gnu.org/onlinedocs/gcc-11.1.0/gcc/Vague-Linkage.html If the class declares any non-inline, non-pure virtual functions, the first one is chosen as the "key method" for the class, and the vtable is only emitted in the translation unit where the key method is defined. then if i make first virtual method of B inline, vtable alse will be inline (or something like that) and then error is gone. but how to properly fix it? I dont want to make it inline bc it looks like crutch

Here is the code:

// A.cppm
export module AMOD;
export class A {
public:
 virtual ~A() = default;
 virtual foo() = 0;
};
// B.cppm
export module BMOD;
import AMOD;
export class B : public A {
public:
 virtual void foo() override;
 virtual ~B() = default;
};
module :private;
void B::foo() {}
// C.cppm
export module CMOD;
import BMOD;
export void bar() { B Bobj; Bobj.foo(); }
// main.cpp
import BMOD;
int main() { B b; b.foo(); }

and I got a linker error:

ld.lld: error: duplicate symbol: vtable for B@BMOD
>>> defined at main.cpp
>>> CMakeFiles/test.dir/main.cpp.o:(vtable for B@BMOD)
>>> defined at CMOD.pcm
>>> CMakeFiles/test.dir/C.cppm.o:(.data.rel.ro+0x0)

as said here https://gcc.gnu.org/onlinedocs/gcc-11.1.0/gcc/Vague-Linkage.html If the class declares any non-inline, non-pure virtual functions, the first one is chosen as the "key method" for the class, and the vtable is only emitted in the translation unit where the key method is defined. then if i make first virtual method of B inline, vtable alse will be inline (or something like that) and then error is gone. but how to properly fix it? I dont want to make it inline bc it looks like crutch

Source Link
Grinlex
  • 23
  • 1
  • 5

C++ 20 modules. duplicate of vtable

Here is the code:

// A.cppm
export module AMOD;
export class A {
public:
 virtual ~A() = default;
 virtual foo() = 0;
};
// B.cppm
export module BMOD;
import AMOD;
export class B : public A {
public:
 virtual void foo() override;
 virtual ~B() = default;
};
module :private;
void B::foo() {}
// C.cppm
export module CMOD;
import BMOD;
export void bar() { B Bobj; Bobj.foo(); }
// main.cpp
import BMOD;
int main() { B b; b.foo(); }

and I got a linker error:

ld.lld: error: duplicate symbol: vtable for B@BMOD
>>> defined at main.cpp
>>> CMakeFiles/test.dir/main.cpp.o:(vtable for B@BMOD)
>>> defined at CMOD.pcm
>>> CMakeFiles/test.dir/C.cppm.o:(.data.rel.ro+0x0)

as said here https://gcc.gnu.org/onlinedocs/gcc-11.1.0/gcc/Vague-Linkage.html If the class declares any non-inline, non-pure virtual functions, the first one is chosen as the "key method" for the class, and the vtable is only emitted in the translation unit where the key method is defined. then if i make first virtual method of B inline, vtable alse will be inline (or something like that) and then error is gone. but how to properly fix it? I dont want to make it inline bc it looks like crutch

created from staging ground
lang-cpp

AltStyle によって変換されたページ (->オリジナル) /