iqtree / iqtree2

NEW location of IQ-TREE software for efficient phylogenomic software by maximum likelihood http://www.iqtree.org
GNU General Public License v2.0
246 stars 57 forks source link

Build issues on macOS 14.5: ` error: call to 'gettimeofday' is ambiguous` #275

Closed corneliusroemer closed 2 months ago

corneliusroemer commented 4 months ago

I've tried to build iqtree2 v2.3.5 on macOS arm64 14.5.

I'm getting the following error:

$ cmake .. -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++
$ gmake -j
...snip...
In file included from /Users/corneliusromer/code/iqtree2/tree/genometree.h:11:
/Users/corneliusromer/code/iqtree2/utils/timeutil.h:80:16: error: functions that differ only in their return type cannot be overloaded
   80 |         __inline void gettimeofday(struct timeval* t, void* timezone) {
      |                  ~~~~ ^
/Applications/Xcode-15.4.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk/usr/include/sys/time.h:198:9: note: previous declaration is here
  198 | int     gettimeofday(struct timeval * __restrict, void * __restrict);
      | ~~~     ^
In file included from /Users/corneliusromer/code/iqtree2/tree/phylokernelsse.cpp:10:
In file included from /Users/corneliusromer/code/iqtree2/tree/phylokernel.h:11:
In file included from /Users/corneliusromer/code/iqtree2/tree/phylotree.h:36:
In file included from /Users/corneliusromer/code/iqtree2/tree/mtree.h:23:
In file included from /Users/corneliusromer/code/iqtree2/tree/node.h:41:
In file included from /Users/corneliusromer/code/iqtree2/alignment/sequence.h:5:
In file included from /Users/corneliusromer/code/iqtree2/tree/genometree.h:11:
/Users/corneliusromer/code/iqtree2/utils/timeutil.h:139:2: error: call to 'gettimeofday' is ambiguous
  139 |         gettimeofday(&tv, NULL);
      |         ^~~~~~~~~~~~
/Applications/Xcode-15.4.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk/usr/include/sys/time.h:198:9: note: candidate function
  198 | int     gettimeofday(struct timeval * __restrict, void * __restrict);
      |         ^
/Users/corneliusromer/code/iqtree2/utils/timeutil.h:80:16: note: candidate function
   80 |         __inline void gettimeofday(struct timeval* t, void* timezone) {
      |                       ^
In file included from /Users/corneliusromer/code/iqtree2/tree/phylokernelsse.cpp:16:
...snip...

This might be because I use a recent SDK, v14.5

When I comment out the following, I don't get the compilation error (workaround):

https://github.com/iqtree/iqtree2/blob/74da454bbd98d6ecb8cb955975a50de59785fbde/utils/timeutil.h#L80-L85

corneliusroemer commented 4 months ago

Later, I got some libomp errors:

/Users/corneliusromer/code/iqtree2/simulator/alisimulator.cpp:1755:71: error: use of undeclared identifier 'omp_get_num_threads'
 1755 |             if ((*it)->node->sequence->num_threads_done_simulation == omp_get_num_threads())
      |                                                                       ^
1 error generated.
gmake[2]: *** [simulator/CMakeFiles/simulator.dir/build.make:76: simulator/CMakeFiles/simulator.dir/alisimulator.cpp.o] Error 1
gmake[2]: *** Waiting for unfinished jobs....
gmake[1]: *** [CMakeFiles/Makefile2:997: simulator/CMakeFiles/simulator.dir/all] Error 2
gmake: *** [Makefile:156: all] Error 2

I fixed them by using this build script with the help of chatgpt:

export CPPFLAGS="-I/opt/homebrew/opt/libomp/include"
export LDFLAGS="-L/opt/homebrew/opt/libomp/lib"
export CMAKE_CXX_FLAGS="-Xpreprocessor -fopenmp -I/opt/homebrew/opt/libomp/include -L/opt/homebrew/opt/libomp/lib -lomp"
export CMAKE_C_FLAGS="-Xpreprocessor -fopenmp -I/opt/homebrew/opt/libomp/include -L/opt/homebrew/opt/libomp/lib -lomp"

cmake .. -DCMAKE_CXX_FLAGS="$CMAKE_CXX_FLAGS" -DCMAKE_C_FLAGS="$CMAKE_C_FLAGS" -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++
make -j