How to run ROOT with XCODE on MacBook M1

Hi all,

I have found a nice video explaining how to set up ROOT paths and so on for XCODE on INTEL based laptop. I tried on a MacBook M1 (Sonoma 14.2.1 latest version), and it didn’t work due to some errors.

I installed ROOT long time ago, and it has been working since then. I am currently running the root on a terminal from a macro, and it’s working fine. However, I’d like to use XCODE.
On XCODE, I went to Build Settings on a project I created as in the video.
On my terminal, I found where my ROOT is with …
root-config --prefix
/opt/homebrew/Cellar/root/6.30.02
I set up the path as stated on the video: ROOTSYS = /opt/homebrew/Cellar/root/6.30.02

Then, I defined Header Search Paths: $(ROOTSYS)/include/root

Then, I set Runpath Search Path: $(ROOTSYS)/lib/root

Then, I set Other Linker Flags: -L$(ROOTSYS)/lib/root -lCore -lImt -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lROOTVecOps -lTree -lTreePlayer -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -lMultiProc -lROOTDataFrame -Wl,-rpath,/opt/homebrew/Cellar/root/6.30.02/lib/root -stdlib=libc++ -lpthread -lm -ldl

However, I got these 2 errors which I added the photo of it.

The project name and the function name in the file are not the same. I am not sure if that’S the issue. Normally, the main function name should be the same in ROOT as far as I remember.

Thanks in advance.

Dear Can,

I am sorry to hear you are experiencing this issue.
Have you tried to use as your linker command with the output of root-config --libs --glibs --cflags ?
The screenshot seems to hint to a debugging output: could you perhaps dig it out? Useful information about the cause of this issue might be found there.

Cheers,
D

[quote=“spyhunter01, post:1, topic:57922”]

Note that ROOT is working fine on my MacBook if I use terminal directly.

TERMINAL RESULT: I will post this one as you suggested instead of previous one.
% root-config --libs --glibs --cflags

-L/opt/homebrew/Cellar/root/6.30.02/lib/root -lCore -lImt -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lROOTVecOps -lTree -lTreePlayer -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -lMultiProc -lROOTDataFrame -Wl,-rpath,/opt/homebrew/Cellar/root/6.30.02/lib/root -stdlib=libc++ -lpthread -lm -ldl -L/opt/homebrew/Cellar/root/6.30.02/lib/root -lGui -stdlib=libc++ -pthread -std=c++17 -m64 -I/opt/homebrew/Cellar/root/6.30.02/include/root

FAILED AGAIN. This is the screen shot showing details.

Screenshot 2024-01-24 at 15.52.55

This is the file I run. Source link:ROOT: TGraph Class Reference
main.cpp (401 Bytes)

I also set up the c++ dialect as -std=c++17 on the target section in XCODE:

TERMİNAL RESULT FOR THAT:
root-config --cflags
-stdlib=libc++ -pthread -std=c++17 -m64 -I/opt/homebrew/Cellar/root/6.30.02/include/root

@Danilo

I have just install new ROOT version 6.30, and it works fine on terminal.

I repeated the procedure I explained above with screenshots again, but XCODE cannot compile the code.

The error at this time is “… .h. files not found”. I guess XCODE cannot reach the library files. I set up the PATH already. Why it cannot find it? It should be easy.

[quote=“Danilo, post:2, topic:57922”]
root-config --libs --glibs --cflags
[/quote root-config --libs --glibs --cflags

-L/opt/local/libexec/root6/lib/root -lCore -lImt -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lROOTVecOps -lTree -lTreePlayer -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -lMultiProc -lROOTDataFrame -Wl,-rpath,/opt/local/libexec/root6/lib/root -stdlib=libc++ -lpthread -lm -ldl -L/opt/local/libexec/root6/lib/root -lGui -stdlib=libc++ -pthread -std=c++17 -m64 -I/opt/local/libexec/root6/include/root

I tried to posted this in other linker flags section in XCODE, but it didn’t work as well.

I also tried to use this command below on terminal instead of XCODE, and it didn’t work as well.

clang++ -std=c++17 -I/opt/local/libexec/root6/include/root -L/opt/local/libexec/root6/lib/root -lCore /Users/…/ROOTtest/ROOTtest/main.cpp

RESULT:

ld: Undefined symbols:

TGraph::TGraph(int, double const*, double const*), referenced from:

_main in main-15c840.o

clang: error: linker command failed with exit code 1 (use -v to see invocation)

Again, root works fine on terminal directly without XCODE.

@couet
Does Couet suggest renaming the include directory to any other name?

I have removed the old ROOT installed by homebrew anyway.
I used Macport this time.

I reinstalled ROOT with macport. Here is its details:

Welcome to ROOT 6.30/03
| Built for macosxarm64 on Jan 16 2024, 13:11:20
| From heads/master@tags/v6-30-03
| With Apple clang version 15.0.0 (clang-1500.1.0.2.5)
///////////////////////////////////////////////
I have XCODE 15.2 installed.
////////////////////////////////////////////////
I have SONOMA 14.2.1 on my MacBook.
/////////////////////////////////////////////////////////////////////
These are the commands on terminal. and their results to place in XCODE to make ROOT work (hopefully).

root-config --prefix : /opt/local/libexec/root6
ROOTSYS = /opt/local/libexec/root6
Header Search Paths: $(ROOTSYS)/include/root

Runpath Search Path: “$”(ROOTSYS)/lib/root
Linker Flags command: root-config --libs --glibs --cflags
Linker Flags: -L/opt/local/libexec/root6/lib/root -lCore -lImt -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lROOTVecOps -lTree -lTreePlayer -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -lMultiProc -lROOTDataFrame -Wl,-rpath,/opt/local/libexec/root6/lib/root -stdlib=libc++ -lpthread -lm -ldl -L/opt/local/libexec/root6/lib/root -lGui -stdlib=libc++ -pthread -std=c++17 -m64 -I/opt/local/libexec/root6/include/root

C++ language dialect in XCODE is set to -std=c+++17

That’s how it looks inside my root6 directory on my terminal:

Now, The question is if there is anything else to put on either “build settings” or " targets build setting" section in XCODE to work!?

I finally concluded that it is nothing to do with me. The headers got errors (BUGS) in them. For instance, parameter pr is not defined in TMath.h and implicit conversion error in line " return TString(buffer, strlen(buffer), s.Data(), s.Length());" in TString.h file.

I am using ROOT only from terminal on Mac, and always install it from sources. I do not have experience with what you are trying to do.

Hi!

It seems we are a bit blocked here.
Perhaps can the suggestion of Olivier be followed and a minimal build of ROOT tried from sources?

Best,
D

Hi,

I will stick with stand alone ROOT. I will just run the macro from a file on a terminal. Unfortunately, I can’t get the benefit of using XCODE which might have speed up my code writing. I still use XCODE but only to read the code not to compile.