nx10 / httpgd

Asynchronous http server graphics device for R.
https://nx10.github.io/httpgd
GNU General Public License v2.0
368 stars 19 forks source link

Mac compilation error #120

Closed adamaltmejd closed 1 year ago

adamaltmejd commented 1 year ago

The Github version does not compile for me. Seems to be related to C++17 not supporting unary_function.

In file included from /Users/adam/.R/packages/BH/include/boost/functional/hash.hpp:6:
/Users/adam/.R/packages/BH/include/boost/container_hash/hash.hpp:132:33: error: no template named 'unary_function' in namespace 'std'; did you mean '__unary_function'?
        struct hash_base : std::unary_function<T, std::size_t> {};
                           ~~~~~^~~~~~~~~~~~~~
                                __unary_function

The CRAN version does compile. I'm compiling with brew llvm, using the following Makevars. Tried compiling with default (no) Makevars, but then I ran into problems with missing libraries.

XC_LOC:=$(shell xcrun --show-sdk-path)
LLVM_LOC:=$(shell brew --prefix llvm)
GCC_LOC:=$(shell brew --prefix gcc)
GETTEXT_LOC:=$(shell brew --prefix gettext)
OMP_LOC:=$(shell brew --prefix libomp)

CC=$(LLVM_LOC)/bin/clang
CXX=$(LLVM_LOC)/bin/clang++
CXX11=$(LLVM_LOC)/bin/clang++
CXX14=$(LLVM_LOC)/bin/clang++
CXX17=$(LLVM_LOC)/bin/clang++
CXX1X=$(LLVM_LOC)/bin/clang++

OBJC=$(LLVM_LOC)/bin/clang
OBJCXX=$(LLVM_LOC)/bin/clang++

CFLAGS=-g -O2 -Wall -pedantic -std=gnu99 -mtune=native -pipe
CXXFLAGS=-g -O2 -Wall -pedantic -std=c++11 -mtune=native -pipe
# X11, libtiff and jpeg-turbo needs to be included above for cairo/ragg/jpeg/httpgd
LDFLAGS=-L"$(LLVM_LOC)/lib" -L"$(GETTEXT_LOC)/lib"  -L/opt/homebrew/opt/libpng/lib -L/opt/homebrew/opt/libtiff/lib -L/opt/homebrew/opt/jpeg-turbo/lib -Wl,-rpath,$(LLVM_LOC)/lib --sysroot="$(XC_LOC)" -lomp
CPPFLAGS=-I"$(GETTEXT_LOC)/include" -I"$(LLVM_LOC)/include"  -I/opt/homebrew/opt/libpng/include -I/opt/homebrew/opt/libtiff/include -I/opt/homebrew/opt/jpeg-turbo/include -isysroot "$(XC_LOC)" -I"$(OMP_LOC)/include" -Xclang -fopenmp

FC=$(GCC_LOC)/bin/gfortran
F77=$(GCC_LOC)/bin/gfortran
FLIBS=-L$(GCC_LOC)/lib/gcc/10/ -lm
nx10 commented 1 year ago

Hi,

Your Makevars file seems to not include the c++ standard.

CXX11=$(LLVM_LOC)/bin/clang++ std=c++11
CXX14=$(LLVM_LOC)/bin/clang++ std=c++14
CXX17=$(LLVM_LOC)/bin/clang++ std=c++17

(Reference: https://clang.llvm.org/cxx_status.html)

Let me know if this fixes your error

nx10 commented 1 year ago

Also please post the compile log (including error) if this does not work.

nx10 commented 1 year ago

Also: No Makevars is not the default. The configure script will generate a Makevars file on install.

adamaltmejd commented 1 year ago

Thanks! I had set CXXFLAGS=-g -O2 -Wall -pedantic -std=c++11 -mtune=native -pipe so was using std=c++11 for all versions. Changing it to

CXXFLAGS=-g -O2 -Wall -pedantic -std=c++11 -mtune=native -pipe
CXX11FLAGS=-g -O2 -Wall -pedantic -std=c++11 -mtune=native -pipe
CXX14FLAGS=-g -O2 -Wall -pedantic -std=c++14 -mtune=native -pipe
CXX17FLAGS=-g -O2 -Wall -pedantic -std=c++17 -mtune=native -pipe

did not help. Same error. Attaching the whole log at the end of this message.

Right, I meant no custom ~/.R/Makevars file. When I remove the file I instead get this error

ld: library not found for -lpng
clang: error: linker command failed with exit code 1 (use -v to see invocation)

even though pkg-config yield a path:

❯ pkg-config --cflags libpng
-I/opt/homebrew/Cellar/libpng/1.6.38/include/libpng16

guessing its because default uses non-homebrew pkg-config?

Full compile log:

> remotes::install_github("nx10/httpgd", force = TRUE)
Using github PAT from envvar GITHUB_PAT
Downloading GitHub repo nx10/httpgd@HEAD
   checking for file ‘/private/var/folders/b9/b7hn3x0x7pv_1q51k3xmw6m40000gn/T/RtmpCfrJxg/remotesc6d733109c8d/nx10-httpgd-a2572dc/DESCRIPT✔  checking for file ‘/private/var/folders/b9/b7hn3x0x7pv_1q51k3xmw6m40000gn/T/RtmpCfrJxg/remotesc6d733109c8d/nx10-httpgd-a2572dc/DESCRIPTION’
─  preparing ‘httpgd’:
✔  checking DESCRIPTION meta-information ...
─  cleaning src
─  checking for LF line-endings in source and make files and shell scripts
─  checking for empty or unneeded directories
─  building ‘httpgd_2.0.0.9000.tar.gz’
   Warning: file 'httpgd/cleanup' did not have execute permissions: corrected

Installing package into ‘/Users/adam/.R/packages’
(as ‘lib’ is unspecified)
* installing *source* package ‘httpgd’ ...
** using staged installation
** libs
rm -f httpgd.so cpp11.o httpgd.o httpgd_rng.o httpgd_webserver.o unigd_impl.o
/opt/homebrew/opt/llvm/bin/clang++ -std=gnu++17 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -Ilib -DBOOST_NO_AUTO_PTR -DFMT_HEADER_ONLY -I'/Users/adam/.R/packages/cpp11/include' -I'/Users/adam/.R/packages/BH/include' -I'/Users/adam/.R/packages/unigd/include' -I"/opt/homebrew/opt/gettext/include" -I"/opt/homebrew/opt/llvm/include"  -I/opt/homebrew/opt/libpng/include -I/opt/homebrew/opt/libtiff/include -I/opt/homebrew/opt/jpeg-turbo/include -isysroot "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk" -I"/opt/homebrew/opt/libomp/include" -Xclang -fopenmp   -fPIC  -g -O2 -Wall -pedantic -std=c++17 -mtune=native -pipe -c cpp11.cpp -o cpp11.o
/opt/homebrew/opt/llvm/bin/clang++ -std=gnu++17 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -Ilib -DBOOST_NO_AUTO_PTR -DFMT_HEADER_ONLY -I'/Users/adam/.R/packages/cpp11/include' -I'/Users/adam/.R/packages/BH/include' -I'/Users/adam/.R/packages/unigd/include' -I"/opt/homebrew/opt/gettext/include" -I"/opt/homebrew/opt/llvm/include"  -I/opt/homebrew/opt/libpng/include -I/opt/homebrew/opt/libtiff/include -I/opt/homebrew/opt/jpeg-turbo/include -isysroot "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk" -I"/opt/homebrew/opt/libomp/include" -Xclang -fopenmp   -fPIC  -g -O2 -Wall -pedantic -std=c++17 -mtune=native -pipe -c httpgd.cpp -o httpgd.o
In file included from httpgd.cpp:21:
In file included from /Users/adam/.R/packages/BH/include/boost/optional.hpp:15:
In file included from /Users/adam/.R/packages/BH/include/boost/optional/optional.hpp:28:
In file included from /Users/adam/.R/packages/BH/include/boost/core/addressof.hpp:17:
In file included from /Users/adam/.R/packages/BH/include/boost/config.hpp:48:
/Users/adam/.R/packages/BH/include/boost/config/stdlib/libcpp.hpp:98:11: warning: 'BOOST_NO_AUTO_PTR' macro redefined [-Wmacro-redefined]
#  define BOOST_NO_AUTO_PTR
          ^
<command line>:2:9: note: previous definition is here
#define BOOST_NO_AUTO_PTR 1
        ^
In file included from httpgd.cpp:21:
In file included from /Users/adam/.R/packages/BH/include/boost/optional.hpp:15:
In file included from /Users/adam/.R/packages/BH/include/boost/optional/optional.hpp:38:
/Users/adam/.R/packages/BH/include/boost/type_traits/has_nothrow_constructor.hpp:27:84: warning: builtin __has_nothrow_constructor is deprecated; use __is_nothrow_constructible instead [-Wdeprecated-builtins]
template <class T> struct has_nothrow_constructor : public integral_constant<bool, BOOST_HAS_NOTHROW_CONSTRUCTOR(T)>{};
                                                                                   ^
/Users/adam/.R/packages/BH/include/boost/type_traits/intrinsics.hpp:199:48: note: expanded from macro 'BOOST_HAS_NOTHROW_CONSTRUCTOR'
#     define BOOST_HAS_NOTHROW_CONSTRUCTOR(T) (__has_nothrow_constructor(T) && is_default_constructible<T>::value)
                                               ^
In file included from httpgd.cpp:21:
In file included from /Users/adam/.R/packages/BH/include/boost/optional.hpp:15:
In file included from /Users/adam/.R/packages/BH/include/boost/optional/optional.hpp:47:
In file included from /Users/adam/.R/packages/BH/include/boost/type_traits/is_nothrow_move_assignable.hpp:16:
/Users/adam/.R/packages/BH/include/boost/type_traits/has_nothrow_assign.hpp:65:7: warning: builtin __has_nothrow_assign is deprecated; use __is_nothrow_assignable instead [-Wdeprecated-builtins]
      BOOST_HAS_NOTHROW_ASSIGN(T)
      ^
/Users/adam/.R/packages/BH/include/boost/type_traits/intrinsics.hpp:205:43: note: expanded from macro 'BOOST_HAS_NOTHROW_ASSIGN'
#     define BOOST_HAS_NOTHROW_ASSIGN(T) (__has_nothrow_assign(T) && !is_volatile<T>::value && is_assignable<T&, const T&>::value)
                                          ^
In file included from httpgd.cpp:23:
In file included from ./httpgd_webserver.h:9:
In file included from lib/crow.h:228:
In file included from /Users/adam/.R/packages/BH/include/boost/functional/hash.hpp:6:
/Users/adam/.R/packages/BH/include/boost/container_hash/hash.hpp:132:33: error: no template named 'unary_function' in namespace 'std'; did you mean '__unary_function'?
        struct hash_base : std::unary_function<T, std::size_t> {};
                           ~~~~~^~~~~~~~~~~~~~
                                __unary_function
/opt/homebrew/opt/llvm/bin/../include/c++/v1/__functional/unary_function.h:46:1: note: '__unary_function' declared here
using __unary_function = __unary_function_keep_layout_base<_Arg, _Result>;
^
In file included from httpgd.cpp:23:
In file included from ./httpgd_webserver.h:9:
lib/crow.h:713:9: warning: variable 'i' set but not used [-Wunused-but-set-variable]
    int i=0;
        ^
In file included from httpgd.cpp:23:
In file included from ./httpgd_webserver.h:9:
In file included from lib/crow.h:6369:
In file included from /Users/adam/.R/packages/BH/include/boost/algorithm/string.hpp:23:
In file included from /Users/adam/.R/packages/BH/include/boost/algorithm/string/split.hpp:16:
In file included from /Users/adam/.R/packages/BH/include/boost/algorithm/string/iter_find.hpp:27:
In file included from /Users/adam/.R/packages/BH/include/boost/algorithm/string/find_iterator.hpp:24:
In file included from /Users/adam/.R/packages/BH/include/boost/algorithm/string/detail/find_iterator.hpp:18:
In file included from /Users/adam/.R/packages/BH/include/boost/function.hpp:30:
In file included from /Users/adam/.R/packages/BH/include/boost/function/detail/prologue.hpp:17:
In file included from /Users/adam/.R/packages/BH/include/boost/function/function_base.hpp:22:
/Users/adam/.R/packages/BH/include/boost/type_traits/has_trivial_copy.hpp:34:4: warning: builtin __has_trivial_copy is deprecated; use __is_trivially_copyable instead [-Wdeprecated-builtins]
   BOOST_HAS_TRIVIAL_COPY(T) BOOST_TT_TRIVIAL_CONSTRUCT_FIX
   ^
/Users/adam/.R/packages/BH/include/boost/type_traits/intrinsics.hpp:190:41: note: expanded from macro 'BOOST_HAS_TRIVIAL_COPY'
#     define BOOST_HAS_TRIVIAL_COPY(T) (__has_trivial_copy(T) && !is_reference<T>::value)
                                        ^
In file included from httpgd.cpp:23:
In file included from ./httpgd_webserver.h:9:
In file included from lib/crow.h:6369:
In file included from /Users/adam/.R/packages/BH/include/boost/algorithm/string.hpp:23:
In file included from /Users/adam/.R/packages/BH/include/boost/algorithm/string/split.hpp:16:
In file included from /Users/adam/.R/packages/BH/include/boost/algorithm/string/iter_find.hpp:27:
In file included from /Users/adam/.R/packages/BH/include/boost/algorithm/string/find_iterator.hpp:24:
In file included from /Users/adam/.R/packages/BH/include/boost/algorithm/string/detail/find_iterator.hpp:18:
In file included from /Users/adam/.R/packages/BH/include/boost/function.hpp:30:
In file included from /Users/adam/.R/packages/BH/include/boost/function/detail/prologue.hpp:17:
In file included from /Users/adam/.R/packages/BH/include/boost/function/function_base.hpp:23:
/Users/adam/.R/packages/BH/include/boost/type_traits/has_trivial_destructor.hpp:30:86: warning: builtin __has_trivial_destructor is deprecated; use __is_trivially_destructible instead [-Wdeprecated-builtins]
template <typename T> struct has_trivial_destructor : public integral_constant<bool, BOOST_HAS_TRIVIAL_DESTRUCTOR(T)>{};
                                                                                     ^
/Users/adam/.R/packages/BH/include/boost/type_traits/intrinsics.hpp:196:47: note: expanded from macro 'BOOST_HAS_TRIVIAL_DESTRUCTOR'
#     define BOOST_HAS_TRIVIAL_DESTRUCTOR(T) (__has_trivial_destructor(T)  && is_destructible<T>::value)
                                              ^
In file included from httpgd.cpp:23:
In file included from ./httpgd_webserver.h:9:
lib/crow.h:8718:21: warning: variable 'totalBlocksBefore' set but not used [-Wunused-but-set-variable]
                int totalBlocksBefore = 0;
                    ^
7 warnings and 1 error generated.
make: *** [httpgd.o] Error 1
ERROR: compilation failed for package ‘httpgd’
* removing ‘/Users/adam/.R/packages/httpgd’
* restoring previous ‘/Users/adam/.R/packages/httpgd’
Warning message:
In i.p(...) :
  installation of package ‘/var/folders/b9/b7hn3x0x7pv_1q51k3xmw6m40000gn/T//RtmpCfrJxg/filec6d72c024bf1/httpgd_2.0.0.9000.tar.gz’ had non-zero exit status
nx10 commented 1 year ago

Interesting. What version of llvm do you use? Would it be possible for you to update if it's an older version?

nx10 commented 1 year ago

I have removed the link to libpng and downgraded to c++14 (this was planned for a while and should hopefully result in more stable builds over all).

Please download from GitHub again and let me know if it works.

adamaltmejd commented 1 year ago

Tried both with my custom Makevars, and with no Makevars in ~/.R. And it works! Thanks for the quick fix!

I'm using llvm 15.0.1.