我第一次在Macm1上使用SDL2,#include <SDL2/SDL.h>时遇到了一个问题。
每当我执行:w来保存文件时,我认为ALE在VIM中说“pp_file_not_found:'SDL2/SDL.h‘文件找不到"。
https://i.stack.imgur.com/jeZ3I.png
我下载了SDL2.framework并将其移到了我的/Library/Frameworks目录下.
在终端上编译时,我使用:
g++ -F/Library/Frameworks -framework SDL2 file.cpp这是正确的方式吗?
这将创建./a.out,并运行良好。
如何配置VIM和ALE,以便从SDL2?等包含语句和库中查找和提取构造
*ALEInfo
ALEInfo
Current Filetype: cpp
Available Linters: ['cc', 'ccls', 'clangcheck', 'clangd', 'clangtidy', 'clazy', 'cppcheck', 'cpplint', 'cquery', 'cspell', 'flawfinder']
Linter Aliases:
'cc' -> ['gcc', 'clang', 'g++', 'clang++']
Enabled Linters: ['cc', 'ccls', 'clangcheck', 'clangd', 'clangtidy', 'clazy', 'cppcheck', 'cpplint', 'cquery', 'cspell', 'flawfinder']
Ignored Linters: []
Suggested Fixers:
'astyle' - Fix C/C++ with astyle.
'clang-format' - Fix C/C++ and cuda files with clang-format.
'clangtidy' - Fix C/C++ and ObjectiveC files with clang-tidy.
'remove_trailing_lines' - Remove all blank lines at the end of a file.
'trim_whitespace' - Remove all trailing whitespace characters at the end of every line.
'uncrustify' - Fix C, C++, C#, ObjectiveC, ObjectiveC++, D, Java, Pawn, and VALA files with uncrustify.
Linter Variables:
let g:ale_cpp_cc_executable = '<auto>'
let g:ale_cpp_cc_options = '-std=c++17 -fsanitize=address -Wall -Weffc++ -Wextra -Wshadow -Wsign-conversion -Werror -DONPC -O2 -I/Library/Frameworks/SDL2.framework/Headers/ -F/Library/Frameworks -framework SD
L2'
let g:ale_cpp_ccls_executable = 'ccls'
let g:ale_cpp_ccls_init_options = {}
let g:ale_cpp_clangcheck_executable = 'clang-check'
let g:ale_cpp_clangcheck_options = ''
let g:ale_cpp_clangd_executable = 'clangd'
let g:ale_cpp_clangd_options = ''
let g:ale_cpp_clangtidy_checks = []
let g:ale_cpp_clangtidy_executable = 'clang-tidy'
let g:ale_cpp_clangtidy_extra_options = ''
let g:ale_cpp_clangtidy_options = ''
let g:ale_cpp_clazy_checks = ['level1']
let g:ale_cpp_clazy_executable = 'clazy-standalone'
let g:ale_cpp_clazy_options = ''
let g:ale_cpp_cppcheck_executable = 'cppcheck'
let g:ale_cpp_cppcheck_options = '--enable=style'
let g:ale_cpp_cpplint_executable = 'cpplint'
let g:ale_cpp_cpplint_options = ''
let g:ale_cpp_cquery_cache_directory = '/Users/vishalpaudel/.cache/cquery'
let g:ale_cpp_cquery_executable = 'cquery'
let g:ale_cpp_flawfinder_executable = 'flawfinder'
let g:ale_cpp_flawfinder_minlevel = 1
let g:ale_cpp_flawfinder_options = ''
Global Variables:
let g:ale_cache_executable_check_failures = v:null
let g:ale_change_sign_column_color = 0
let g:ale_command_wrapper = ''
let g:ale_completion_delay = v:null
let g:ale_completion_enabled = 0
let g:ale_completion_max_suggestions = v:null
let g:ale_disable_lsp = 0
let g:ale_echo_cursor = 1
let g:ale_echo_msg_error_str = 'Error'
let g:ale_echo_msg_format = '%code: %%s'
let g:ale_echo_msg_info_str = 'Info'
let g:ale_echo_msg_warning_str = 'Warning'
let g:ale_enabled = 1
let g:ale_fix_on_save = 0
let g:ale_fixers = {}
let g:ale_history_enabled = 1
let g:ale_history_log_output = 1
let g:ale_keep_list_window_open = 0
let g:ale_lint_delay = 200
let g:ale_lint_on_enter = 1
let g:ale_lint_on_filetype_changed = 1
let g:ale_lint_on_insert_leave = 1
let g:ale_lint_on_save = 1
let g:ale_lint_on_text_changed = 'normal'
let g:ale_linter_aliases = {}
let g:ale_linters = {}
let g:ale_linters_explicit = 0
let g:ale_linters_ignore = {}
let g:ale_list_vertical = 0
let g:ale_list_window_size = 10
let g:ale_loclist_msg_format = '%code: %%s'
let g:ale_max_buffer_history_size = 20
let g:ale_max_signs = -1
let g:ale_maximum_file_size = v:null
let g:ale_open_list = 0
let g:ale_pattern_options = v:null
let g:ale_pattern_options_enabled = v:null
let g:ale_root = {}
let g:ale_set_balloons = 0
let g:ale_set_highlights = 1
let g:ale_set_loclist = 1
let g:ale_set_quickfix = 0
let g:ale_set_signs = 1
let g:ale_sign_column_always = 0
let g:ale_sign_error = '>>'
let g:ale_sign_info = '--'
let g:ale_sign_offset = 1000000
let g:ale_sign_style_error = '>>'
let g:ale_sign_style_warning = '--'
let g:ale_sign_warning = '--'
let g:ale_sign_highlight_linenrs = 0
let g:ale_statusline_format = v:null
let g:ale_type_map = {}
let g:ale_use_global_executables = v:null
let g:ale_virtualtext_cursor = 0
let g:ale_warn_about_trailing_blank_lines = 1
let g:ale_warn_about_trailing_whitespace = 1
Command History:
(executable check - success) clang++
(finished - exit code 1) ['/bin/zsh', '-c', '''clang++'' -S -x c++ -o /dev/null -iquote ''/Users/vishalpaudel/Documents/SDL_tutorial/lazyFoo_SDL_tutrial'' -std=c++17 -fsanitize=address -Wall -Weffc++ -Wextra
-Wshadow -Wsign-conversion -Werror -DONPC -O2 -I/Library/Frameworks/SDL2.framework/Headers/ -F/Library/Frameworks -framework SDL2 - < ''/var/folders/8k/ggpn5rp16kddhp7gv3hz_tcc0000gn/T/vnX2hNq/2/01_hello_SDL.
cpp''']
<<<OUTPUT STARTS>>>
clang: error: -framework SDL2: 'linker' input unused [-Werror,-Wunused-command-line-argument]
<<<OUTPUT ENDS>>>
(executable check - failure) ccls
(executable check - failure) clang-check
(executable check - success) clangd
(executable check - failure) clang-tidy
(executable check - failure) clazy-standalone
(executable check - failure) cppcheck
(executable check - failure) cpplint
(executable check - failure) cquery
(executable check - failure) cspell
(executable check - failure) flawfinder
(started) ['/bin/zsh', '-c', '''clangd''']
(executable check - failure) ccls
(executable check - failure) cquery我的~/..vimrc:
" .vimrc of Bo Liu
" {{{
" https://github.com/hmybmny/vimrc
set nocompatible
" }}}
" VIM-PLUG BLOCK
" {{{
if has('python3')
endif
silent! if plug#begin('~/.vim/plugged')
" Colors
Plug 'altercation/vim-colors-solarized'
Plug 'tomasr/molokai'
Plug 'colepeters/spacemacs-theme.vim'
Plug 'sheerun/vim-polyglot'
" Editing
Plug 'SirVer/ultisnips'
Plug 'sjl/gundo.vim'
Plug 'matze/vim-move'
Plug 'jiangmiao/auto-pairs'
Plug 'kana/vim-operator-user'
Plug 'gcmt/wildfire.vim'
Plug 'lilydjwg/fcitx.vim'
Plug 'scrooloose/nerdcommenter'
Plug 'derekwyatt/vim-protodef', { 'for': ['c', 'cpp', 'objc'] }
Plug 'suan/vim-instant-markdown', { 'for': 'markdown' }
" Navigation
Plug 'majutsushi/tagbar', { 'on': 'TagbarToggle' }
Plug 'derekwyatt/vim-fswitch', { 'for': ['c', 'cpp', 'objc'] }
Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
Plug 'tpope/vim-fugitive'
Plug 'ctrlpvim/ctrlp.vim'
Plug 'dyng/ctrlsf.vim'
Plug 'fholgado/minibufexpl.vim'
" View
Plug 'Yggdroot/indentLine'
Plug 'airblade/vim-gitgutter'
" Linting
Plug 'w0rp/ale'
"cd ~
"mkdir ycm_build
"cd ycm_build/
"cmake -G "Unix Makefiles" -DPATH_TO_LLVM_ROOT=~/Downloads/clang+llvm-3.9.1-x86_64-linux-gnu-ubuntu-16.04 . ~/.vim/plugged/YouCompleteMe/third_party/ycmd/cpp
"cmake --build . --target ycm_core
"Plug 'Valloric/YouCompleteMe'
function! BuildYCM(info)
if a:info.status == 'installed' || a:info.force
!./install.py --clang-completer
endif
endfunction
Plug 'Valloric/YouCompleteMe', { 'do': function('BuildYCM') }
call plug#end()
endif
" }}}
" BASIC SETTINGS
" {{{
let mapleader = ';'
set encoding=utf-8
" Allow backspacing over everything in insert mode
set backspace=indent,eol,start
" Store lots of :cmdline history
set history=500
" Show line numbers
set nu
set nowrap
" Autoindent when starting new line
set autoindent
set smartindent
set lazyredraw
" Ignore case when searching
set ignorecase
" Don't ignore case when search has capital letter
set smartcase
" Enable highlighted case-insensitive incremential search
set incsearch
" Enble search highlighting
set hlsearch
" Always show window statuses
set laststatus=2
" Statusline style
set statusline=
set statusline+=%7*\[%n] "buffernr
set statusline+=%1*\ %<%F\ "File+path
set statusline+=%2*\ %y\ "FileType
set statusline+=%3*\ %{''.(&fenc!=''?&fenc:&enc).''} "Encoding
set statusline+=%3*\ %{(&bomb?\",BOM\":\"\")}\ "Encoding2
set statusline+=%4*\ %{&ff}\ "FileFormat (dos/unix..)
set statusline+=%8*\ %=\ row:%l/%L\ (%p%%)\ "Rownumber/total (%)
set statusline+=%9*\ col:%c\ "Colnr
set statusline+=%0*\ \ %m%r%w\ %P\ \ "Modified? Readonly? Top/bot.
" Show the size of block one selected in visual mode
set showcmd
" Hide buffers
set hidden
set visualbell
" Indent using four spaces
set expandtab smarttab
set tabstop=4
set shiftwidth=4
set softtabstop=4
set gcr=a:block-blinkon0
set guioptions-=l
set guioptions-=L
set guioptions-=r
set guioptions-=R
set guioptions-=m
set guioptions-=T
function! ToggleFullscreen()
call system("wmctrl -ir " . v:windowid . " -b toggle,fullscreen")
endf
map <silent> <F11> :call ToggleFullscreen()<CR>
imap <silent> <F11> <esc>:call ToggleFullscreen()<CR>
" autocmd VimEnter * call ToggleFullscreen()
" Show the line and column number of the cursor position
set ruler
" Highlight line under cursor
set cursorline
set cursorcolumn
" }}}
" MAPPINGS
" {{{
" ----------------------------------------------------------------------------
" Basic mappings
" ----------------------------------------------------------------------------
" Profile
iabbrev @@ hmybmny@gmail.com
iabbrev @b hmybmny.com
" Edit myvimrc
nnoremap <leader>ev :vsplit $MYVIMRC<cr>
nnoremap <leader>sv :source $MYVIMRC<cr>
" Edit
nnoremap <leader>" viw<esc>a"<esc>hbi"<esc>lel
" Save
inoremap <C-s> <C-O>:w<cr>
nnoremap <C-s> :w<cr>
nnoremap <leader>w :w<cr>
" Copy
vnoremap <Leader>y "+y
nmap <Leader>p "+p
" Quit
nnoremap <Leader>q :q<cr>
nnoremap <Leader>Q :qa!<cr>
" Movement in insert mode
inoremap <C-h> <C-o>h
inoremap <C-j> <C-o>j
inoremap <C-k> <C-o>k
inoremap <C-l> <C-o>a
inoremap <C-^> <C-o><C-^>
" ----------------------------------------------------------------------------
" Quickfix
" ----------------------------------------------------------------------------
nnoremap ]q :cnext<cr>zz
nnoremap [q :cprev<cr>zz
" ----------------------------------------------------------------------------
" <tab> / <s-tab> | Circular windows navigation
" ----------------------------------------------------------------------------
nnoremap <tab> <c-w>w
nnoremap <S-tab> <c-w>W
nnoremap <Leader>hw <C-W>h
nnoremap <Leader>jw <C-W>j
nnoremap <Leader>kw <C-W>k
nnoremap <Leader>lw <C-W>l
" ----------------------------------------------------------------------------
" :CopyRTF
" ----------------------------------------------------------------------------
function! s:colors(...)
return filter(map(filter(split(globpath(&rtp, 'colors/*.vim'), "\n"),
\ 'v:val !~ "^/usr/"'),
\ 'fnamemodify(v:val, ":t:r")'),
\ '!a:0 || stridx(v:val, a:1) >= 0')
" ----------------------------------------------------------------------------
endfunction
" <F8> | Color scheme selector
" ----------------------------------------------------------------------------
"
set background=dark
let g:molokai_original = 1
colorschem molokai
function! s:rotate_colors()
if !exists('s:colors')
let s:colors = s:colors()
endif
let name = remove(s:colors, 0)
call add(s:colors, name)
set background=dark
execute 'colorscheme' name
redraw
echo name
endfunction
nnoremap <silent> <F8> :call <SID>rotate_colors()<cr>
inoremap <silent> <F8> <esc>:call <SID>rotate_colors()<cr>
" }}}
" PLUGINS
" {{{
" ----------------------------------------------------------------------------
" ultisnips
" ----------------------------------------------------------------------------
let g:UltiSnipsSnippetDirectories=["mysnippets"]
let g:UltiSnipsExpandTrigger="<leader><tab>"
let g:UltiSnipsJumpForwardTrigger="<leader><tab>"
let g:UltiSnipsJumpBackwardTrigger="<leader><s-tab>"
" ----------------------------------------------------------------------------
" vim-multiple-cursors
" ----------------------------------------------------------------------------
let g:multi_cursor_next_key='<S-n>'
let g:multi_cursor_skip_key='<S-k>'
" ----------------------------------------------------------------------------
" vim-move
" ----------------------------------------------------------------------------
let g:move_key_modifier = 'C'
" ----------------------------------------------------------------------------
" auto-pairs
" ----------------------------------------------------------------------------
" ----------------------------------------------------------------------------
" vim-operator-user
" ----------------------------------------------------------------------------
" ----------------------------------------------------------------------------
" wildfire.vim
" ----------------------------------------------------------------------------
map <SPACE> <Plug>(wildfire-fuel)
vmap <C-SPACE> <Plug>(wildfire-water)
" ----------------------------------------------------------------------------
" indentLine
" ----------------------------------------------------------------------------
let g:indentLine_char = '│'
" ----------------------------------------------------------------------------
" tarbar
" ----------------------------------------------------------------------------
inoremap <F2> <esc>:TagbarToggle<cr>
nnoremap <F2> :TagbarToggle<cr>
let tagbar_left=1
let tagbar_width=32
let g:tagbar_sort = 0
let g:tagbar_compact=1
let g:tagbar_type_cpp = {
\ 'ctagstype' : 'c++',
\ 'kinds' : [
\ 'c:classes:0:1',
\ 'd:macros:0:1',
\ 'e:enumerators:0:0',
\ 'f:functions:0:1',
\ 'g:enumeration:0:1',
\ 'l:local:0:1',
\ 'm:members:0:1',
\ 'n:namespaces:0:1',
\ 'p:functions_prototypes:0:1',
\ 's:structs:0:1',
\ 't:typedefs:0:1',
\ 'u:unions:0:1',
\ 'v:global:0:1',
\ 'x:external:0:1'
\ ],
\ 'sro' : '::',
\ 'kind2scope' : {
\ 'g' : 'enum',
\ 'n' : 'namespace',
\ 'c' : 'class',
\ 's' : 'struct',
\ 'u' : 'union'
\ },
\ 'scope2kind' : {
\ 'enum' : 'g',
\ 'namespace' : 'n',
\ 'class' : 'c',
\ 'struct' : 's',
\ 'union' : 'u'
\ }
\ }
" ----------------------------------------------------------------------------
" vim-fswitch
" ----------------------------------------------------------------------------
nmap <silent> <Leader>fs :FSHere<cr>
" ----------------------------------------------------------------------------
" vim-protodef
" ----------------------------------------------------------------------------
let g:protodefprotogetter='~/.vim/plugged/vim-protodef/pullproto.pl'
let g:disable_protodef_sorting=1
" ----------------------------------------------------------------------------
" nerdcommenter
" ----------------------------------------------------------------------------
" ----------------------------------------------------------------------------
" nerdtree
" ----------------------------------------------------------------------------
inoremap <F3> <esc>:NERDTreeToggle<CR>
nnoremap <F3> :NERDTreeToggle<CR>
let NERDTreeWinSize=22
let NERDTreeWinPos="right"
let NERDTreeShowHidden=0
let NERDTreeMinimalUI=1
let NERDTreeAutoDeleteBuffer=1
" ----------------------------------------------------------------------------
" vim-instant-markdown
" ----------------------------------------------------------------------------
autocmd BufNewFile,BufReadPost *.md set filetype=markdown
let g:instant_markdown_slow = 1
let g:instant_markdown_autostart = 0
nnoremap <Leader>md :InstantMarkdownPreview<CR>
" ----------------------------------------------------------------------------
" vim-fugitive
" ----------------------------------------------------------------------------
" ----------------------------------------------------------------------------
" vim-gitgutter
" ----------------------------------------------------------------------------
set updatetime=250
set signcolumn=yes
" ----------------------------------------------------------------------------
" ale
" ----------------------------------------------------------------------------
" ----------------------------------------------------------------------------
" minibufexpl
" ----------------------------------------------------------------------------
inoremap <F4> <esc>:MBEToggle<cr>
nnoremap <F4> :MBEToggle<cr>
nnoremap ]b :bnext<cr>
nnoremap [b :bprev<cr>
" ----------------------------------------------------------------------------
" gundo.vim
" ----------------------------------------------------------------------------
nnoremap <Leader>ud :GundoToggle<CR>
set sessionoptions="blank,globals,localoptions,tabpages,sesdir,folds,help,options,resize,winpos,winsize"
if !strlen(finddir('~/.vim/undofiles'))
echo "undofiles[~/.vim/undofiles] not found. Now it's being created. Press ENTER or type command to continue."
!mkdir -p ~/.vim/undofiles
endif
if v:version >= 703
set undodir=~/.vim/undofiles
set undofile
set colorcolumn=+1
endif
" ----------------------------------------------------------------------------
" ctrlsf.vim
" ----------------------------------------------------------------------------
nnoremap <c-f> :CtrlSF<CR>
" ----------------------------------------------------------------------------
" ctrlp.vim
" ----------------------------------------------------------------------------
" Disable output, vcs, archive, rails, temp and backup files
set wildignore+=*.o,*.out,*.obj,.git,*.pyc,*.class
set wildignore+=*.zip,*.tar.gz,*.tar.bz2,*.rar,*.tar.xz
set wildignore+=*.swp,*~,._*
set wildignore+=*/tmp/*,*.so,*.swp,*.zip " MacOSX/Linux
let g:ctrlp_map = '<s-p>'
let g:ctrlp_cmd = 'CtrlP'
let g:ctrlp_custom_ignore = '\v[\/]\.(git|hg|svn)$'
let g:ctrlp_custom_ignore = {
\ 'dir': '\v[\/]\.(git|hg|svn|vendor/bundle/*\|vendor/cache/*\|public\|spec)$',
\ 'file': '\v\.(exe|so|dll|swp|log|jpg|png|json)$',
\ }
" ----------------------------------------------------------------------------
" YouCompleteMe
" ----------------------------------------------------------------------------
set completeopt-=preview
nnoremap <leader>jc :YcmCompleter GoToDeclaration<CR>
nnoremap <leader>jd :YcmCompleter GoToDefinition<CR>
inoremap <leader>; <C-x><C-o>
"run and compile cpp
nnoremap <f8> :!g++ -o %:r.out % -std=c++14<Enter>
autocmd filetype cpp nnoremap <f9> :!%:r.out<CR>
let g:ycm_complete_in_comments=1
let g:ycm_confirm_extra_conf=0
let g:ycm_collect_identifiers_from_tags_files=0
let g:ycm_min_num_of_chars_for_completion=1
let g:ycm_cache_omnifunc=0
let g:ycm_seed_identifiers_with_syntax=1
let g:ale_cpp_cc_options = '-std=c++17 -fsanitize=address -Wall -Weffc++ -Wextra -Wshadow -Wsign-conversion -Werror -DONPC -O2 -I/Library/Frameworks/SDL2.framework/Headers/ -F/Library/Frameworks -framework SDL2'
" }}}~/..zshrc
alias python="python3.10"
alias pip="pip3"
alias vim="/Applications/MacVim.app/Contents/bin/Vim"
alias cmake="/Applications/CMake.app/Contents/bin/cmake"
alias g++="g++ -std=c++17 -fsanitize=address -Wall -Weffc++ -Wextra -Wshadow -Wsign-conversion -Werror -DONPC -O2" # -I/Library/Frameworks/SDL2.framework/Headers/ -F/Library/Frameworks -framework SDL2"
alias clang++="clang++ -std=c++17 -fsanitize=address -Wall -Weffc++ -Wextra -Wshadow -Wsign-conversion -Werror -DONPC -O2" # -I/Library/Frameworks/SDL2.framework/Headers/ -F/Library/Frameworks -framework SDL2"
alias gcc="gcc -std=c++17 -fsanitize=address -Wall -Weffc++ -Wextra -Wshadow -Wsign-conversion -Werror -DONPC -O2" # -I/Library/Frameworks/SDL2.framework/Headers/ -F/Library/Frameworks -framework SDL2"
export CPLUS_INCLUDE_PATH="/Library/Frameworks/SDL2.framework/Headers/:$CPLUS_INCLUDE_PATH"
export LIBRARY_PATH="/Library/Frameworks/SDL2.framework/:$LIBRARY_PATH"
# If you come from bash you might have to change your $PATH.
export PATH=$HOME/bin:/usr/local/bin:$PATH
export PATH=$HOME/Applications/CMake.app/Contents/bin:$PATH
export PATH=/opt/homebrew/bin:$PATH
# Path to your oh-my-zsh installation.
export ZSH="$HOME/.oh-my-zsh"
ZSH_THEME="powerlevel10k/powerlevel10k"
plugins=(git zsh-autosuggestions zsh-syntax-highlighting)
source $ZSH/oh-my-zsh.sh
export MANPATH="/usr/local/man:$MANPATH"
export LANG=en_US.UTF-8
# Preferred editor for local and remote sessions
if [[ -n $SSH_CONNECTION ]]; then
export EDITOR='vim'
else
export EDITOR='mvim'
fi
# For file icons in ls -a
if [ -x "$(command -v colorls)" ]; then
alias ls="colorls"
alias la="colorls -al"
fi
# To customize prompt, run `p10k configure` or edit ~/.p10k.zsh.
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh发布于 2022-08-22 07:27:28
我终于让它起作用了
使用这个,而不是#include <SDL2/SDL.h>
#include <SDL.h>简单的回答是,在~/.zshrc和~/.zshprofile的末尾加上这几行
PATH="/Library/Frameworks/SDL2.framework/./:${PATH}"
export PATH
LIBRARY_PATH="/Library/Frameworks/SDL2.framework/:${LIBRARY_PATH}"
export LIBRARY_PATH
CPLUS_INCLUDE_PATH="/Library/Frameworks/SDL2.framework/Headers/:$CPLUS_INCLUDE_PATH"
export CPLUS_INCLUDE_PATH以上设置没有任何问题,请不要复制上面的设置。看一看,你可能会发现一些有用的东西。
免责声明:我能感觉到我已经用一种讨厌的方式做了这件事,而且我对正在发生的事情并不完全理解。
我认为编译器在当前PATH变量中搜索头文件,因此在路径中追加Library位置可能会有所帮助。
https://stackoverflow.com/questions/73441233
复制相似问题