Makefile errors when compiling executable program using rootcling-generated dictionaries

Root Version: 6.26/10
Platform: AlmaLinux 8.7
Compiler: g++

Issue to address:

I’ve written a simple program with the goal of learning how to generate dictionaries for use in ROOT programs using a Makefile. However, when I try to make the program in its current state, I receive the following error:

/usr/bin/ld: cannot find -lDict
collect2: error: ld returned 1 exit status
make: *** [Makefile:16: test] Error 1

My guess is that I’ve probably made a simple mistake here, but I’ve so far been unable to figure it out.

Steps to reproduce:

I am unfortunately unable to post links as a first time poster, so I have pasted my Makefile below.

Makefile:

SRC = src
BIN = bin

CC = g++
CFLAGS = -c -w -std=c++14 -I$(shell root-config --incdir)
CFLAGSDICT = -c -w -I$(shell root-config --incdir)
LINKOPTION = $(shell root-config --libs)

test : $(BIN)/test.o $(BIN)/simple_struct.so
	@echo "Linking..."
	$(CC) $^ -o$@ $(LINKOPTION) -L./$(BIN) -lDict
	@echo "Finished"

$(BIN)/simple_struct.so : simple_struct.cxx
	$(CC) -shared -fPIC -o$@ $(CFLAGS) -I$(ROOTSYS)/include $^ `root-config --ldflags --libs`

simple_struct.cxx : $(SRC)/simple_struct.h $(SRC)/LinkDef.h
	rootcling -f $@ $(CFLAGSDICT) -p $^

$(BIN)/test.o : $(SRC)/test.cpp
	@echo "Compiling..."
	$(CC) $(CFLAGS) -c $< -o $@

clean:
	rm -f $(BIN)/*.o
	rm -f $(BIN)/*.so
	rm -f *.cxx
	rm -f *.pcm

.PHONY: $(SRC)/simple_struct.h $(SRC)/Linkdef.h test clean

Additional comments:

First time forum-poster here. I have moderate experience with ROOT and C++, and usually spend time researching issues like this before I resort to the forums route. However, I have been banging my head against a wall on this one for a while now with no discernible progress, so here I am.

The most useful references I’ve encountered so far include the manual page on “I/O of custom classes” and an old forum post on “Using rootcint to generate dictionaries for standalone progs.”

I would like to be able to generate some shared object dictionary files from some header files and compile them into an executable program. However, the official ROOT documentation on how to do this is not very thorough, and most of the forum posts I’ve found are either 10 years old or don’t provide adequate code references for me to be able to understand what they are doing.

The step I’m struggling with is generating the executable program while referencing the previously generated shared object dictionary files correctly. What is the proper way to do this?

Hi Henry,

thanks for the post and welcome to the ROOT Community!

Your question is not really related to ROOT but seems rather a general Makefile question. You seem to try to link against a library called libDict.so but you do not generate it anywhere. Perhaps it’s there by mistake.

Best,
D

Thank you for the response! I guess you’re right that this is more of a Makefile question than a ROOT specific question, but I’ll gladly take your help if you’re still willing to offer it.

I don’t see libDict.so explicitly anywhere in my Make file, but I’m guessing this has something to do with the -lDict flag in the test rule? I looked this one up before posting, and I think I understand that this is looking for a library called Dict. However, I instead want to point to the simple_struct.so library. This is created from the simple_struct.cxx file generated by rootcling, but I’m not sure what “name” rootcling gives the shared library after compilation.

I’ve tried using the name of the file (i.e. -lsimple_struct), but this leads to the same error as before. What is the correct way to link against a rootcling-generated library in a Makefile?

Hi,

In general libraries are called libXYZ.so, they are linked as -l XYZ and can be found in an env variable called LD_LIBRARY_PATH.

Cheers,
Danilo

After I generate the simple_struct.cxx file using rootcling, I then compile it into simple_struct.so library file. However, as mentioned above, when I try to use the -l simple_struct option to link this particular library, I get the same error as before.

One other thing I tried is using the -s option in rootcling to specify a library name. However, if I do this and use the same specified library name with the -l option, I also still get the same error.

How then do I figure out what library name to use with the -l option?