Skip to content

[SYCL] Cannot compile some standard library functions in SYCL mode #15

Closed
@Ruyk

Description

@Ruyk

The following (silly) code:

#include <iostream>
#include <vector>
#include <algorithm>

int main () {
  std::vector<int> foo;

  foo.emplace_back(33);

  std::for_each(std::begin(foo), std::end(foo), [&](int& elem) {
      std::cout << elem << std::endl;
  });

  return foo.size();
};

Fails to compile in SYCL mode:

$ intel_sycl -std=c++11 -fsycl  k.cpp  -lOpenCL -lsycl
In file included from k.cpp:3:
/home/ruyman/Projects/sycl/build/lib/clang/8.0.0/include/sycl_wrappers/algorithm:26:10: error: 
      function 'std::for_each<__gnu_cxx::__normal_iterator<int *, std::vector<int,
      std::allocator<int> > >, (lambda at k.cpp:10:49)>' is used but not defined in this
      translation unit, and cannot be defined in any other translation unit because its type does
      not have linkage
Function for_each(InputIterator first, InputIterator last, Function f);
         ^
k.cpp:10:8: note: used here
  std::for_each(std::begin(foo), std::end(foo), [&](int& elem) {
       ^
1 error generated.
In file included from k.cpp:3:
/home/ruyman/Projects/sycl/build/lib/clang/8.0.0/include/sycl_wrappers/algorithm:26:10: error: 
      function 'std::for_each<__gnu_cxx::__normal_iterator<int *, std::vector<int,
      std::allocator<int> > >, (lambda at k.cpp:10:49)>' is used but not defined in this
      translation unit, and cannot be defined in any other translation unit because its type does
      not have linkage
Function for_each(InputIterator first, InputIterator last, Function f);
         ^
k.cpp:10:8: note: used here
  std::for_each(std::begin(foo), std::end(foo), [&](int& elem) {
       ^
1 error generated.

but works without SYCL on the command line:

$ intel_sycl -std=c++11  k.cpp  -lOpenCL -lsycl
$ 

Is this expected?
Am I correct in understanding that the SYCL mode requires different C++ headers, and that some alias are missing?
Is there any particular reason the normal system headers cannot be used? Note there is no SYCL code in that example.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions