When attempting to setup SDL2 with VS Code in Ubuntu 20.01 LTM I get the following VS Code error:
cannot open source file "begin_code.h" (dependency of "SDL2/SDL.h")
Any tips?
Just add "/usr/include/SDL2/" to your c_cpp_properties.json like so:
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"/usr/include/SDL2/"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "gnu18",
"cppStandard": "gnu++14",
"intelliSenseMode": "gcc-x64"
}
],
"version": 4
}
in case you don't have the "c_cpp_properties.json" file in your
folder.
Different answer than above, but I believe might be a better approach.
to create the c_cpp_properties.json on your workspace
do the following:
ctrl + shift + p (opens the command palette)
search for "C/C++: Edit Configurations (JSON)" and click on it
"c_cpp_properties.json" file will be created on your workspace
add "/usr/include/SDL2/" to your "c_cpp_properties.json" like
https://stackoverflow.com/a/64187964/8540466
reload C/C++ IntelliSense extension.
I'm assuming you already have the extension
"C/C++ IntelliSense, debugging, and code browsing"
installed on your vscode.
After these steps this problem was fixed for me.
If you, like me, don't have the c_cpp_properties.json file in your project, you can solve it by adding the following line to your settings.json (in VSCode, hit Ctrl+Shift+P and search for Open settings (JSON)):
{
// ...
"C_Cpp.default.includePath": ["/usr/include/SDL2", "${default}"],
//...
}
Related
I want to use CMDR as VS Code default integrated terminal. I have added the following options in my settings.json
"terminal.integrated.shell.windows": "C:\\Windows\\system32\\cmd.exe",
"terminal.integrated.shellArgs.windows": [
"/k %CMDER_ROOT%\\vendor\\init.bat"
],
and it was working but with this new VS Code update Version: 1.60.0 it stopped working.
any suggestions? how to fix this?
Also had this problem today and managed to fix it by updating settings.json as follows:
"terminal.integrated.profiles.windows": {
"Cmder": {
"path": [
"${env:windir}\\Sysnative\\cmd.exe",
"${env:windir}\\System32\\cmd.exe"
],
"args": ["/K", "C:\\Program Files\\cmder\\vendor\\init.bat"]
}
},
"terminal.integrated.defaultProfile.windows": "Cmder"
Make sure to update the path to cmder to match the install location on your system
These old legacy settings can then be removed:
terminal.integrated.shell.windows
terminal.integrated.shell.windowsExec
terminal.integrated.shellArgs.windows
I have an existing C++ project that I've configured and built in Visual Studio. This project's only target is Windows, no other platforms. I'm using Bash in WSL to launch the executable.
I prefer to develop in Visual Code (not Visual Studio). I prefer to build and launch applications through Bash (strong Linux background).
Right now, my development workflow is:
Edit code in VS Code
Switch to Visual studio and click the build button
Switch to Bash and execute the built program
Since I only keep Visual Studio open for building, I would much prefer to build by command line through Bash.
My naive approach was to use an open source tool to convert the Visual Studio project file into a CMake file. Then cmake & make from Bash, but I stopped when I started encountering errors looking for windows.h (maybe I just need to add some windows include paths to my include_path).
I'm not sure what the best way to go about this would be. Any suggestions would be appreciated!
If the project is entirely C++, there should be no reason to leave WSL. Building and launching the application can be easily handled right there!
You can absolutely build by the command line in bash by using
g++ -o <outputfile> <inputfiles>
However, the easiest way to run the program is to create a build configuration in Visual Code. You will need 2 files: launch.json and tasks.json
To create the launch file, hit F1 (or open your command pallet) and select Tasks: Configure Default Build Task. It should look something like this.
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "g++ build active file",
"command": "/usr/bin/g++",
"args": [
"-g",
"${file}", //input files
"-o",
"${fileDirname}/a.out" //output file
],
"options": {
"cwd": "/usr/bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
To create launch.json, go to the 'debug' tab and select 'create a launch.json file'. It should look something like this
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "g++ build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/a.out", //output file
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "g++ build active file",
"miDebuggerPath": "/usr/bin/gdb"
}
]
}
with both of these files in place, all you have to do is hit the run button like in Visual Studio.
MSBuild.exe is provided with my installation of Microsoft Visual Studio. From within WSL bash, I can invoke MSBuild.exe and give the .sln file of my project as the first and only argument.
The compilation output is written to the terminal.
I have been recently trying to use the MinGW gcc compiler with Code, and am getting some issues with Intellisense(not breaking, but I find it annoying).
I followed the documentation to edit the path for the c_cpp_properties.json file, but the error continues to pop up and I think I have also found contradictory information.
{
"name": "Win32",
"includePath": [
"${workspaceRoot}"
],
"defines": [
"_DEBUG",
"UNICODE"
],
"intelliSenseMode": "msvc-x64",
"browse": {
"path": [
"${workspaceRoot}",
"C:\\MinGW\\lib\\gcc\\mingw32\\6.3.0\\include\\c++"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
}
}
],
"version": 3
I looked on the github repo for the documentation and found someone had committed a change where ${workspaceRoot} was changed to workspaceFolder in the documentation. However, root seems to be the default for VS code, and I only updated to the new orange logo version this morning.
https://github.com/Microsoft/vscode-docs/commit/fa613d436a53bd9c5a21065cf5fa0f1b350d9bc6
So which is the correct way to get Intellisense working, Folder or Root?
Turning #Marks comment into an answer: ${workspaceRoot} is deprecated, ${workspaceFolder} should be used instead: https://code.visualstudio.com/docs/editor/multi-root-workspaces
See also this description of variables: https://code.visualstudio.com/docs/editor/variables-reference
${workspaceFolder} - the path of the folder opened in VS Code
I am new to web development in general, and I am trying to setup sass following the documentation here:
https://code.visualstudio.com/docs/languages/css
However I am receiving this error:
"An output directory must be specified when compiling a directory". On
the internet people are suggesting solutions, but they are related to
configuration of other editors.
My project looks like this, so you can have an idea how my project is set up:
SASS project config screenshot
I tried adding all design files in the same folder as the tasks.json file, but it didn't work and I got the same error.
I have one more question: do I need to create the .css file, or does the task create it if it's not found?
I appreciate any help possible.
I just figured this out, while looking for the same solution.
Your "args" have to be configured like this:
"args": ["./src/app/styles.scss", "./src/app/styles.css"]
or
"args": ["./(static or assets folder)/(sass folder)/styles.scss", "./(static or assets folder)/(css folder)/styles.css"]
The "./" points to the root of the project, then simply include the appropriate folder path.
Cheers!
The default setup for the Sass Task Runner on https://code.visualstudio.com/docs/languages/css now looks like this:
// Sass configuration
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Sass Compile",
"type": "shell",
"command": "node-sass styles.scss styles.css",
"group": "build"
}
]
}
If you get the error
"An output directory must be specified when compiling a directory"
then change the configuration like:
"command": "node-sass ./<your path>/styles.scss ./<your path>/styles.css",
For example, there is package for less LessToCss. As for Sass(or SCSS) I don't know what i should do. Ruby and sublime package Sass are installed.
You have to alter the PATH variable at the end of PATH string in the Environment Variables: Desktop - Properties - Environment Variables. It for win vista/7 users. Detail for 2000/XP here Sass compiler not working in sublime text 3
One way is to download a SASS build compiler from here: SASS Compiler
This is automatic Sublime package that simply builds your file at the place.
However since they released the new version, there seem to be multiple settings on this package - you could try to mess with that a bit and see what it can do nowdays.
Second way is to write your own Build command in Sublime. You do this by going to "Tools>Build System>New Build System..."
{
"cmd": ["sass", "--update", "$file:${project_path}/Project/Web/css/${file_base_name}.css", "--stop-on-error", "--style", "compressed", "--no-cache", "--sourcemap=none"],
"selector": "source.sass, source.scss",
"line_regex": "Line ([0-9]+):",
"osx":
{
"path": "/usr/local/bin:$PATH"
},
"windows":
{
"shell": "true"
}
}
Explanation: I use a folder structure as the following: Project/Web/CSS - If you have the Sublime Project FILE at the same level as Project FOLDER, then this will automatically build your Sass file (placed ANYWHERE in the project file) in your Web/CSS folder. Of course you can change this as you see fitting.
here is 100% solution, as i also using. Actually i am using in mac so, i am not sure about windows because i wouldn't try yet in windows but i think it will works in window's too.
so here is the build;
copy this from starting brackets and paste it into build and then save with any name like (Build to CSS),"
{
"cmd": ["sass", "--update", "$file:${file_path}/../css/${file_base_name}.css", "--stop-on-error", "--no-cache"],
"osx":
{
"path": "/user/local/bin:$PATH"
},
"windows":
{
"shell": true
}
}
If it's working then please comment.
Thanks