Linking problem in a pass

My pass uses another class which is defined in a separate .h file, which sits in the same folder as the pass .cpp file. The pass compiles fine, but when using the pass “opt -load …”, there is an error: opt symbol lookup error … undefined symbol xxx, where xxx is the class name. It looks like that class file’s object file is not linked into the pass.so file. How should I change the Makefile to make the linking happen?

Thanks,
Welson

My pass uses another class which is defined in a separate .h file, which sits in the same folder as the pass .cpp file. The pass compiles fine, but when using the pass “opt -load …”, there is an error: opt symbol lookup error … undefined symbol xxx, where xxx is the class name. It looks like that class file’s object file is not linked into the pass.so file. How should I change the Makefile to make the linking happen?

If your .cpp file isn’t including the .h file, then the class in the .h file isn’t being compiled and, therefore, isn’t being included in the final library file.

Classes should be declared in header files and have their methods defined in .cpp files. That’s the easiest way to fix the problem.

– John T.

Originally, the problem is the lack of .cpp file. Then I noticed the compilation log is not showing the .o file being generated for the non-pass classes.

Then I added the .cpp files for each .h file, then the .o files are being generated, shown in the Debug directory. Actually, if I add “VERBOSE = 1” in the Makefile, it shows the linking command is actually linking all the .o files into the pass.so file.

Any help will be appreciated.

Thanks!
Welson

Hi Welson, are you saying that the .o file containing the class is being linked
into the .so file, but nonetheless you get "undefined symbol XYZ" errors where
XYZ is that class? Maybe you defined the class inside an anonymous name space?
Alternatively, if XYZ refers to a method of the class, maybe you forgot to
define that method.

Ciao, Duncan.

HI Duncan,

Your understanding of the problem is correct. However, the XYZ class is not inside an anonymous name space. Also, all the XYZ methods are defined in the .cpp file. Looking at the error message:

opt: symbol lookup error: path/to/pass.so: undefined symbol: _ZN12DataTransferD1Ev

Where DataTransfer is the class name. Maybe I am missing certain type of constructors?

Thanks,
Welson

OK, problem found! Inspired by Duncan’s message, I double checked the XYZ class, and what I was missing is the definition of the destructor! What a stupid mistake!

Thanks,
Welson