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:
f3f42dbefc29afde98f351888bad7f99

Build Command:

cmake -DLLVM_TARGETS_TO_BUILD=LoongArch -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang -DCMAKE_BUILD_TYPE=Debug -G "Ninja" ../llvm

ninja -j1

Environment:
LLVM-project-llvmorg-10.0.0
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 {
    protected:
    class LoongArchCC {
            public:
                ...
                LoongArchCC(CallingConv::ID CallConv, bool IsILP32S, CCState &Info,
                       SpecialCallingConvType SpecialCallingConv = NoSpecialCallingConv);
                ...
    }
  }
}
// LoongArchISelLowering.cpp
SDValue
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.

2 Likes

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.

school-of-rock-jack-black

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:
school-of-rock-jack-black

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