I want to use it in some of my programs instead of the standard IOStream.
Also, does NCurses work on Windows, and if so, any better?
Download the zip file, unpack it wherever you typically put external libraries, and check the readme, which tells you the following:
PDCurses has been ported to DOS, OS/2, Win32, X11 and SDL. A directory containing the port-specific source files exists for each of these platforms. Build instructions are in the README file for each platform.
The readme file in the Win32 directory tells you that there are makefiles for several different compilers. In short, you run make:
make -f makefilename
It tells mentions a couple of options you can set, including WIDE and UTF8.
To then use the library, add the directory that contains curses.h to your include path and link with the pdcurses.lib file that make generates for you. How you modify your include path and your linked libraries depends on your development environment and is largely irrelevant to PDCurses.
On VSCode
[Step 1] Install MinGW :
MinGW installation steps
^(make sure you followed the steps carefully)
[Step 2] BUILD PDCurses:
Download PDCurses-master.zip and extract the content
Open\Run MSYS2 MinGW 64-bit (or MSYS2 MinGW 32-bit^1)
cd into the wincon folder and run make -f Makefile WIDE=Y DLL=Y source
[Step 3] Copy Files:
If you followed the steps above so far correctly, there should be 2 specific files inside wincon folder called pdcurses.a and pdcurses.dll
rename pdcurses.a to libpdcurses.a
copy pdcurses.dll into C:\msys64\mingw64\bin
copy libpdcurses.a into C:\msys64\mingw64\lib
copy curses.h and panel.h form PDCurses-master folder into C:\msys64\mingw64\include
[Step 4] Build an example:
Install the C/C++ extension
Follow those steps to create a working enviroment inside VSCode
Add "-lpdcurses" under "args": into tasks.json
and you are Done (at least those steps worked for me)
Extra
you can also just manually build an example by runing g++ your_example.c -o your_example -lpdcurses inside MSYS2 MinGW 64-bit terminal if you want so [...]
^1 if you want to build for 32 systems a good rule is to follow all steps above but wherever you see 64 replace it with 32
demos / examples
how things should look like:
c_cpp_properties.json
{
"configurations": [
{
"name": "Win64",
"includePath": [
"${default}"
],
"windowsSdkVersion": "10.0.17763.0",
"compilerPath": "C:/msys64/mingw64/bin/g++.exe",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "${default}"
}
],
"version": 4
}
launch.json
{
// 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++.exe - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\msys64\\mingw64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++.exe build active file"
}
]
}
tasks.json:
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file",
"command": "C:\\msys64\\mingw64\\bin\\g++.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"-lpdcurses"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
I finally made it. First Build/Compile the Source according to docs.
make -f Makefile # did for me, Windows 10
Copy curses.h and panel.h into your include folder. And, Copy wincon/pdcurses.a into your lib folder. Rename pdcurses.a to libpdcurses.a. (Because it's the standard).
Now, You can include curses.h and compile it like this.
g++ main.cpp -lpdcurses
Related
I am trying to complie a basic openGL program in VSCode on mac. I am using glad and GLFW, and I have the Glad files in the same folder as the test.cpp file I am trying to run. However, the include statement throws an error no matter how I type it. This is the program I am writing
#include <iostream>
#include "glad.h"
However, it throws the errors:
screenshot of errors
VSCode cannot find the header files the program needs to run, and the compiler throws errors as a result. I should add, that autocomplete for these libraries is working, however, the file cannot be found by the editor.
Here is the c_cpp_properties.json code
{
"configurations": [
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"macFrameworkPath": [
"/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks"
],
"compilerPath": "/usr/bin/clang",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "macos-clang-x64"
}
],
"version": 4
}
Perhaps the problem could be realted to how I am trying to compile the file? Here is my tasks.json file
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++ build active file",
"command": "/usr/bin/g++",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}",
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
Any guidance on how to set this project up correctly, any advice would be greatly appreciated. For reference, here is the tutorial I am trying to follow: https://learnopengl.com/Getting-started/Hello-Window.
Thank you so much!
I'll start by pointing out a few things that aren't really important.
VSCode is not a compiler, nor an IDE. VScode is a text editor. As a text editor it may have some extensions that help you with developing (thus turning it into a make-shift IDE).
What is happening here is that the compiler (gcc) doesn't know where to look for include files. It is even hinting you that you need to update the includePath in a way that you point it to the correct folder with the header files. In the CLI this is done via the -I flag i.e. g++ main.cpp -Ipath/to/your/include_folder/.
If you look into the Getting Started section they even go through these steps and go as far as to suggest the usage of CMake (which is a build tool that helps you generate the makefile with which you build your binaries).
By looking at the tasks.json I can conclude that the extension which you are using in VSCode uses this file to pass down the correct arguments to g++. So the quickest solution for you right now is to specify another element in args that points to the header files i.e.:
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"-Ipath/to/your/include_folder/with_the_headers", <----
"${fileDirname}/${fileBasenameNoExtension}",
],
Hope it helps!
I have set up VS code as my development environment and used
MSVC build tools (cl.exe compiler) instead of g++. I tried to set up SFML for my environment. I want to know how do I set the SFML include path and library path. And also, How do I perform static Linking with cl.exe. Note: I am using only VS code and NOT Visual Studio for programming. Below are some files I've used. Tasks.json,Launch.json, C_cpp_properties.json.
Tasks.json:
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: cl.exe build active file",
"command": "cl.exe",
"args": [
"/Zi",
"/EHsc",
"/nologo",
"/Fe:",
"${workspaceFolder}\\bin\\${fileBasenameNoExtension}.exe",
"${workspaceFolder}\\*.cpp"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$msCompile"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
Launch.json:
{
// 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": "cl.exe - Build and debug active file",
"type": "cppvsdbg",
"request": "launch",
"program": "${workspaceFolder}\\bin\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"console": "externalTerminal",
"preLaunchTask": "C/C++: cl.exe build active file"
}
]
}
c_cpp_properties.json
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${default}"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.19041.0",
"compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2022/BuildTools/VC/Tools/MSVC/14.30.30705/bin/Hostx64/x64/cl.exe",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "windows-msvc-x64"
}
],
"version": 4
}
As mentioned in the comments, you need to use a C++ build system to manage dependencies and build your project. VSCode does not come with any built-in build systems like Visual Studio does.
VSCode tasks allow you to specify a command line, which can then be invoked easily in the IDE. The task shown is just a "build active file" task, which is only really useful for trivial programs with no dependencies. It invokes cl.exe on the current source file (and passes a few other arguments).
You can specify include directories and pass arguments to the linker by adding to the "args" array in the task, e.g.:
"/I", "D:\\Code Libraries\\boost_1_77_0",
"/link", "/LIBPATH:\"D:\\Code Libraries\\boost_1_77_0\\stage\\lib\"",
which assumes that the boost headers and (statically built) libraries are at the specified locations.
You could probably work out how to build an entire project by adding command lines with VSCode tasks, but it's probably easier to use a build system (even if that system is CMake).
I am new to VS code. I have configured it using Clang on macOS using the provided [VS code documentation] (https://code.visualstudio.com/docs/cpp/config-clang-mac)
It works, I can build and debug. Great!
My question is: how do I configure VS Code to build in Release mode? I don't seem to be able to find any info in the documentation or a tutorial on how to do it
In case it helps, this is the way tasks.json looks right now
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "clang++ build active file",
"command": "/usr/bin/clang++",
"args": [
"-std=c++17",
"-stdlib=libc++",
"-g",
"-v",
"${file}",
"${workspaceFolder}/source/*.cpp",
"${workspaceFolder}/FFTreal/*.cpp",
"-I.",
"-L",
"${workspaceFolder}/BassLibrary",
"-lbass",
"-o",
"${workspaceFolder}/final.out",
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": ["$gcc"],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
Any idea? Thanks!
Sorry, for the last answer...
So first of all, I need to claim that I'm not really familiar to Clang Family, but I did some research and found that there are two special groups out in tasks.json which VSCode provides: Build and Test. So, I guess that we need to build it in release mode manually where again I don't have any confidence on me...
I found that you can build your Clang scripts using CMake. CMake is simply a builder tool to help you reassemble your whole code, including libraries, dependencies, modules etc.
So, I'm not sure if that'll be possible but you can change your tasks.json configuration from Clang++ to CMake, maybe?
First of all, for a quick answer, I edited your tasks.json snippet to this:
{
"tasks": [
{
"label": "cmake init",
"type": "shell",
"options": {
"cwd": "${workspaceRoot}"
},
"command": "/path/to/cmake",
"args": [
"-S",
"${cwd}",
"-B",
"${cwd}/build"
],
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
}
},
{
"label": "cmake release builder",
"type": "shell",
"options": {
"cwd": "${workspaceRoot}"
},
"command": "/path/to/cmake",
"args": [
"--build",
"${workspaceRoot}/build",
"--config",
"Release"
],
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
What it does is, basically CMake scans your project folder and create configuration files via the cmake init task. After that, when you run cmake release builder, the task will assume that you have a build folder - which you can change easily - and creates a compact executable file, in build/Release.
But also, in order to use CMake, you need to create a CMakeLists.txt file whose baseName is case-sensitive. So, I created a really simple CMake configuration file which you can add your source files manually, unfortunately, like this:
cmake_minimum_required(VERSION 3.13) # CMake version check
project(simple_example) # Create project "simple_example"
set(CMAKE_CXX_STANDARD 14) # Enable c++14 standard
set(SOURCE_FILES test.cpp add.cpp) # Append source files
# Add executable target with source files listed in SOURCE_FILES variable
add_executable(simple_example ${SOURCE_FILES})
Finally, to make this process REAL, you need to go Terminal > Run Build Task in VSCode.
I'm not really sure that you can use Clang compiler to build a whole application, like an .exe file in Windows. During the research, I focused a lot on the difference between compiler and builder which I recommend to look it up!
I hope that I used English in a comprehensible way and not made confused.
I am trying to set up build and run a c++ file in VS Code 2019. I am having build errors after editing the tasks.json file. The environment variable is set to g++ as it should be. So far, I have been following this tutorial.
I attempted changing "command" to"C:\MinGW\bin\g++.exe" as recommended in a question thread on GitHub. However, because my c++ file is not in this file path, the program was not able to find it when I built the code. This is what the "command" portion of the tasks.json file should look like:
"label": "build calculator adventure",
"type": "shell",
"command": "g++",
"args": [
"-g",
"-o",
"Calculator-Adventure",
"Calculator Adventure.cpp"
],
"group": {
"kind": "build",
"isDefault": true
}
}
The "Calculator-Adventure" part is my filename. The expected output is for the code to build and create a .exe file for my code, as stated in the tutorial and said in the VS Code Docs.
However, it currently outputs the following into the terminal:
> Executing task: g++ -g Calculator Adventure.cpp -o Calculator-Adventure <
g++ : The term 'g++' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
The terminal process terminated with exit code: 1"
OK, I finally figured it out. What worked for me was adding the file path to the git bash shell (C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Git) to the System Environment Variables in the Control Panel (how to do that here). Make sure you also have the file path to the MinGW bin folder added to the Environment Variables as well (32bit installer: C:\MinGW\bin) (64bit installer: C:/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/bin) Then, restart VS Code and build (Ctrl+Shift+B) again.
Here's my final code for the .json files:
c_cpp_properties.json:
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.17763.0",
"compilerPath": "C:/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/bin/g++.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-x64",
"browse": {
"path": [
"${workspaceFolder}"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
}
}
],
"version": 4
}
tasks.json:
{
"version": "2.0.0",
"tasks": [
{
"label": "build calculator adventure",
"type": "shell",
"command": "g++",
"args": [
"-g",
"-o",
"Calculator-Adventure",
"Calculator Adventure.cpp"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
For more information, check out this page. It is a really detailed step-by-step guide for using the MinGW compiler for C++ in VS Code (read it carefully). If you have any other trouble, take a look at this tutorial (same tutorial linked in the question). Hope this helps!
Note: in the docs page I linked, they use the 64bit version of MinGW. It should still work with the 32bit version though. Thanks, to #drescherjm for posting the VS Code Docs!
Can someone explain how to get building and debugging to work in VSCode on a Mac?
Let's assume we successfully installed cpp tools:
-Including creating a proper task file that works on a mac.
-The required changes to launch.json
-Any other step required.
(Don't get me wrong, I'm not lazy, I have been trying for more then 2 hours now and it seems that a proper answer for this question can help a lot of people.)
Once you have the C/C++ extension downloaded, you can use the configurations to generate a project.json in debug window of VsCode. If you do not currently have a project.json under the project's .vscode folder, hit F5 and a dropdown list should show up. There you can select C++ (GDB/LLDB), and this should generate a project.json for you to use.
If you want to just hit F5 so it automatically compiles and debugs your program, you will need to add a tasks.json. This can be done by hitting F1 and selecting Tasks: Configure Task Runner and select Other. Replace "echo" with "gcc" (or clang) and replace the args with your .cpp files and don't forget to add -g.
You can find more information in their documentation: https://code.visualstudio.com/docs/languages/cpp
I don't count the time I lost looking for an answer to this question!
I found the vscode-lldb extension and it works fine, all other solutions I found don't work for me.
You still have to create configuration files, here are mine to debug my unit tests:
I'm using googletest and extension c++14 in this example
tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "build & debug tests",
"type": "shell",
"command": "g++",
"args": [
"-g",
"-std=c++14",
"-I/src",
"-lgtest",
"tests/MainTest.cpp",
"-o",
"bin/testMain"
],
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": [
"$gcc"
]
}
]
}
launch.json
{
"version": "0.2.0",
"configurations":
[
{
"name": "Debug Tests C/C++",
"type": "lldb",
"request": "launch",
"program": "${workspaceFolder}/bin/testMain",
"args": [],
"cwd": "${workspaceFolder}/tests",
"preLaunchTask": "build & debug tests"
}
]
}