Skip to content
This repository was archived by the owner on Jan 26, 2024. It is now read-only.
This repository was archived by the owner on Jan 26, 2024. It is now read-only.

error: multiple definitions of sycl::helpers::negative_distance #61

@domantasjurkus

Description

@domantasjurkus

I am trying to import <sycl/execution_policy> into my main.cpp file as well as a separate lib.cpp file, however I keep getting an internal SyclParallelSTL naming clash:

[ 80%] Building CXX object CMakeFiles/main.dir/main.cpp.o
[100%] Linking CXX executable main
liblib.a(lib.cpp.o):(.bss+0x0): multiple definition of `sycl::helpers::negative_distance'
CMakeFiles/main.dir/main.cpp.o:(.bss+0x0): first defined here
collect2: error: ld returned 1 exit status
CMakeFiles/main.dir/build.make:97: recipe for target 'main' failed
make[2]: *** [main] Error 1
CMakeFiles/Makefile2:100: recipe for target 'CMakeFiles/main.dir/all' failed
make[1]: *** [CMakeFiles/main.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

The execution policy source code has a #ifndef __SYCL_EXECUTION_POLICY__ import guard, so I assume I can #include <sycl/execution_policy> in multiple files? The basic setup to reproduce the problem is below.

CMakeLists.txt:

# ...
# SYCL setup
#...
add_executable(main ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp)
add_library (lib lib.cpp)
target_link_libraries(main PRIVATE lib)
add_sycl_to_target(main ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp)

main.cpp:

#include <vector>

#include <sycl/execution_policy>
#include <experimental/algorithm>

#include "lib.h"

int main() {
    std::vector<int> v = {3, 1, 5, 6};
    sycl::sycl_execution_policy<class sort> par;
    std::experimental::parallel::sort(par, v.begin(), v.end());

    reduction();

    return 0;
}

lib.cpp:

#include <sycl/execution_policy>
#include <experimental/algorithm>

void reduction() {
    std::vector<int> v = {3, 1, 5, 6};
    sycl::sycl_execution_policy<class reduce> par;
    int result = std::experimental::parallel::reduce(par, v.begin(), v.end(), 0, [](int acc, int e) { return acc + e; });
    std::cout << result << std::endl;
}

The corresponding problem can be found on this line. What I've tried is to add extern in front of the class definition, but that leads to negative_distance being undefined.

Any advice?

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions