I am using Vscode to compile my c++ programs. I have a program in which auto keyword is used. However when I compile it gives me the error. I have installed c++11 extension pack . But I am not able to solve the problem . I am using LLVM compiler on Macbook. I have tried to install gcc but it stopped on make (I am not sure why). Also I have seen in .json file c++11 is present there. I have tried many options but still getting the following error"warning: auto type specifier is a c++ extension"
This is codeRunner excecutor map code
{
"C_Cpp.updateChannel": "Insiders",
"code-runner.runInTerminal": true,
"workbench.colorTheme": "Visual Studio Light",
"python.pythonPath": "/Library/Frameworks/Python.framework/Versions/3.8/bin/python3",
"editor.renderWhitespace": "none",
"workbench.editorAssociations": {
"*.ipynb": "jupyter-notebook"
},
"jupyter.jupyterServerType": "remote",
"notebook.cellToolbarLocation": {
"default": "right",
"jupyter-notebook": "left"
},
"python.defaultInterpreterPath": "/Library/Frameworks/Python.framework/Versions/3.8/bin/python3",
"C_Cpp.default.cppStandard": "c++11",
"C_Cpp.default.cStandard": "c11",
"C_Cpp.loggingLevel": "Debug",
"json.schemas": [
],
"code-runner.executorMap": {
"javascript": "node",
"java": "cd $dir && javac $fileName && java $fileNameWithoutExt",
"c": "cd $dir && gcc $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
"cpp": "cd $dir && g++ $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
"objective-c": "cd $dir && gcc -framework Cocoa $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
"php": "php",
"python": "python -u",
"perl": "perl",
"perl6": "perl6",
"ruby": "ruby",
"go": "go run",
"lua": "lua",
"groovy": "groovy",
"powershell": "powershell -ExecutionPolicy ByPass -File",
"bat": "cmd /c",
"shellscript": "bash",
"fsharp": "fsi",
"csharp": "scriptcs",
"vbscript": "cscript //Nologo",
"typescript": "ts-node",
"coffeescript": "coffee",
"scala": "scala",
"swift": "swift",
"julia": "julia",
"crystal": "crystal",
"ocaml": "ocaml",
"r": "Rscript",
"applescript": "osascript",
"clojure": "lein exec",
"haxe": "haxe --cwd $dirWithoutTrailingSlash --run $fileNameWithoutExt",
"rust": "cd $dir && rustc $fileName && $dir$fileNameWithoutExt",
"racket": "racket",
"scheme": "csi -script",
"ahk": "autohotkey",
"autoit": "autoit3",
"dart": "dart",
"pascal": "cd $dir && fpc $fileName && $dir$fileNameWithoutExt",
"d": "cd $dir && dmd $fileName && $dir$fileNameWithoutExt",
"haskell": "runhaskell",
"nim": "nim compile --verbosity:0 --hints:off --run",
"lisp": "sbcl --script",
"kit": "kitc --run",
"v": "v run",
"sass": "sass --style expanded",
"scss": "scss --style expanded",
"less": "cd $dir && lessc $fileName $fileNameWithoutExt.css",
"FortranFreeForm": "cd $dir && gfortran $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
"fortran-modern": "cd $dir && gfortran $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
"fortran_fixed-form": "cd $dir && gfortran $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
"fortran": "cd $dir && gfortran $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt"
}
}"
Related
I know there is GNU make utility or Cmake(what I use usually). But I am learning dash/posix shell and I want to write a simple script to compile and build my solution. This is what I have so far.
#!/bin/sh
#THIS BUILD SOLUTION SHOULD WORK ANY PROGRAMMING SOLUTION AS LONG AS IT CONFORMS THE SAME FOLDER STRUCTURE
#THIS BUILD SOLUTION WILL ONLY WORK IN ANY POSIX CONFORMING SHELL
#THIS SOLUTION IS IDEAL FOR VERY SMALL PROGRAMS
PROGRAM_NAME="count_vowels"
SOURCE_DIR="src"
files_timestamp="files_timestamp.txt"
compile() {
for file in $SOURCE_DIR/*.c; do
files="${files:=$files} $file"
done
gcc -ggdb3 -std=c17 $files -Wall -o $1 && echo "An executable $1 has been created" || echo "Failed to complie!!!"
unset file files
return 0
}
compile_with_msg() {
CURRENT_MOD_TIME="$( stat -c %Z $SOURCE_DIR $SOURCE_DIR/headers $SOURCE_DIR/*.c $SOURCE_DIR/headers/*.h )"
echo "$CURRENT_MOD_TIME" > $files_timestamp
echo "Timestamps of files attempting to complie: \n$CURRENT_MOD_TIME\n"
echo "Compiling and linking files..."
compile $PROGRAM_NAME
return 0
}
compile_with_msg_changes(){
echo "Changes in source files detected"
rm $PROGRAM_NAME $files_timestamp && echo "Deleted existing $PROGRAM_NAME executable"
compile_with_msg
return 0
}
build() {
[ ! -d $SOURCE_DIR ] && echo "Cannot find the source directory\nPlease open the build scipt in an editor and check if the source directory information is correct" && return 2
if [ ! -f $PROGRAM_NAME ]; then
[ -f $files_timestamp ] && rm $files_timestamp && echo "Error: $PROGRAM_NAME does not exist but $files_timestamp from last compilation exists\nRemoved $files_timestamp" && return 1
compile_with_msg
else
[ ! -f $files_timestamp ] && rm "$PROGRAM_NAME" && echo "Error: $files_timestamp not found\nDeleted $PROGRAM_NAME" && return 1
CURRENT_MOD_TIME="$( stat -c %Z $SOURCE_DIR $SOURCE_DIR/headers $SOURCE_DIR/*.c $SOURCE_DIR/headers/*.h )"
LAST_MOD_TIME="$( cat $files_timestamp )"
[ "$CURRENT_MOD_TIME" = "$LAST_MOD_TIME" ] && echo "$PROGRAM_NAME is up to date" || compile_with_msg_changes
fi
return 0
}
main() {
err_check=1
while [ "$err_check" -eq 1 ]; do
build
err_check=$?
done
return 0
}
main
Problem is I do not know how I can set a global variable and main fucntion in dash shell.
LAST_MOD_TIME has to be global for it to work and not get updated outside the scope of the build fucntion which is my main function.
Update: this code worked for me. thanks
I am using below apache groovy script in jenkins pipeline to deploy my artifact(dev.ear) to server. I have embedded shell script in groovy to securely copy dev.ear from jenkins slave to target server(unix server).
node('linux') {
stage('Checkout/Download/Deploy') {
timeout(time: 30, unit: 'MINUTES') {
def ziptmp = '.ziptmp'
output = sh returnStdout: true, script:"/bin/rm -rf ${ziptmp}; /bin/mkdir ${ziptmp}; cd ${ziptmp}; /usr/bin/unzip -qq ${tempdir}/${artifactFilename}; ls -ltr; echo *;
if [ -e dev.ear ]
then
scp dev.ear lsfi#${serverName57}:/apps/wls/dev/applications;
echo "COPIED DEV ARTIFACT TO SERVER"
else
echo "DEPLOYMENT PACKAGE DOESNT CONTAIN DEV ARTIFACT"
fi"
echo "RESULT::: ${output}"
}
}
}
I am getting the below error when I trigger Jenkins job
WorkflowScript: 54: expecting anything but ''\n''; got it anyway # line 54, column 171.
ctFilename}; ls -ltr; echo *;
I removed new lines in the shell script and updated code as below :
def ziptmp = '.ziptmp'
output = sh returnStdout: true, script:"/bin/rm -rf ${ziptmp}; /bin/mkdir ${ziptmp}; cd ${ziptmp}; /usr/bin/unzip -qq ${tempdir}/${artifactFilename}; ls -ltr; echo *; if [ -e dev.ear ] then scp dev.ear lsfi#${serverName57}:/apps/wls/dev/applications; fi;"
echo "RESULT::: ${output}"
But I am getting the below error :
line 2: syntax error near unexpected token `fi'
How to resolve this error.
Groovy doesn't like a newline in a GString. According to the Grails cookbook you can make multiline Strings using either '''Your multiline String''' or """Your multiline ${GString}""".
I'm not very sure on bash syntax, but you also seem to be missing a semicolon after if [ -e dev.ear ] according to these docs.
Putting it all together:
output = sh returnStdout: true, script: """/bin/rm -rf ${ziptmp}; /bin/mkdir ${ziptmp}; cd ${ziptmp}; /usr/bin/unzip -qq ${tempdir}/${artifactFilename}; ls -ltr; echo *;
if [ -e dev.ear ];
then
scp dev.ear lsfi#${serverName57}:/apps/wls/dev/applications;
echo "COPIED DEV ARTIFACT TO SERVER"
else
echo "DEPLOYMENT PACKAGE DOESNT CONTAIN DEV ARTIFACT"
fi"
echo "RESULT::: ${output}"""
I want to install package.json using ansible, I'm using the example from the docs, only thing different from this is that I'm using npm not nvm so the tasks look like this
- name: npm install (manual)
npm:
path:"{{ project_path }}"
executable: /usr/bin/npm
{{ project_path }} is path to package.json file, basically it's /srv/example.com/.
The result of this tasks is
TASK [angular : npm install (manual)] ******************************************
task path: /srv/example.com/orchestration/ansible/roles/angular/tasks/main.yml:16
Using module file /usr/local/lib/python2.7/dist-packages/ansible/modules/packaging/language/npm.py
<default> ESTABLISH LOCAL CONNECTION FOR USER: vagrant
<default> EXEC /bin/sh -c 'echo ~ && sleep 0'
<default> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/vagrant/.ansible/tmp/ansible-tmp-1540437954.12-74081721294328 `" && echo ansible-tmp-1540437954.12-74081721294328="` echo /home/vagrant/.ansible/tmp/ansible-tmp-1540437954.12-74081721294328 `" ) && sleep 0'
<default> PUT /tmp/tmpkx6E4h TO /home/vagrant/.ansible/tmp/ansible-tmp-1540437954.12-74081721294328/npm.py
<default> EXEC /bin/sh -c 'chmod u+x /home/vagrant/.ansible/tmp/ansible-tmp-1540437954.12-74081721294328/ /home/vagrant/.ansible/tmp/ansible-tmp-1540437954.12-74081721294328/npm.py && sleep 0'
<default> EXEC /bin/sh -c 'sudo -H -S -n -u root /bin/sh -c '"'"'echo BECOME-SUCCESS-anopitzukaokwawzhqmxqjfzoxjtozxh; /usr/bin/python /home/vagrant/.ansible/tmp/ansible-tmp-1540437954.12-74081721294328/npm.py; rm -rf "/home/vagrant/.ansible/tmp/ansible-tmp-1540437954.12-74081721294328/" > /dev/null 2>&1'"'"' && sleep 0'
ok: [default] => {
"changed": false,
"invocation": {
"module_args": {
"executable": "/usr/bin/npm",
"global": false,
"ignore_scripts": false,
"name": null,
"path": "/srv/example.com/",
"production": false,
"registry": null,
"state": "present",
"version": null
}
}
}
It does not do anything, why? How can I install my package.json, can someone please help me understand how to overcome this, thanks.
This question already has answers here:
How to call a function in shell Scripting?
(7 answers)
Bash - writing function definition in script after first call (as a GOTO/jump problematics)
(3 answers)
How can i check if no arguments are given [duplicate]
(1 answer)
Closed 4 years ago.
I am trying to set up a simple script to compile my project that takes the name of the module(s) to compile, or if no arguments, compile them all.
None of the other answers on StackOverflow have worked for me.
When I try the below script I get this error:
$ ./build.sh updater
Creating the build path: build/0.1.4-master
./build.sh: line 21: updater: command not found
I don't like the ambiguity of the language, it could be a function or a command. But it is what it is. How can I make it execute the function and not try to run a command called updater?
#! /bin/sh -e
# release="0.0.0-$(git rev-parse --abbrev-ref HEAD)"
release="$(git describe --tags --abbrev=0)-$(git rev-parse --abbrev-ref HEAD)"
echo "Creating the build path: build/$release"
mkdir -p "build/$release"
while [ "$#" -gt 0 ]; do
param="$1"
case $param in
s|setup)
setup
shift
;;
l|launcher)
launcher
shift
;;
u|updater)
updater
shift
;;
d|deflector)
deflector
shift
;;
# *)
# setup
# launcher
# updater
# deflector
# shift
# ;;
esac
done
function setup {
echo "Compiling executable: build/$release/setup.exe"
ldc2 "source/setup.d" "source/common.d" -of="build/$release/setup.exe" \
-O3 -ffast-math -release -g
echo "Adding icon to executable: build/$release/setup.exe"
[ -e "build/$release/setup.exe" ] && \
rcedit "build/$release/setup.exe" --set-icon "icons/icon.ico"
}
function launcher {
echo "Compiling executable: build/$release/launcher.exe"
ldc2 "source/launcher.d" "source/common.d" -of="build/$release/launcher.exe" \
-O3 -ffast-math -release -g
echo "Adding icon to executable: build/$release/launcher.exe"
[ -e "build/$release/launcher.exe" ] && \
rcedit "build/$release/launcher.exe" --set-icon "icons/icon.ico"
}
function updater {
echo "Compiling executable: build/$release/updater.exe"
ldc2 "source/updater.d" "source/common.d" -of="build/$release/updater.exe" \
-O3 -ffast-math -release -g
}
function deflector {
echo "Compiling executable: build/$release/deflector.exe"
ldc2 "source/deflector.d" "source/common.d" -of="build/$release/deflector.exe" \
-O3 -ffast-math -release -g
}
echo "Removing residual object files."
find "build/$release" -name "*.obj" -delete
echo "Copying engines file: build/$release/engines.txt"
cp "engines.txt" "build/$release"
echo "Copying libcurl library: build/$release/libcurl.dll"
cp $(which libcurl.dll) "build/$release"
I would also like help making a default case for when there are no arguments passed to the script. My attempt can be seen in the commented block in the switch case.
Appreciate any help.
You need to define the functions before they are called from top-level code.
...
updater () { ... }
...
while [ "$#" -gt 0 ]; do
...
done
I have the following Ruby script that creates a Debian package, which works fine:
#!/usr/bin/ruby
dest = "#{File.dirname(__FILE__)}/../build"
package = "foo"
[
"cd #{dest} && tar czvf data.tar.gz bin console data.sql etc filter install.rb",
"cd #{dest} && tar czvf control.tar.gz control",
"cd #{dest} && echo 2.0 > debian-binary",
"cd #{dest} && ar -cr #{package}.deb debian-binary control.tar.gz data.tar.gz",
"cd #{dest} && mv #{package}.deb ..",
"cd #{dest} && rm data.tar.gz control.tar.gz",
].each do |command|
puts command
system(command)
end
Is there a way in Ruby where I can leave off the "cd #{dest} &&" part of each command?
Dir.chdir(dest) do
# code that shall be executed while in the dest directory
end
Dir.chdir when invoked with a block will change to the given directory, execute the block and then change back.
You can also use it without a block, in which case it will never change back.
Yes. Use Dir.chdir:
#!/usr/bin/ruby
dest = "#{File.dirname(__FILE__)}/../build"
package = "foo"
Dir.chdir dest
[
"tar czvf data.tar.gz bin console data.sql etc filter install.rb",
"tar czvf control.tar.gz control",
"echo 2.0 > debian-binary",
"ar -cr #{package}.deb debian-binary control.tar.gz data.tar.gz",
"mv #{package}.deb ..",
"rm data.tar.gz control.tar.gz",
].each do |command|
puts command
system(command)
end