Ncurses.h ( (.text+0xd): undefined reference to `initscr') visual code Ubuntu - visual-studio-code

I need to know why VS code is not compiling ncurses.h. but it is possible to compile in the terminal ubuntu. this message is appearing on the VS code. (.text+0xd): undefined reference to `initscr'

the code runner extension configuration add -lncurses before -o
"code-runner.executorMap": {
"c": "cd $dir && gcc $fileName -lncurses -o $fileNameWithoutExt && $dir$fileNameWithoutExt "
}

I solved this problem adding "-lncurses" in the "args" (tasks.json)
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}",
"-lncurses" <--------- add the library ("-lncurses" ) here
],

Related

C programming on PI using VS-Code. Get "undefined reference to '...' " when using the quote form of the include directive

I would like to program a PI via VS-Code. When I translate the program I get "undefined referenc to `...' ". It seems that the header files that I include via #include "..." are not translated. If I translate the data in the terminal and then link the headers afterwards, it works. If I have understood correctly, you can set this via the tasks.json. However, I have not yet found out how.
I would like to modify an existing C program that has already been programmed on a PI. The programming is to be done in VS-Code via SSH. However, as soon as I try to run the program, I get numerous error messages with "undefined reference to '...' ".
Even with the minimal program helloworld I get this notification as soon as I want to include local .h-files with #include "...". System files with #include <..> are found.
The following programme
#include <stdio.h>
int main()
{
printf("Hello World\n");
}
is translated without problems.
However, as soon as I add Messages.h
#ifndef MESSAGES_H_INCLUDED
#define MESSAGES_H_INCLUDED
void printMsg(char *str);
#endif // MESSAGES_H_INCLUDED
and Messages.c
#include "Messages.h"
void printMsg(char *str)
{
printf("Testausgabe: %s\n",str);
}
to the project and to the program
#include <stdio.h>
#include "Messages.h"
int main()
{
printf("Hello World\n");
printMsg("Somthing else.\n");
}
The compiler returns
/usr/bin/ld: /tmp/ccBVuwoo.o: in function `main':
helloworld.c:(.text+0x14): undefined reference to `printMsg'
collect2: error: ld returned 1 exit status
And this although all files are stored in the same folder.
If I create the files manually using the terminal and then link them, it works.
$ gcc -c helloworld.c
$ gcc -c Messages.h
$ gcc -o Hello helloworld.o Messages.o
Does this mean that I have to manually create a make file that I have to expand for each new header (that would be a bummer)? Couldn't this also be done automatically via VS-Code? Have I perhaps overlooked something here? Sorry, but I am very new to this.
I am grateful for any help.
Attached is also the automatically generated tasks.json from VSC.
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: gcc Aktive Datei kompilieren",
"command": "/usr/bin/gcc",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Vom Debugger generierte Aufgabe."
}
],
"version": "2.0.0"
}

How to run path setting script in vscode terminal at startup?

I have a script which sets path variables. I have to run this script manually every time I start a new terminal instance.
I am looking for an automated way to run this script at startup for every terminal instance.
I have tried the below approach which doesn't work
{
"terminal.integrated.profiles.windows": {
"Command Prompt": {
"path": "cmd.exe",
"args": [
"-noexit",
"-file",
"h:\\all-languages-env.cmd"
]
}
},
"terminal.integrated.defaultProfile.windows": "Command Prompt",
}
I am expecting the script h:\all-languages-env.cmd to run at every terminal(Command Prompt) startup.
The script file is as below
#ECHO OFF
call devtools isSupported nodejs 16.13.0 || exit /B %ERRORLEVEL%
call devtools isSupported phantomjs 2.1.1 || exit /B %ERRORLEVEL%
set npm_config_registry=http://example.com
set npm_config_user_agent="npm/{npm-version} node/{node-version} {platform} {arch} | NDS %USERNAME% %COMPUTERNAME%"
set SASS_BINARY_SITE=http://example.com/node-sass
set SPAWN_WRAP_SHIM_ROOT=H:\.nodejs
set CHROME_BIN="C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
set npm_config_prefix=H:\.nodejs\npm\8
set npm_config_cache=H:\.nodejs\npm\8\cache
set npm_config_tmp=H:\.nodejs\npm\8\tmp
set NODEJS_16_13_0=H:\nodejs\16
set PATH=%NODEJS_16_13_0%;H:\.nodejs\npm\8;%PATH%
type nul > H:\nodejs\16\lastUsed
set PHANTOMJS_2_1_1=H:\phantomjs\2\bin
set PHANTOMJS_BIN=%PHANTOMJS_2_1_1%\phantomjs.exe
set PATH=%PHANTOMJS_2_1_1%;%PATH%
type nul > H:\phantomjs\2\lastUsed
ECHO javascript environment set
cmd.exe uses different arguments
{
"terminal.integrated.profiles.windows": {
"Command Prompt": {
"path": "cmd.exe",
"args": [
"/K",
"h:\\all-languages-env.cmd"
]
}
},
"terminal.integrated.defaultProfile.windows": "Command Prompt",
}

Unable to use environment variables in VS Code launch configuration

I have the following in my workspace settings.json file:
"terminal.integrated.env.osx": {
"AUTH_TOKEN": "secret_XXXXXX"
}
However, when trying to pass this via a launch command (defined in launch.json):
{
"name": "Example: Query",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/examples/query.py",
"args": [ "${env:AUTH_TOKEN}" ]
}
The resulting command contains an empty string for the argument:
/usr/bin/env /.../.venv/bin/python /.../debugpy/launcher 58644 -- /.../examples/query.py ""
However, if I print the variable from within the script, it is set properly.
I believe there is an ordering issue, such that the launch.json commands are generated before the terminal environment is set up - resulting in empty vars. Any ideas how to propagate the env value to the command line?
Update: I have also tried using a .env file for the variables (rather than settings.json), but the result is the same.
Try using "env" in launch.json...
{
"name": "Example: Query",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/examples/query.py",
"args": ["${AUTH_TOKEN}"], // using var from env on args
"env": {
"AUTH_TOKEN": "XXXX",
"ENV2" : "XXX"
}
}
you can use envs from file too
{
// ...
"args": ["${AUTH_TOKEN}"],
"envFile": "${workspaceFolder}/local.env",
}
You can create a .env file, and then put the variable in there, and read it from the environmental variables in the program instead of it being an argument.

how to pass multiple args to vscode task command?

in tasks.json I am using the "args" property to specify the arguments to pass to "command":"gulp". But when I run the task in vscode, only the first argument is being passed to gulp.
I want to run a gulp task against a single file. In gulpfile.js I am using the process.argv array to retrieve the command line arguments. So, on the command line I enter "gulp copy3 --file abc.js" and the copy3 task is run. The code then reads the argv array to get the name of the file being copied.
this code works from the command line. But does not work when I run it as a task in vscode. How to do that?
the gulpfile.js code:
gulp.task('copy3', function( )
{
console.log(process.argv) ;
let pattern = '*.js' ;
// single file to copy
if (( process.argv.length >= 5 ) && ( process.argv[3] == '--file' ))
{
let fileName = process.argv[4] ;
pattern = fileName ;
}
console.log('pattern:' + pattern ) ;
return gulp.src(pattern).pipe(gulp.dest('dev'));
}) ;
the tasks.json file
{
"version": "2.0.0",
"tasks": [
{
"taskName": "copy3",
"command": "gulp",
"args": [ "copy3", "--file", "${fileBasename}" ],
"problemMatcher": []
}
]
}
Here is the terminal output:
[10:52:57] Using gulpfile C:\vscTest\rpgproj\gulpfile.js
[10:52:57] Starting 'copy3'...
[ 'C:\\Program Files\\nodejs\\node.exe',
'C:\\vscTest\\rpgproj\\node_modules\\gulp\\bin\\gulp.js',
'copy3' ]
pattern:*.js
[10:52:57] Finished 'copy3' after 16 ms
thanks,
I made a couple of small changes, try:
{
"label": "Tasks: copy3",
"type": "shell",
"command": "gulp",
"args": [ "copy3", "--file", "${fileBasename}" ],
"problemMatcher": []
}
and your entire code works perfectly. Make sure to reload vscode after modifying the tasks.json.
VSCode appears to have a built-in gulp extension. This seems to scan your gulpfile for tasks and list them for you. It also seems to ignore the args option.
The workaround is to use the full path to gulp as the command e.g. ./node_modules/.bin/gulp to bypass it.

Error running CoffeeScript in Sublime Text 2

I am new to both CoffeeScript and Sublime Text 2, so any help would be greatly appreciated.
When I try to compile a CoffeeScript test file in Sublime, I get the following error message:
[Error 2] The system cannot find the file specified
[cmd: [u'coffee', u'-c', u'C:\\Users\\username\\Desktop\\test.coffee']]
[dir: C:\Users\username\Desktop]
[path: $HOME/bin:/usr/local/bin:$HOME/bin:/usr/local/bin:C:\Program Files (x86)\ImageMagick-6.9.1-Q16;C:\ProgramData\Oracle\Java\javapath;C:\Program Files\Java\jdk1.8.0_25\bin;C:\Java\bin;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files\nodejs\;C:\Program Files (x86)\GnuWin32\bin;C:\Program Files (x86)\Heroku\bin;C:\Program Files (x86)\git\cmd;C:\Program Files (x86)\Skype\Phone\;C:\RailsInstaller\Git\cmd;C:\RailsInstaller\Ruby2.1.0\bin;C:\Users\username\AppData\Roaming\npm]
[Finished]
Here are my build settings in commands:
{
"path": "$HOME/bin:/usr/local/bin:$PATH",
"cmd": ["coffee","-c","$file"],
"file_regex": "^(...*?):([0-9]*):?([0-9]*)",
"selector": "source.coffee, source.litcoffee, source.coffee.md"
}
Any idea how to fix this problem? Thanks.
I managed to get it working with the following code in the build file:
{
"cmd": [ "coffee", "-m", "-c", "$file" ],
"file_regex": "^(...*?):([0-9]*):?([0-9]*)",
"selector": "source.coffee, source.litcoffee, source.coffee.md",
"windows":
{
"shell": true
}
}