undefined reference to `Mcuda_compiled' in nvhpc

Viewed 18

I have a simple program to test the parallel feature of nvc++ from nvhpc:

#include <iostream>
#include <numeric>
#include <vector>

int main(int argc, char** argv)
{
  std::vector<int> numbers{1, 2, 3, 4, 5, 6, 7};
  int sum = std::accumulate(numbers.begin(),
                            numbers.end(),
                            0,
                            [](int sum, const int num) { return sum + num; }
  );

  std::cout << "sum is " << sum << '\n';
  return 0;
}

I can compile this program in the command line without problem:

nvc++ -g -O0  main.cpp -o main

But when I compile it with CMakeLists.txt it says undefined reference to 'Mcuda_compiled', the CMakeLists.txt is a simple one too:

cmake_minimum_required(VERSION 3.20)
project(nvhpc LANGUAGES CXX)

message(STATUS "C++ compiler is: ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}")

if(CMAKE_CXX_COMPILER_ID STREQUAL NVHPC)
    add_compile_options(-stdpar)
endif()


add_executable(main main.cpp)

The cmake configure gives:

[main] Configuring folder: nvhpc 
[proc] Executing command: path/to/home/software/cmake-3.24.0-linux-x86_64/bin/cmake --no-warn-unused-cli -DCMAKE_CXX_COMPILER=/opt/nvidia/hpc_sdk/Linux_x86_64/22.7/compilers/bin/nvc++ -DCMAKE_VERBOSE_MAKEFILE=ON -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Debug -Spath/to/home/code/oss/nvhpc -Bpath/to/home/code/oss/nvhpc/build_Debug -G Ninja
[cmake] Not searching for unused variables given on the command line.
[cmake] -- The CXX compiler identification is NVHPC 22.7.0
[cmake] -- Detecting CXX compiler ABI info
[cmake] -- Detecting CXX compiler ABI info - done
[cmake] -- Check for working CXX compiler: /opt/nvidia/hpc_sdk/Linux_x86_64/22.7/compilers/bin/nvc++ - skipped
[cmake] -- Detecting CXX compile features
[cmake] -- Detecting CXX compile features - done
[cmake] -- C++ compiler is: NVHPC 22.7.0
[cmake] -- Configuring done
[cmake] -- Generating done
[cmake] -- Build files have been written to: path/to/home/code/oss/nvhpc/build_Debug

and cmake build is:

[main] Building folder: nvhpc 
[build] Starting build
[proc] Executing command: path/to/home/software/cmake-3.24.0-linux-x86_64/bin/cmake --build path/to/home/code/oss/nvhpc/build_Debug --config Debug --target all --
[build] [1/2  50% :: 0.962] /opt/nvidia/hpc_sdk/Linux_x86_64/22.7/compilers/bin/nvc++   -g -O0 -stdpar -MD -MT CMakeFiles/main.dir/main.cpp.o -MF CMakeFiles/main.dir/main.cpp.o.d -o CMakeFiles/main.dir/main.cpp.o -c path/to/home/code/oss/nvhpc/main.cpp
[build] [2/2 100% :: 1.088] : && /opt/nvidia/hpc_sdk/Linux_x86_64/22.7/compilers/bin/nvc++ -g -O0  CMakeFiles/main.dir/main.cpp.o -o main   && :
[build] FAILED: main 
[build] : && /opt/nvidia/hpc_sdk/Linux_x86_64/22.7/compilers/bin/nvc++ -g -O0  CMakeFiles/main.dir/main.cpp.o -o main   && :
[build] /usr/bin/ld: CMakeFiles/main.dir/main.cpp.o:(.init_array+0x20): undefined reference to `Mcuda_compiled'
[build] ninja: build stopped: subcommand failed.
[proc] The command: path/to/home/software/cmake-3.24.0-linux-x86_64/bin/cmake --build path/to/home/code/oss/nvhpc/build_Debug --config Debug --target all -- exited with code: 1 and signal: null
[build] Build finished with exit code 1
0 Answers
Related