2

I want to include some C++ code in my chapel libs, the first step is getting the Chapel compiler to compile cpp according to this page. However, I'm getting a strange error. My .cpp is

/* Hello World program
 * `/Users/buddha/github/chapel/util/config/compileline --compile` hello.cpp
 * */

//#include<stdio.h>   // just fine
#include<iostream>  // gastro-intestinal distress...

int main()
{
    printf("Hello World\n");
}

But when I run compileline I get an error

 `/Users/buddha/github/chapel/util/config/compileline --compile` hello.cpp 
In file included from hello.cpp:6:
In file included from /Library/Developer/CommandLineTools/usr/include/c++/v1/iostream:38:
In file included from /Library/Developer/CommandLineTools/usr/include/c++/v1/ios:216:
In file included from /Library/Developer/CommandLineTools/usr/include/c++/v1/__locale:18:
In file included from /Library/Developer/CommandLineTools/usr/include/c++/v1/mutex:189:
In file included from /Library/Developer/CommandLineTools/usr/include/c++/v1/__mutex_base:17:
/Library/Developer/CommandLineTools/usr/include/c++/v1/__threading_support:156:1: error: unknown type name 'mach_port_t'
mach_port_t __libcpp_thread_get_port();
^
/Library/Developer/CommandLineTools/usr/include/c++/v1/__threading_support:300:1: error: unknown type name 'mach_port_t'
mach_port_t __libcpp_thread_get_port() {
^
/Library/Developer/CommandLineTools/usr/include/c++/v1/__threading_support:301:12: error: use of undeclared identifier 'pthread_mach_thread_np'
    return pthread_mach_thread_np(pthread_self());
           ^
3 errors generated.

I feel like I'm following the documentation, but I don't see what I'm missing.

Brian Dolan
  • 3,086
  • 2
  • 24
  • 35

2 Answers2

2

Chapel 1.17 (not released yet, but you can try the pre-release master branch) adds util/config/compileline --compile-c++ which works similarly but requests a C++ compiler instead of a C one.

mppf
  • 1,820
  • 9
  • 9
  • 1
    The `--compile-c++` option is (briefly) discussed in the documentation here: https://chapel-lang.org/docs/master/technotes/libraries.html?highlight=compile-c++ – mppf Nov 30 '17 at 17:47
1

You're including <iostream> for std::cout but you're using printf from <cstdio>.

Basically you're mixing not just C++ and chapel but also C++ and C.

Brad
  • 3,839
  • 7
  • 25
MSalters
  • 173,980
  • 10
  • 155
  • 350
  • It's true that I'm mixing c & c++, but the real issue is that `compileline` barfs when you include `c++` headers. – Brian Dolan Nov 29 '17 at 23:08
  • 1
    Well, there's no viable way to use realistic C++ without C++ headers. Chapel itself claims the integration with C (not C++) is already fragile .It might be fair to say that it simply does not work with C++ today. – MSalters Nov 30 '17 at 01:15