I am trying to make YCM plugin of vim to work for CUDA source files.
Since CUDA is basically C++ syntax with some extensions, I thought that editing the standard '.ycm_extra_conf.py' file would be sufficient. I changed the line
SOURCE_EXTENSIONS = [ '.cpp', '.cxx', '.cc', '.c', '.m', '.mm']
to
SOURCE_EXTENSIONS = [ '.cpp', '.cxx', '.cc', '.c', '.m', '.mm', '.cu' ]
and the line
return extension in [ '.h', '.hxx', '.hpp', '.hh']
to
return extension in [ '.h', '.hxx', '.hpp', '.hh', '.cuh' ]
But YCM does not work, it does not even ask me to use the config file as it should in the beginning. In normal C/C++ source files YCM works correct.
Any ideas what is missing?
I got this working by the following steps:
First remap .cu files to cpp in your .vimrc
" Map cuda files to c++ so that Ycm can parse
autocmd BufNewFile,BufRead *.cu set filetype=cpp
Next update .ycm_extra_conf.py with flags for Clang CUDA support.
import os
import ycm_core
includes = ['-I/opt/cudatoolkit/6.5/include', '-I/your/includes/here']
common = ['-std=c++11',
'-DUSE_CLANG_COMPLETER',
'-I/usr/local/include',
'-I/usr/include/clang/3.5/include',
'-I/usr/include/x86_64-linux-gnu',
'-I/usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/include',
'-I/usr/include',
'-I/usr/include/c++/4.9']
cpp_flags = ['-x', 'c++',]
# http://llvm.org/docs/CompileCudaWithLLVM.html
cuda_flags = ['-x', 'cuda', '--cuda-gpu-arch=sm_35']
def FlagsForFile( filename ):
compile_flags = cpp_flags
if filename.endswith('.cu'):
compile_flags = cuda_flags
compile_flags.extend(common)
compile_flags.extend(includes)
return {
'flags': compile_flags,
'do_cache': True
}
Finally you need to add in a header file to your .cu file so Ycm can parse the CUDA builtins. This file, cuda_builtin_vars.h was in my local Clang build.
#ifdef __clang__
#include <cuda_builtin_vars.h>
#endif
Even with all this, the Clang parser still doesn't seem to accept that my __global__ functions are actually __global__ (even though it can handle the kernel call syntax with any problems), so I usually wrap them with #ifndef __clang__
Sources:
https://github.com/Valloric/YouCompleteMe/issues/1766
http://llvm.org/docs/CompileCudaWithLLVM.html
https://github.com/Microsoft/clang-1/blob/master/test/SemaCUDA/kernel-call.cu
Related
i'm on nixos 20.09 and try to build godot-3.2.3-stable with support for C#.
I'm following the instruction on the godot docs, which states that one first has to enable the mono module and then generate the mono-glue. I tried to adapt the default.nix of the NixOS/nixpkgs repository to my needs but failed.
What i tried is to first generate the glue like mentioned in the godot docs and then compile with C# support.
with import <nixpkgs> {};
let options = {
pulseaudio = true;
};`
in
stdenv.mkDerivation rec {
name = "tools_";
version = "3.2.3";
src = ./godot-3.2.3-stable.tar.gz;
nativeBuildInputs = with pkgs; [ pkg-config ];
buildInputs = with pkgs; [ scons mono6 msbuild dotnetPackages.Nuget xorg.libX11 xorg.libXcursor
xorg.libXinerama xorg.libXrandr xorg.libXrender xorg.libXi xorg.libXext
xorg.libXfixes freetype openssl alsaLib libpulseaudio libGLU zlib yasm
];
patches = [
./pkg_config_additions.patch
./dont_clobber_environment.patch
];
enableParallelBuilding = true;
sconsFlags = "target=release_debug platform=x11 tools=yes module_mono_enabled=yes mono_glue=no";
preConfigure = ''
sconsFlags+=" ${lib.concatStringsSep " " (lib.mapAttrsToList (k: v: "${k}=${builtins.toJSON v}") options)}"
'';
outputs = [ "out" ];
installPhase = ''
mkdir -p "$out/bin"
cp bin/godot.* $out/bin/godot
'';
}
But if i run this with nix-build i get the error:
Checking for `thread_local` support... supported
Mono root directory not found. Using pkg-config instead
/nix/store/vnyfysaya7sblgdyvqjkrjbrb0cy11jf-bash-4.4-p23/bin/sh: pkg-config: command not found
OSError: 'pkg-config monosgen-2 --libs-only-L' exited 127:
File "/build/godot-3.2.3-stable/SConstruct", line 617:
SConscript("modules/SCsub")
File "/nix/store/ypb1lsl610mw3s76p232hjmnhwakjb06-scons-4.0.1/lib/python3.8/site-packages/SCons/Script/SConscript.py", line 661:
return method(*args, **kw)
File "/nix/store/ypb1lsl610mw3s76p232hjmnhwakjb06-scons-4.0.1/lib/python3.8/site-packages/SCons/Script/SConscript.py", line 598:
return _SConscript(self.fs, *files, **subst_kw)
File "/nix/store/ypb1lsl610mw3s76p232hjmnhwakjb06-scons-4.0.1/lib/python3.8/site-packages/SCons/Script/SConscript.py", line 287:
exec(compile(scriptdata, scriptname, 'exec'), call_stack[-1].globals)
File "/build/godot-3.2.3-stable/modules/SCsub", line 21:
SConscript(name + "/SCsub") # Built-in.
File "/nix/store/ypb1lsl610mw3s76p232hjmnhwakjb06-scons-4.0.1/lib/python3.8/site-packages/SCons/Script/SConscript.py", line 661:
return method(*args, **kw)
File "/nix/store/ypb1lsl610mw3s76p232hjmnhwakjb06-scons-4.0.1/lib/python3.8/site-packages/SCons/Script/SConscript.py", line 598:
return _SConscript(self.fs, *files, **subst_kw)
File "/nix/store/ypb1lsl610mw3s76p232hjmnhwakjb06-scons-4.0.1/lib/python3.8/site-packages/SCons/Script/SConscript.py", line 287:
exec(compile(scriptdata, scriptname, 'exec'), call_stack[-1].globals)
File "/build/godot-3.2.3-stable/modules/mono/SCsub", line 34:
mono_configure.configure(env, env_mono)
File "/build/godot-3.2.3-stable/modules/mono/build_scripts/mono_configure.py", line 351:
tmpenv.ParseConfig("pkg-config monosgen-2 --libs-only-L")
File "/nix/store/ypb1lsl610mw3s76p232hjmnhwakjb06-scons-4.0.1/lib/python3.8/site-packages/SCons/Environment.py", line 1612:
return function(self, self.backtick(command))
File "/nix/store/ypb1lsl610mw3s76p232hjmnhwakjb06-scons-4.0.1/lib/python3.8/site-packages/SCons/Environment.py", line 599:
raise OSError("'%s' exited %d" % (command, status))
builder for '/nix/store/acpp99hr7q92a7j1bk2nga00n4v8za7z-tools_.drv' failed with exit code 2
error: build of '/nix/store/acpp99hr7q92a7j1bk2nga00n4v8za7z-tools_.drv' failed
I'm sorry but i'm totally lost there, since this is my first derivation i am trying to build. I have already searched the nixpkgs manual but couldn't solve my problem. Probably due to the fact that i'm not exactly sure what i am looking for. Also i was asking myself if this is going to work anyways since the godot docs state that after generating the glue one has to:
### Build binaries normally
# Editor
scons p=x11 target=release_debug tools=yes module_mono_enabled=yes
and i don't know if i could then simply rerun the above mentioned derivation with the appropriate sconsFlags or if and how i could simply write one file which does the same job done.
If someone could help me and point me in the right direction so that i at least would know what i exactly have to search for i would very much appreciate it. Thanks in advance.
When attempting to install the Octave io package on Windows 7 I receive the following error:
>> pkg install io-2.4.12.tar.gz
0 [main] us 0 init_cheap: VirtualAlloc pointer is null, Win32 error 487
AllocationBase 0x0, BaseAddress 0x60EA0000, RegionSize 0x190000, State 0x10000
C:\Octave\Octave-4.2.0\bin\perl.exe: *** Couldn't reserve space for cygwin's heap, Win32 error 0
warning: doc_cache_create: unusable help text found in file 'getxmlattv'
For information about changes from previous versions of the io package, run 'news io'.
>>
I have a read a few other similar questions but have been unable to find an answer, and I do not understand the error message in all honesty. I understand cygwin in a Unix-like interface for windows, but that is about it. I have tried running as administrator, deleting all temp files, restarting etc. but cannot get the pkg to install successfully. Any ideas?
The referenced file 'getxmlattv' is just a function and not a text file as described and cannot be run as a standalone file:
function [retval] = getxmlattv (xmlnode, att)
retval = '';
## Get end of first tag
iend = index (xmlnode, ">");
## Get start of value string. Concat '="' to ensure minimal ambiguity
vals = index (xmlnode, [att '="']);
if (vals == 0)
## Attribute not in current tag
return
elseif (vals)
vals = vals + length (att) + 2;
vale = regexp (xmlnode(vals:end), '"[ >/]');
if (! isempty (vale))
retval = xmlnode(vals:vals+vale-2);
endif
endif
endfunction
I don't see how this is of any use.
For the windows version of octave the packages are already available in the installer
https://wiki.octave.org/Octave_for_Microsoft_Windows
so you don't need to install io from source package. Just re-run the installer
if you missed it.
Please note that the error message is misleading as you are not using the
cygwin version of octave but msys/mingw one; that is based on a modified
version of the cygwin1.dll where they forgot to update the messages:
$ strings msys-1.0.dll | grep cygwin
...
%P: *** Couldn't reserve space for cygwin's heap (%p <%p>) in child, %E
...
I've encountered a problem trying to set up a C++ project on my Mac (Yosemite with Xcode 6) using CMake with Unix style Makefiles and vim with the youcompleteme plugin (I'm a Linux veteran and Mac newbie so I prefer this setup to Xcode). The code builds and runs but youcompleteme throws some bogus errors which I think boil down to it not being able to find the <cstdint> header.
I've just tried it on Linux too, and had the same problem.
I've configured .ycm_extra_conf.py to use a compile_commands.json generated by cake. The "command" lines in compile_commands.json use these flags:
"command": "/usr/bin/c++ -std=c++11 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk -F/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/System/Library/Frameworks -I/usr/local/include -I/Users/tony/Dev/cow/jni -I/Users/tony/Library/Frameworks/SDL2.framework/Headers -Wall -Wextra -Wunused -F/Users/tony/Library/Frameworks -o ...
There doesn't seem to be an explicit reference there to any directory containing stdint as a direct parent.
Is there a way I can get youcompleteme to do its stuff with libclang in such a way that it can find the directory implicitly, which seems to work when running c++ on the command line? Or what's the best way to get cmake to add an appropriate system header path without hardwiring it? I want my CMakeLists.txt to be portable and to be able to cope with toolchain upgrades.
My .ycm_extra_conf.py was pretty much a copy of the supplied example modified slightly to find compile_commands.json where I put it.
As #ladislas said, YCM needs to be explicitly pointed to all relevant include directories as libclang won't use the same implicit location a normal compiler driver invocation (i.e. clang++ from the command line) would use.
What I usually do, on OSX, is to let YCM know about Xcode's libc++ headers with something like (in .ycm_extra_conf.py):
import os
import ycm_core
import subprocess
xcode_cpp11headers = subprocess.Popen("xcode-select -p", stdout = subprocess.PIPE, shell=True).communicate()[0].rstrip('\n') + '/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1'
.
.
flags = [
.
.
'-isystem',
xcode_cpp11headers,
.
.
]
The "xcode_cpp11headers" variable is populated with the proper path depending on the location of your current Xcode's installation, and you can change it accordingly if you want to use say the commandline-tools version of libc++ (i.e. the includes are in /Library/Developer/CommandLineTools/usr/include/c++/v1) or a source distribution of libc++ if you have compiled your own.
Of course this is platform dependant and either you provide a platform specific .ycm_extra_conf.py alongside your project, or you can populate that variable differently with some extra python code accordingly to the current platform.
You must add all the paths where YCM needs to look for your sources, libraries, and so on.
It does not work recursively, so it's a little bit cumbersome at first but is should not change once set for your project.
As an example, here is mine for an Arduino project :
https://github.com/ladislas/Bare-Arduino-Project/blob/master/.ycm_extra_conf.py#L21
Hope this helps!
EDIT - 2015/01/08
The solution of #abigagli is very elegant! I too use something like this to parse my lib directory and look for .h files to add their path to flags.
Here it is if it can be useful :) http://git.io/IiR1JA
As I found out from the above answers, YCM needs to be told the compiler's system include paths which are usually implicit in other ways of using the compiler. I added a function GetSystemIncludePaths() to .ycm_extra_conf.py to discover and cache these paths portably. Here's the full file with comments and irrelevant content of flags list snipped. The original is Copyright (C) 2014 Google Inc with a GPL2+ licence:
import subprocess, os
import ycm_core
flags = []
def DirectoryOfThisScript():
return os.path.dirname( os.path.abspath( __file__ ) )
compilation_database_folder = os.path.abspath(
os.path.join(DirectoryOfThisScript(), 'build-make'))
if os.path.exists( compilation_database_folder ):
database = ycm_core.CompilationDatabase( compilation_database_folder )
else:
database = None
SOURCE_EXTENSIONS = [ '.cpp', '.cxx', '.cc', '.c', '.m', '.mm' ]
def MakeRelativePathsInFlagsAbsolute( flags, working_directory ):
if not working_directory:
return list( flags )
new_flags = []
make_next_absolute = False
path_flags = [ '-isystem', '-I', '-iquote', '--sysroot=' ]
for flag in flags:
new_flag = flag
if make_next_absolute:
make_next_absolute = False
if not flag.startswith( '/' ):
new_flag = os.path.join( working_directory, flag )
for path_flag in path_flags:
if flag == path_flag:
make_next_absolute = True
break
if flag.startswith( path_flag ):
path = flag[ len( path_flag ): ]
new_flag = path_flag + os.path.join( working_directory, path )
break
if new_flag:
new_flags.append( new_flag )
return new_flags
def IsHeaderFile( filename ):
extension = os.path.splitext( filename )[ 1 ]
return extension in [ '.h', '.hxx', '.hpp', '.hh' ]
def GetCompilationInfoForFile( filename ):
if IsHeaderFile( filename ):
basename = os.path.splitext( filename )[ 0 ]
for extension in SOURCE_EXTENSIONS:
replacement_file = basename + extension
if os.path.exists( replacement_file ):
compilation_info = database.GetCompilationInfoForFile(
replacement_file )
if compilation_info.compiler_flags_:
return compilation_info
return None
return database.GetCompilationInfoForFile( filename )
def GetSystemIncludePaths():
cache = os.path.join(DirectoryOfThisScript(), ".ycm_sys_incs")
if os.path.exists(cache):
fp = open(cache, 'r')
flags = fp.readlines()
fp.close()
flags = [s.strip() for s in flags]
else:
devnull = open(os.devnull, 'r')
child = subprocess.Popen(["/usr/bin/cpp", "-xc++", "-v"],
stdin = devnull, stderr = subprocess.PIPE)
output = child.communicate()[1].split('\n')
devnull.close()
flags = []
status = 0
for l in output:
l = l.strip()
if l == '#include "..." search starts here:':
status = 1
elif l == '#include <...> search starts here:':
status = 2
elif status:
if l == 'End of search list.':
break
elif l.endswith('(framework directory)'):
continue
elif status == 1:
flags.append('-I')
elif status == 2:
flags.append('-isystem')
flags.append(os.path.normpath(l))
fp = open(cache, 'w')
fp.write('\n'.join(flags))
fp.close()
return flags
def FlagsForFile( filename, **kwargs ):
if database:
compilation_info = GetCompilationInfoForFile( filename )
if not compilation_info:
return None
final_flags = MakeRelativePathsInFlagsAbsolute(
compilation_info.compiler_flags_,
compilation_info.compiler_working_dir_ )
sys_incs = GetSystemIncludePaths()
if sys_incs:
final_flags += sys_incs
else:
relative_to = DirectoryOfThisScript()
final_flags = MakeRelativePathsInFlagsAbsolute( flags, relative_to )
return {
'flags': final_flags,
'do_cache': True
}
I'm trying to build my qt-plugin in both debug and release modes under Linux OS (Ubuntu 13.10), but it seems to me qmake ignores CONFIG += debug_and_release option. I also tried to use CONFIG += build_all, but it didn't work to. When I use the same options on Windows Qt generated two output files (for example plugin.a and plugind.a), but on Linux i get just one of them. When I force QtCreator to build my project in opposite mode (debug instead of relesae) it overrides already generated target file with the one that has the same name. Where did I go wrong?
Maybe the problem is that in your .pro file you should have set different target directories or different target file names. I do not know why but it looks like on Windows the target file names generated into your Makefiles are different and on Linux they are not different. You can try to change either your target directory or your target file name for debug build.
Try either
CONFIG(release, debug|release) {
TARGET = plugin
} else {
TARGET = plugind
}
or
CONFIG(release, debug|release) {
DESTDIR = release
OBJECTS_DIR = release/.obj
MOC_DIR = release/.moc
RCC_DIR = release/.rcc
UI_DIR = release/.ui
} else {
DESTDIR = debug
OBJECTS_DIR = debug/.obj
MOC_DIR = debug/.moc
RCC_DIR = debug/.rcc
UI_DIR = debug/.ui
}
At the moment I'm using some magic to get the current git revision into my scons builds.. I just grab the version a stick it into CPPDEFINES.
It works quite nicely ... until the version changes and scons wants to rebuild everything, rather than just the files that have changed - becasue the define that all files use has changed.
Ideally I'd generate a file using a custom builder called git_version.cpp and
just have a function in there that returns the right tag. That way only that one file would be rebuilt.
Now I'm sure I've seen a tutorial showing exactly how to do this .. but I can't seem to track it down. And I find the custom builder stuff a little odd in scons...
So any pointers would be appreciated...
Anyway just for reference this is what I'm currently doing:
# Lets get the version from git
# first get the base version
git_sha = subprocess.Popen(["git","rev-parse","--short=10","HEAD"], stdout=subprocess.PIPE ).communicate()[0].strip()
p1 = subprocess.Popen(["git", "status"], stdout=subprocess.PIPE )
p2 = subprocess.Popen(["grep", "Changed but not updated\\|Changes to be committed"], stdin=p1.stdout,stdout=subprocess.PIPE)
result = p2.communicate()[0].strip()
if result!="":
git_sha += "[MOD]"
print "Building version %s"%git_sha
env = Environment()
env.Append( CPPDEFINES={'GITSHAMOD':'"\\"%s\\""'%git_sha} )
You don't need a custom Builder since this is just one file. You can use a function (attached to the target version file as an Action) to generate your version file. In the example code below, I've already computed the version and put it into an environment variable. You could do the same, or you could put your code that makes git calls in the version_action function.
version_build_template="""/*
* This file is automatically generated by the build process
* DO NOT EDIT!
*/
const char VERSION_STRING[] = "%s";
const char* getVersionString() { return VERSION_STRING; }
"""
def version_action(target, source, env):
"""
Generate the version file with the current version in it
"""
contents = version_build_template % (env['VERSION'].toString())
fd = open(target[0].path, 'w')
fd.write(contents)
fd.close()
return 0
build_version = env.Command('version.build.cpp', [], Action(version_action))
env.AlwaysBuild(build_version)