From debugging, it looks as if it's not finding anything in the FPCDIR environment variable and is supplying its own default of ~/freepascal/fpc, which in my case is not there. I'm a little puzzled as I'm sure I installed the FPC source as one of the three install downloads, but I'm not sure which folder on my system is regarded as the FPCDIR. Can anyone help here?

I renamed the /etc/fpc.cfg to /etc/fpc.cfg.OLD, whereupon, my Lazarus refused to build anything. I promptly renamed /etc/fpc.cfg.OLD back to /etc/fpc.cfg again. Now I can build again.

If there is a conflict, usually that's the one that caused it. Technically it *should* also be the correct one because of linux search order.Problem is that it won't get removed by the package managers when purging a previous install. Which in turn leads to your kind of problem after a re-install using a different directory.

You need to generate local fpc.cfg config file by using fpcmkcfg utility. I suggest generating the config file in the same place where the fpc binary resides. Then rename the fpc binary e.g to fpc_old and use following bash script snippet (name it to fpc) to pass the configuration file to renamed compiler executable.

I use following bash script snippet to generate fpc.cfg file and make my installation of FPC fully portable. Whenever you move FPC to different directory, run this and you get fully working FPC distribution in seconds.

Getting back to the real issue here. From debugging CodeTools I can see that CodeToolBoss.SimpleInit(ConfigFilename); ends up calling TCodeToolsOptions.InitWithEnvironmentVariables;

This method attempts to read the following environment variable: PP, FPCDIR, LAZARUSDIR, FPCTARGET and FPCTARGETCPU.

If it doesn't find them, it then sets default values, but unfortunately these defaults bare no resemblance to my actual folder structure.

For example, the variable FPCSrcDir which is supposed to be the value of FPCDIR gets initialised to "~/freepascal/fpc".

I experimented with adding the line export FPCDIR=/usr/local/share/fpcsrc to my .bash_profile but I've had problems debugging this because any attempt to use a GUI for debugging (Xcode in this case) means that GetEnvironmentVariableUtf8 doesn't work. GetEnvironmentVariableUtf8 does work ok if I just use a console app - I just can't debug it the usual way.

So basically I need values for PP, FPCTARGET and FPCTARGETCPU. Can anyone help?

If anyone is doing CodeTools stuff on an Apple Mac under Sierra and wants to debug then use the guide on this page to set up Xcode. https://macpgmr.github.io/ObjP/ProjectXC.htmlThere are a few things to remember. Try to put your code that you want debugged in a class in a .pas file and call that class from a console app. Xcode debugging doesn't seem to work directly in .lpr files.

You'll need to add the environment variables to Xcode. Select Product -> Scheme -> Edit Scheme and add the environment variables here along with any runtime parameters, such as a .pas file parameter. See the attached image as a guide.

Using this setup I have managed to debug in Xcode to the end of this method without raising any exceptions. I just need to figure out how the CodeToolBoss.Explore(Code, CodeTool, True, True); stuff works next. But that can wait until the morning!