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

_Geant4 Version:_geant4-v11.1.3
_Operating System:_Sonoma14.5
_Compiler/Version:_Clang 18.1.6
_CMake Version:_3.29.3


Hi,

I’m getting this error and would like not to. Any help?

[ 1%] No install step for ‘G4ENSDFSTATE’
[ 1%] Completed ‘G4ENSDFSTATE’
[ 1%] Built target G4ENSDFSTATE
[ 1%] Building CXX object source/externals/ptl/src/CMakeFiles/ptl-shared.dir/TaskGroup.cc.o
[ 1%] Building CXX object source/externals/ptl/src/CMakeFiles/ptl-shared.dir/TaskRunManager.cc.o
[ 1%] Building CXX object source/externals/ptl/src/CMakeFiles/ptl-shared.dir/ThreadData.cc.o
[ 1%] Building CXX object source/externals/ptl/src/CMakeFiles/ptl-shared.dir/ThreadPool.cc.o
[ 1%] Building CXX object source/externals/ptl/src/CMakeFiles/ptl-shared.dir/Threading.cc.o
[ 1%] Building CXX object source/externals/ptl/src/CMakeFiles/ptl-shared.dir/Timer.cc.o
[ 1%] Building CXX object source/externals/ptl/src/CMakeFiles/ptl-shared.dir/UserTaskQueue.cc.o
[ 1%] Building CXX object source/externals/ptl/src/CMakeFiles/ptl-shared.dir/VUserTaskQueue.cc.o
[ 1%] Linking CXX shared library …/…/…/…/BuildProducts/lib/libG4ptl.dylib
Undefined symbols for architecture arm64:
“std::exception_ptr::__from_native_exception_pointer(void*)”, referenced from:
std::__1::promise::~promise() in UserTaskQueue.cc.o
“___cxa_init_primary_exception”, referenced from:
std::__1::promise::~promise() in UserTaskQueue.cc.o
ld: symbol(s) not found for architecture arm64
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [BuildProducts/lib/libG4ptl.2.3.3.dylib] Error 1
make[1]: *** [source/externals/ptl/src/CMakeFiles/ptl-shared.dir/all] Error 2
make: *** [all] Error 2

I think you’re running into this issue: Compilation Failure with Clang from Brewed LLVM · Issue #169820 · Homebrew/homebrew-core · GitHub

There are some workarounds there, but it’s fundamentally to do with LLVM/Homebrew and not a Geant4 issue.

Thanks. Adding

export CXXFLAGS=“-I$(brew --prefix llvm)/include”
export LDFLAGS=“-L$(brew --prefix llvm)/lib/c++”

as environmental variable solved the issue. In case it may help someone, in the same compilation I had another issues mostly related to homebrew

  • about the redefinition of fdopen in /geant4-v11.1.3/source/externals/zlib/include/zutil.h:146. It was enough wrapping it as

#if defined(APPLE)
#include <stdio.h>
#else
#ifndef fdopen
#define fdopen(fd,mode) NULL /* No fdopen() */
#endif
#endif

  • qt class redifinition
    geant4-v11.1.3/source/interfaces/basic/include/G4UIQt.hh:54:7: error: definition of type 'QStringList

was solved by commenting out that line

I am struggling with latest (hopefully) error again due to Qt

  • qt templates - e.g. /opt/homebrew/Cellar/qt@5/5.15.13_1/lib/QtCore.framework/Headers/qobject.h:305:43: error: no template named ‘QStaticSlotObject’ in namespace ‘QtPrivate’
    305 | new QtPrivate::QStaticSlotObject<Func2,
    | ~~~~~~~~~~~^

I did set the following env

export Qt5_DIR=$(brew --prefix qt@5)/lib/cmake/Qt5
export CMAKE_INCLUDE_PATH=$(brew --prefix qt@5)/include

and added explicitly qt5 paths while building the project

-DCMAKE_PREFIX_PATH=$(brew --prefix qt@5)/lib/cmake/Qt5
-DCMAKE_INCLUDE_PATH=$(brew --prefix qt@5)/include

but the error is still there. Any idea?

Do you have the Homebrew qt (i.e. Qt6) formula installed and linked? If you do, this needs unlinking otherwise its headers will clash with those of the qt@5 formula.

I have no idea about the zlib issue, but it feels like you might need to export CFLAGS as well for this.

Thanks. It looks like that the command
brew unlink qt
was enough. For the zlib, the wrapping described in the previous reply did the job. Now I can run exampleB1 smoothly.

Thanks again!