0

I have compiled a variety of LLVM Object files.

However, when linking them together, I get this error:

error: Linking globals named '_ZTV4CRpg': symbol multiply defined!

I debugged and found there was a conflict between two objects: rpg.o and weapons.o. They both had the _ZTV4CRpg symbol in them. This translates to a vtable for CRpg. And that would make sense, as they both define CRpg. However, the definitions of CRpg are totally different. Why would this happen and is there a fix?

Here are the two C++ source files: weapons.cpp, rpg.cpp

I found a bug in LLVM regarding this issue but I cannot apply the latest version as the program I am trying to compile is 7 years old, the patch is 1 year old, and I need to avoid compatibility issues as much as possible.

Using modern compilers, however, it is shown that the symbols are NOT the same:

$ nm build/dlls/CMakeFiles/server.dir/rpg.cpp.o | grep _ZTV4CRpg 
                  U _ZTV4CRpg 
$ nm build/dlls/CMakeFiles/server.dir/weapons.cpp.o | grep _ZTV4CRpg
 0000000000000000 V _ZTV4CRpg

However on the LLVM build they are both 0000000000000000 V _ZTV4CRpg

Note I used nm and grep to scan for conflicting symbols.

8
  • 2
    This is simply illegal C++. At least one of the classes should be in unnamed namespace { ... } to not collide. Commented Oct 16, 2024 at 8:29
  • "...However, the definitions of CRpg are totally different..." Breaks the one-definition-rule, no diagnostic required. Definitions and ODR (One Definition Rule) "... There can be more than one definition in a program of each of the following: class type ... as long as all of the following is true: ... each definition consists of the same sequence of tokens ..."_ Commented Oct 16, 2024 at 8:38
  • you should make a minimal reproducible example/sscce Commented Oct 16, 2024 at 13:59
  • @HolyBlackCat Is it really if dozens of other people managed to compile it? It's the Half-Life SDK, I'm sure it would have been compiled multiple times. Commented Oct 17, 2024 at 6:45
  • @HolyBlackCat For proof, I just compiled it with regular GCC 🤷‍♂️. Worked fine. Commented Oct 17, 2024 at 8:20

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.