How to know which library I need add to link

I don’t know how to know which libraries I need add additionally when I compiled ROOT code using g++, like this:

g++ -o main mian.c `root-config --cflags` `root-config --libs` -lMinuit -lGui -lEve -lGeom -lRGL

When I already have a code which I using “root -l” to run, but now I want to change it to compile mode, how can I know which library I need add besides the default libraries in root-config --libs.
For example, I want to use THttpServer, I can use a code with THttpServer with “root -l”, but when I want to compile it using g++, I will get error like undefined reference to THttpServer::THttpServer(char const*)', it can be solved by add -lRHTTP` in the g++ compile command, but I know it quite by chance. So I want to know the best way when facing this problem.

By the way, I want to ask the best way to get or print all libraries provided by ROOT(in my ROOT environment ), like root-config --libs which only print the default libraries.


ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided