2017-05-24 2 views
0

En CMakeList.txt Je ne veux ajouter le -std=g++0x à g ++ des options comme ceci: set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++0x)CMake: Est-il possible d'options de passer à g ++ mais pas nvcc

Cependant tous les CMAKE_CXX_FLAGS sont transmis à nvcc aussi, via le drapeau -Xcompiler (qui est fait automatiquement). Cependant nvcc ne fonctionne pas avec la norme gnu++0x.

est-il un moyen de passer le drapeau à g ++ mais pas nvcc

Le compilateur est spécifié par

if(CUDA_NVCC_HOST_COMPILER) 
    list(APPEND CUDA_NVCC_FLAGS "--compiler-bindir=${CUDA_NVCC_HOST_COMPILER}") 
endif(CUDA_NVCC_HOST_COMPILER) 
+1

Quelle version de CUDA avez-vous? Afaik C++ 11 est pris en charge depuis CUDA 7. – Shadow

+1

vérifier ce https://stackoverflow.com/a/23995391/1418828 – xiaobing

+0

@Shadow nvcc: Pilote de compilateur NVIDIA (R) Cuda Copyright (c) 2005-2013 NVIDIA Corporation Construit le Wed_Jul_17_18: 36: 13_PDT_2013 Outils de compilation Cuda, version 5.5, V5.5.0 – Michael

Répondre

2

De l'FindCUDA documentation:

CUDA_PROPAGATE_HOST_FLAGS (Default ON) 
-- Set to ON to propagate CMAKE_{C,CXX}_FLAGS and their configuration 
    dependent counterparts (e.g. CMAKE_C_FLAGS_DEBUG) automatically to the 
    host compiler through nvcc's -Xcompiler flag. This helps make the 
    generated host code match the rest of the system better. Sometimes 
    certain flags give nvcc problems, and this will help you turn the flag 
    propagation off. This does not affect the flags supplied directly to nvcc 
    via CUDA_NVCC_FLAGS or through the OPTION flags specified through 
    CUDA_ADD_LIBRARY, CUDA_ADD_EXECUTABLE, or CUDA_WRAP_SRCS. Flags used for 
    shared library compilation are not affected by this flag. 

Ainsi, pour fixer votre problème, il suffit de mettre

set(CUDA_PROPAGATE_HOST_FLAGS FALSE) 

près du début de votre script CMake.

+0

@MultipleMonmials votre réponse est utile, mais elle n'a pas résolu le problème. J'ai défini le commutateur '-std' cible par cible en utilisant' target_compile_options ( PUBLIC -std = C++ 11) ' – Michael