xmake-io / xmake-repo

📦 An official xmake package repository
https://xrepo.xmake.io
Apache License 2.0
674 stars 396 forks source link

NVCC compilation failure when having boost and nlohmann_json at the same time #4188

Closed wang-mengdi closed 4 months ago

wang-mengdi commented 4 months ago

Xmake Version

xmake v2.9.2+dev.baeddec3

Operating System Version and Architecture

Windows 10 Pro 10.0.19045 Build 19045, Visual Studio Professional 2022

Describe Bug

Compilation of main.cu fails when both having boost and nlohmann_json in the project. Prompted that cannot find perm_options.

Expected Behavior

Successfully compile

Project Configuration

xmake.lua

add_rules("mode.debug", "mode.release", "mode.releasedbg")

set_languages("cxx17")
add_requires("boost")
add_requires("nlohmann_json")

target("my_project")
    add_rules("plugin.vsxmake.autoupdate")
    set_kind("binary")
    add_headerfiles("src/*.h")
    add_files("src/*.cu")

    add_packages("boost")
    add_packages("nlohmann_json")

src/main.cu

#include <boost/filesystem.hpp>
#include <nlohmann/json.hpp>

int main(int argc, char **argv) {
    return 0;
}

Additional Information and Error Logs

λ xmake -v -D -y
checking for platform ... windows
checking for architecture ... x64
checking for cl.exe ... C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.40.33807\bin\HostX64\x64\cl.exe
checking for Microsoft Visual Studio (x64) version ... 2022
checking for Microsoft C/C++ Compiler (x64) version ... 19.40.33808
checkinfo: cannot runv(zig.exe version), No such file or directory
checking for zig ... no
checkinfo: cannot runv(zig.exe version), No such file or directory
checking for zig ... no
checkinfo: cannot runv(nim.exe --version), No such file or directory
checking for nim ... no
checkinfo: cannot runv(nim.exe --version), No such file or directory
checking for nim ... no
checking for unzip ... ok
checking for git ... ok
checking for gzip ... ok
checking for tar ... ok
checking for ping ... ok
pinging the host(gitlab.com) ... 11 ms
pinging the host(github.com) ... 94 ms
pinging the host(gitee.com) ... 172 ms
git rev-parse HEAD
finding boost from xmake ..
checking for xmake::boost ... boost 1.85.0
finding nlohmann_json from xmake ..
checking for xmake::nlohmann_json ... nlohmann_json v3.11.3
checking for Cuda SDK directory ... C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.4
checking for link.exe ... C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.40.33807\bin\HostX64\x64\link.exe
checking for the linker (ld) ... link.exe
checking for nvcc ... C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.4\bin\nvcc
checking for the cuda compiler (cu) ... nvcc
checking for C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.4\bin\nvcc ... ok
checking for flags (-O3) ... ok
> nvcc "-O3"
checking for flags (-rdc=true) ... ok
> nvcc "-rdc=true"
checking for cl.exe ... C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.40.33807\bin\HostX64\x64\cl.exe
checking for the c++ compiler (cxx) ... cl.exe
[ 50%]: compiling.release src\main.cu
"C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v12.4\\bin\\nvcc" -c -O3 "-IC:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v12.4\\include" --std c++17 -DBOOST_ALL_NO_LIB -IC:\Users\mengdimwang\AppData\Local\.xmake\packages\b\boost\1.85.0\49166697c65042c091ab029ed57c9f24\include -IC:\Users\mengdimwang\AppData\Local\.xmake\packages\n\nlohmann_json\v3.11.3\0204c17d97ae463ab3998f3c82c9ea2d\include -m64 -rdc=true -o build\.objs\my_project\windows\x64\release\src\main.cu.obj src\main.cu
checking for flags (-MD -MF) ... ok
> nvcc "-MD" "-MF" "C:\Users\MENGDI~1\AppData\Local\Temp\.xmake\240528\_15746775EA8A4F10810D02D01105A720"
error: @programdir\core\main.lua:329: @programdir\actions\build\main.lua:148: @programdir\modules\async\runjobs.lua:322: @programdir\modules\private\action\build\object.lua:91: @programdir\modules\core\tools\nvcc.lua:418: C:/Users/mengdimwang/AppData/Local/.xmake/packages/b/boost/1.85.0/49166697c65042c091ab029ed57c9f24/include\boost/filesystem/path.hpp(1489): error C3083: 'filesystem': the symbol to the left of a '::' must be a type
C:/Users/mengdimwang/AppData/Local/.xmake/packages/b/boost/1.85.0/49166697c65042c091ab029ed57c9f24/include\boost/filesystem/path.hpp(1489): error C2039: 'perm_options': is not a member of 'std'
C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.40.33807\include\shared_mutex(26): note: see declaration of 'std'
stack traceback:
    [C]: in function 'error'
    [@programdir\core\base\os.lua:973]:
    [@programdir\modules\core\tools\nvcc.lua:418]: in function 'catch'
    [@programdir\core\sandbox\modules\try.lua:123]: in function 'try'
    [@programdir\modules\core\tools\nvcc.lua:356]:
    [C]: in function 'xpcall'
    [@programdir\core\base\utils.lua:275]:
    [@programdir\core\tool\compiler.lua:278]: in function 'compile'
    [@programdir\modules\private\action\build\object.lua:91]: in function 'script'
    [@programdir\modules\private\action\build\object.lua:122]: in function 'build_object'
    [@programdir\modules\private\action\build\object.lua:147]: in function 'jobfunc'
    [@programdir\modules\async\runjobs.lua:238]:
    [C]: in function 'xpcall'
    [@programdir\core\base\utils.lua:275]: in function 'trycall'
    [@programdir\core\sandbox\modules\try.lua:117]: in function 'try'
    [@programdir\modules\async\runjobs.lua:220]: in function 'cotask'
    [@programdir\core\base\scheduler.lua:406]:

stack traceback:
        [C]: in function 'error'
        @programdir\core\base\os.lua:973: in function 'os.raiselevel'
        (...tail calls...)
        @programdir\core\main.lua:329: in upvalue 'cotask'
        @programdir\core\base\scheduler.lua:406: in function <@programdir\core\base\scheduler.lua:399>
warning: please use package:runtimes() or package:has_runtime() instead of package:config("vs_runtime")
warning: .\xmake.lua:22: cannot match add_files("src\*.cpp") in target(my_project)
star-hengxing commented 4 months ago

I can't reproduce the code, maybe nvcc or msvc bug.

$ nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2022 NVIDIA Corporation
Built on Wed_Sep_21_10:41:10_Pacific_Daylight_Time_2022
Cuda compilation tools, release 11.8, V11.8.89
Build cuda_11.8.r11.8/compiler.31833905_0
$ xmake -rv
[ 50%]: compiling.release src\main.cu
C:\Users\star\scoop\apps\cuda\current\bin\nvcc -c -O3 -IC:\Users\star\scoop\apps\cuda\current\include --std c++17 -DBOOST_ALL_NO_LIB -IC:\Users\star\AppData\Local\.xmake\packages\b\boost\1.85.0\49166697c65042c091ab029ed57c9f24\include -IC:\Users\star\AppData\Local\.xmake\packages\n\nlohmann_json\v3.11.3\af9f1bc1320f4be3a31ec1e2ed3a87ab\include -allow-unsupported-compiler -m64 -rdc=true -o build\.objs\my_project\windows\x64\release\src\main.cu.obj src\main.cu
main.cu
[ 75%]: devlinking.release my_project_gpucode.cu.obj
C:\Users\star\scoop\apps\cuda\current\bin\nvcc -o build\.objs\my_project\windows\x64\release\rules\cuda\devlink\my_project_gpucode.cu.obj build\.objs\my_project\windows\x64\release\src\main.cu.obj -LC:\Users\star\scoop\apps\cuda\current\lib\x64 -LC:\Users\star\AppData\Local\.xmake\packages\b\boost\1.85.0\49166697c65042c091ab029ed57c9f24\lib -llibboost_atomic-mt-s -llibboost_filesystem-mt-s -lcudadevrt -lcudart_static -m64 -dlink
[ 75%]: linking.release my_project.exe
"C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.40.33807\\bin\\HostX64\\x64\\link.exe" -nologo -dynamicbase -nxcompat -machine:x64 -libpath:C:\Users\star\scoop\apps\cuda\current\lib\x64 -libpath:C:\Users\star\AppData\Local\.xmake\packages\b\boost\1.85.0\49166697c65042c091ab029ed57c9f24\lib /opt:ref /opt:icf libboost_atomic-mt-s.lib libboost_filesystem-mt-s.lib cudadevrt.lib cudart_static.lib -out:build\windows\x64\release\my_project.exe build\.objs\my_project\windows\x64\release\src\main.cu.obj build\.objs\my_project\windows\x64\release\rules\cuda\devlink\my_project_gpucode.cu.obj
[100%]: build ok, spent 5.5s
wang-mengdi commented 4 months ago

Worked with forcing:

boost=1.78.0 nlohmann_json=3.10.5

When installing openvdb, xrepo will automatically install boost 1.85.0. So I have to create a local repo and set boost=1.78.0 manually when working with openvdb and nlohmann_json.

star-hengxing commented 4 months ago
add_requireconfs("openvdb.boost", {version = "1.78.0"})