Closed basvandijk closed 5 years ago
I tried setting the C++ standard to c++11 but that didn't help. Maybe there's a bug in Cabal or GHC that causes the -std=c++11
flag not to be passed on to the compiler compiling files generated with addForeignFile.
Since the documentation of addForeignFile
mentions:
the flags passed as part of -optc will be also applied to the C compiler invocation
that will compile them.
I tried forcing clang
to use C++ (-xc++
) and the C++11 standard (-std=c++11
):
$ cabal build --ghc-options="-optc-xc++ -optc-std=c++11"
Preprocessing library for inline-c-cpp-0.2.2.1..
Building library for inline-c-cpp-0.2.2.1..
ignoring (possibly broken) abi-depends field for packages
Preprocessing test suite 'tests' for inline-c-cpp-0.2.2.1..
Building test suite 'tests' for inline-c-cpp-0.2.2.1..
Linking dist/build/tests/tests ...
clang-5.0: warning: argument unused during compilation: '-nopie' [-Wunused-command-line-argument]
In file included from /var/folders/8m/tqlhlzrd4lsbb8r3j9zw7wsw0000gn/T/ghc19845_0/ghc_1.c:1:0: error:
In file included from /nix/store/nc6wvwy7skyz2nsh7hyhgshg5a0y56j5-ghc-8.4.3/lib/ghc-8.4.3/include/Rts.h:29:0: error:
/nix/store/nc6wvwy7skyz2nsh7hyhgshg5a0y56j5-ghc-8.4.3/lib/ghc-8.4.3/include/Stg.h:29:3: error:
error: __STDC_VERSION__ does not advertise C99 or later
|
29 | # error __STDC_VERSION__ does not advertise C99 or later
| ^
# error __STDC_VERSION__ does not advertise C99 or later
^
1 error generated.
`cc' failed in phase `C Compiler'. (Exit code: 1)
Note that this condition is likely failing because __STDC_VERSION__
is undefined when compiling in C++ mode.
Maybe the condition needs to support C++ as in:
#if !(__STDC_VERSION__ >= 199901L || __cplusplus >= 201103L)
# error __STDC_VERSION__ does not advertise C99 or later nor does __cplusplus advertise C++11 or later
#endif
Of course I can just define __STDC_VERSION__
myself but that leads to all other kinds of errors:
$ cabal build --ghc-options="-optc-xc++ -optc-std=c++11 -optc-D__STDC_VERSION__=199901L"
Preprocessing library for inline-c-cpp-0.2.2.1..
Building library for inline-c-cpp-0.2.2.1..
ignoring (possibly broken) abi-depends field for packages
Preprocessing test suite 'tests' for inline-c-cpp-0.2.2.1..
Building test suite 'tests' for inline-c-cpp-0.2.2.1..
Linking dist/build/tests/tests ...
clang-5.0: warning: argument unused during compilation: '-nopie' [-Wunused-command-line-argument]
In file included from /var/folders/8m/tqlhlzrd4lsbb8r3j9zw7wsw0000gn/T/ghc20020_0/ghc_1.c:1:0: error:
In file included from /nix/store/nc6wvwy7skyz2nsh7hyhgshg5a0y56j5-ghc-8.4.3/lib/ghc-8.4.3/include/Rts.h:29:0: error:
In file included from /nix/store/nc6wvwy7skyz2nsh7hyhgshg5a0y56j5-ghc-8.4.3/lib/ghc-8.4.3/include/Stg.h:222:0: error:
In file included from /nix/store/nc6wvwy7skyz2nsh7hyhgshg5a0y56j5-ghc-8.4.3/lib/ghc-8.4.3/include/stg/Types.h:37:0: error:
In file included from /nix/store/3kiymx2x7isvafzlqxv1rxn8arwvj8bw-clang-wrapper-5.0.2/resource-root/include/inttypes.h:30:0: error:
/nix/store/nbcf9myn3rs5i0ic303wjmgr3jx1a934-Libsystem-osx-10.11.6/include/inttypes.h:251:35: error:
error: expected ')'
|
251 | strtoimax(const char * __restrict __nptr,
| ^
strtoimax(const char * __restrict __nptr,
...
So I guess -optc-xc++
is not really the way to go.
Hello again @basvandijk, fancy seeing you here 😄
Friendly reminder that this is identical to https://github.com/LumiGuide/haskell-opencv/issues/104
Note I'm using Nix on OS X.