Undefined reference when Linking CXX executable bin/llvm-lto2

Could anyone please help me look at this problem ???
I will pay 10 bucks(PayPal only), really. :sob: :sob: :sob: :sob:
Strange ! Please help me! I’m getting crasy :tired_face:

Build Command:


ninja -j1

clang 10.0.0
gcc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0

Debug Info:

Undefined reference to llvm::LoongArchTargetLowering::LoongArchCC::LoongArchCC(

I checked My code, it definitely well defined in LoongArchISelLowering.h and be included by LoongArchISelLowering.cpp as follow:

// LoongArchISelLowering.h
namespace llvm {
  class LoongArchTargetLowering : public TargetLowering {
    class LoongArchCC {
                LoongArchCC(CallingConv::ID CallConv, bool IsILP32S, CCState &Info,
                       SpecialCallingConvType SpecialCallingConv = NoSpecialCallingConv);
// LoongArchISelLowering.cpp
LoongArchTargetLowering::LowerReturn(...) const {
    LoongArchCC LoongArchCCInfo(CallConv, ABI.IsILP32S(), CCInfo); //this is line 109 where error occur

I also asked my teacher to check it and he said my doesn’t have any problem ,it’s just a simple class constructor call. I first thought that might because I build llvm by -j4 so the compiler could had started to linking library while something hadn’t be done. But when I delete all the Build files and build it with -j1 command, it still failed.

In case you want to see my full code: github Url

Declaring class inside a class? This is not C++ syntax.

1 Like

Sorry, my mistake. I didn’t know it before. This is allowed in C++ Nested classes - cppreference.com
Maybe you cannot declare it with protected:?

1 Like

Can you show the definition of the constructor? What you have in the .h file is a declaration, not a definition.


There is only a declaration of the constructor in the header file. There is no matching implementation in the implementation file you linked to on GitHub.

1 Like

thank for your reply.
I tried public ,still not working

Like @ributzka said, you need to implement the constructor. Change LoongArch_CodeGen_Optimize/LoongArchISelLowering.h at main · DYY-Drummer/LoongArch_CodeGen_Optimize · GitHub to something like:

 LoongArchCC(CallingConv::ID CallConv, bool IsILP32S, CCState &Info,
                   SpecialCallingConvType SpecialCallingConv = NoSpecialCallingConv) : CCInfo(Info), .... {}
1 Like

Jesus! How can I be so stupid :tired_face:

I must be a shame of C++ Programmer to ignore such base acknowledge.


That exactly what I was missed !!!

even though it’s such a stupid question, it still messed me up for a whole day.

By the way,sir. As I worte in the question, you are the first one to solve my problem, Could you please let me buy you a coffee? :joy: I only have Paypal for international payment.

You are right, sir. :sob:

I’m so appreciate that you’d will to look at my shit mountain at github

could you please dm me your Paypal number so I can buy you a coffee?

You guys’ help must be the warmest thing I’ve met these days.

Damn, I love this Community