I am trying to run a simple project with OpenMP. Since Visual Studio only supports OpenMP 2 so I try to compile and run the project using LLVM clang-cl that comes with Visual Studio 2019. The compilation part seems to be ok, but in the link phase, the linker cannot resolve the OMP functions.
This is my code, there is only 1 file:
#include <stdio.h>
void fn() {
#pragma omp parallel num_threads(5)
{
int i;
#pragma omp task depend(in : i)
for (i = 0; i < 1; i++) {
printf("task\n");
}
}
}
int main() {
printf("hello\n");
fn();
}
My Visual Studio project properties:
Windows SDK version
: 10.0(latest installed version) (10.0.18362.0)Platform toolset
: LLVM (clang-cl)C/c++ - Command Line - Additional Options
:/Zc:twoPhase- -Xclang -fopenmp -v
Linker - Additional Dependencies
:C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\Llvm\lib\libomp.lib
andC:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\Llvm\lib\libiomp5md.lib
Linker - Additional Library Directories
:C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\Llvm\lib
Linker - Command Lines - Additional Options
:-fopenmp -verbose
Error log when running the project
1>lld-link : error : undefined symbol: __kmpc_global_thread_num
1>>>> referenced by D:\Repositories\Test-clang\Test-clang\Source.cpp:4
1>>>> x64\Debug\Source.obj:(void __cdecl fn(void))
1>
1>lld-link : error : undefined symbol: __kmpc_push_num_threads
1>>>> referenced by D:\Repositories\Test-clang\Test-clang\Source.cpp:7
1>>>> x64\Debug\Source.obj:(void __cdecl fn(void))
1>
1>lld-link : error : undefined symbol: __kmpc_fork_call
1>>>> referenced by D:\Repositories\Test-clang\Test-clang\Source.cpp:7
1>>>> x64\Debug\Source.obj:(void __cdecl fn(void))
1>
1>lld-link : error : undefined symbol: __kmpc_omp_task_alloc
1>>>> referenced by D:\Repositories\Test-clang\Test-clang\Source.cpp:10
1>>>> x64\Debug\Source.obj:(.omp_outlined._debug__)
1>
1>lld-link : error : undefined symbol: __kmpc_omp_task_with_deps
1>>>> referenced by D:\Repositories\Test-clang\Test-clang\Source.cpp:10
1>>>> x64\Debug\Source.obj:(.omp_outlined._debug__)
1>Done building project "Test-clang.vcxproj" -- FAILED.
I am using Visual Studio Community 2019. So how do I config the project in order to OpenMP work?
I have also tried to compile like in this answer and it works.
clang -fopenmp -o Source.obj -c Source.cpp
clang -fopenmp -o Source.exe Source.obj
It works for clang-cl too
clang-cl -Xclang -fopenmp -o Source.obj -c Source.cpp
clang-cl /clang:-fopenmp -o Source.exe Source.obj -v
But I don't know how to make Visual Studio build the project using the above way.