Ubuntu 16.04.3下CMake安装ROOT成功但无法通过Makefile使用
Hey there! Since you're new to Linux and ROOT, let's walk through the most common fixes for issues when using a custom Makefile with your CMake-installed ROOT setup. Even though root launches fine, your Makefile might be missing key setup steps that the ROOT shell environment handles automatically.
Common Fixes to Try
First, load ROOT's environment variables before running
make
When you install ROOT via CMake, it doesn't automatically set up all required environment variables for every terminal session. Therootcommand works because it's in your PATH, but your Makefile needs access to include paths, library paths, and compiler flags. Run this command in the terminal where you're trying to use the Makefile:source <your-root-install-path>/bin/thisroot.shReplace
<your-root-install-path>with where you installed ROOT (common spots are~/rootor/usr/local/root). This script sets variables likeROOTCFLAGSandROOTLIBSthat your Makefile needs to compile against ROOT successfully.Update your Makefile to use ROOT's config tool
Your Makefile needs to pull in the correct compiler and linker flags from ROOT. A basic working setup should include these lines:CXX = g++ CXXFLAGS = -Wall -O2 `root-config --cflags` LDFLAGS = `root-config --libs` # Example rule for a ROOT-based program my_root_program: my_root_program.cpp $(CXX) $(CXXFLAGS) -o $@ $^ $(LDFLAGS)The
root-config --cflagscommand grabs all the include paths ROOT uses, whileroot-config --libsprovides the necessary linker flags and library references. If your Makefile doesn't use these, it won't be able to find ROOT's headers or libraries.Verify ROOT's installation path is correct
Runroot-config --prefixin your terminal. This should output the directory where ROOT is installed. Make sure this path is accessible (you have read permissions) and that your Makefile isn't hardcoding a different, incorrect path.Double-check Ubuntu dependencies
Ubuntu 16.04 has some older default packages, and ROOT relies on several system libraries. If you get errors about missing headers or libraries, install these core prerequisites first:sudo apt-get install build-essential libx11-dev libxpm-dev libxft-dev libxext-devIf you installed ROOT with extra features (like Python support), you'll need the corresponding dev packages (e.g.,
python-dev) too.
If you can share the exact error messages you get when running make, plus the content of your Makefile, we can pinpoint the exact issue much faster!
内容的提问来源于stack exchange,提问作者user799429

