C++ Issues with VS Code using CodeRunner extension - visual-studio-code

im totally new to this extension. trying to set it up for C++.
what exactly do i need to add into my settings.json file?
currently i have tried these 2 settings:
"code-runner.executorMap":
{
"cpp": "cd $dir && g++ -std=c++14 $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt"
AND
"cpp": "cd $dir && g++ *.cpp -o $fileNameWithoutExt && $fileNameWithoutExt.exe"
},
But I'm getting these errors:
C:\Users\w6\Documents\1. BME\Semester 4\Basics Of Programming 2\Labs\Lab 4>cd "c:\Users\6\Documents\1. BME\Semester 4\Basics Of Programming 2\Labs\Lab 4\" && g++ *.cpp -o Task 2 Circle && Task 2 Circle.exe
g++: error: 2: No such file or directory
g++: error: Circle: No such file or directory

Related

Building postgres from source throws "'utils/errcodes.h' file not found" when called from other makefile

I am currently constructing a Makefile and one of the things it will be doing is downloading and building postgres from source. Before starting to write the makefile file I always used the following set of commands to do this:
curl -LJ https://github.com/postgres/postgres/archive/refs/tags/REL_13_3.zip -o postgres.zip
unzip postgres.zip
rm postgres.zip
cd postgres-REL_13_3
./configure --prefix "`pwd`" --without-readline --without-zlib
make
make install
Executing the above listed commands in the terminal results in the successful installation of postgres. Then I translated these into a makefile which looks as follows:
build:
curl -LJ https://github.com/postgres/postgres/archive/refs/tags/REL_13_3.zip -o postgres.zip
unzip postgres.zip
rm postgres.zip
cd postgres-REL_13_3 \
&& ./configure --prefix "`pwd`" --without-readline --without-zlib \
&& $(MAKE) \
&& $(MAKE) install
Running this Makefile results in the error:
../../src/include/utils/elog.h:71:10: fatal error: 'utils/errcodes.h' file not found
It seems that something about calling the make from another Makefile causes a referencing issue with the files during the build process, but I just can figure out for the life of me what I have to change to fix this.
It appears to be the influence of Makefile enviromental variables. I didn't discover the exact mechanism, but unsetting them helps.
build:
curl -LJ https://github.com/postgres/postgres/archive/refs/tags/REL_13_3.zip -o postgres.zip
unzip postgres.zip
rm postgres.zip
unset MAKELEVEL && unset MAKEFLAGS && unset MFLAGS && cd postgres-REL_13_3 \
&& ./configure --prefix "`pwd`" --without-readline --without-zlib \
&& $(MAKE) \
&& $(MAKE) install

How to run my code in the right path with WSL? I have edit settings.json already

I setup WSL Ubuntu but I can't run my code in the right path with WSL .
How to run my code in the right path with WSL ?
This is my settings.json
"code-runner.runInTerminal": true
"terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\wsl.exe"
"code-runner.executorMap":
{
"c": "cd $(wslpath $dir) & gcc $fileName -o $fileNameWithoutExt & ./$fileNameWithoutExt"
"cpp": "g++ $fileName -o $fileNameWithoutExt -std=c++11 & ./$fileNameWithoutExt"}\
"python": "python3 -u ./$fileName"
}
When I run my code with "ctrl+alt+N"
The output became:
jamesqian#J:/mnt/c/Users/Jamesqian/Desktop/tmp$ cd $(wslpath "c:\Users\Jamesqian\Desktop\tmp\") & gcc test.c -o test & ./test
wslpath is here

How to make Code Runner run in external terminal (Command Prompt)?

So, basically the Code Runner in Visual Studio Code can run in the integrated terminal. How can I make it to run in external terminal, which is command prompt because I need to present my program's output to my classmates, so it's not convenient to display it through the integrated one.
I know there's a software like Dev-C++ that can run in external terminal, but I love to use this VS Code because of its clean UI, and the Code Runner plugin is pretty good doing its job. How can I do it just with one-click? Is there any configuration?
Supposing that you are using Windows, All you need to do is to put the "start" command before the .exe file you want to run in the code-runner.executorMap option. Here is an example:
"code-runner.executorMap": {
"cpp": "g++ $fullFileName -o $fileNameWithoutExt.exe && start $fileNameWithoutExt.exe"
}
If anybody wondering how to edit "code-runner.executorMap"":{} nether of above answers provide a way to get into settings.json. So I'm writing this answer just to clarify how you can get into the code runner settings.
go to the File -> Preferences -> Settings and search for 'executorMap' in search tab -> then click Code-runner:Executor Map and edit the code as follows for C,
"code-runner.executorMap": {
"c": "g++ $fullFileName -o $fileNameWithoutExt.exe && start $fileNameWithoutExt.exe"
}
For C++ edit the code as follows,
"code-runner.executorMap": {
"cpp": "g++ $fullFileName -o $fileNameWithoutExt.exe && start $fileNameWithoutExt.exe"
}
Note: This solution is for windows environments
On Windows, when Default Shell, in VSCode, is set to PowerShell 7 (pwsh.exe) I use:
"code-runner.executorMap": {
"c": "cd $dir && gcc -Wall -Wextra -pedantic -std=c18 $fileName -o $fileNameWithoutExt.exe && Start-Process -FilePath pwsh -ArgumentList \"-Command &{.\\$fileNameWithoutExt.exe; pause}\"",
}
When Default Shell, in VSCode, is set to Command Prompt (cmd.exe) I use
"code-runner.executorMap": {
"c": "cd $dir && gcc -Wall -Wextra -pedantic -std=c18 $fileName -o $fileNameWithoutExt.exe && Start pwsh -Command \"& {.\\$fileNameWithoutExt.exe; pause}\"",
}
In both cases "pause" will keep the external PowerShell 7 terminal open after the code is executed.
For Linux :
If you are running linux then you can paste this in
code-runner.executorMap
If you want to execute your code with gnome terminal:
"code-runner.executorMap": {
"c": "cd $dir && gcc $fileName -o $fileNameWithoutExt && gnome-terminal -- bash -c './$fileNameWithoutExt ; read line'",
"cpp": "cd $dir && g++ $fileName -o $fileNameWithoutExt && gnome-terminal -- bash -c './$fileNameWithoutExt ; read line'",
}
use this if you are running ubuntu or if you have gnome terminal. 'read line' is used to keep the window open untill any key is pressed after the code is executed
If you want to execute your code with Xterm:
"code-runner.executorMap": {
"c": "cd $dir && gcc $fileName -o $fileNameWithoutExt && xterm -hold ./$fileNameWithoutExt",
"cpp": "cd $dir && g++ $fileName -o $fileNameWithoutExt && xterm -hold ./$fileNameWithoutExt"
}
you can use this if you have xterm. -hold flag is used to keep the window open after the code is executed
If you're using Code Runner you can add this to your settings.json:
"code-runner.executorMap":{
"cpp": "cd $dir && g++ -O2 -std=c++17 $fileName -o $fileNameWithoutExt && start cmd \"/k ; $fileNameWithoutExt\""
},
This will keep the cmd after the execution of program.
I don't know why konsole -- bash -c "command" command is now working for kde konsole So, if you use kde then install gnome-terminal first
If you want to run an external terminal then add this to settings.json vscode
"code-runner.runInTerminal": true,
"code-runner.preserveFocus": false,
"code-runner.executorMap": {
"c": "cd $dir && echo $PWD > /tmp/vsDir && echo $fileName > /tmp/vsFile && gnome-terminal -- bash -c 'dir=\"$(cat /tmp/vsDir)\" && cd $dir;File=\"$(cat /tmp/vsFile)\" && gcc $File -lm;./a.out;echo Hit Enter to EXIT;read lines;rm *.out' && exit",
"cpp": "cd $dir && echo $PWD > /tmp/vsDir && echo $fileName > /tmp/vsFile && gnome-terminal -- bash -c 'dir=\"$(cat /tmp/vsDir)\" && cd $dir;File=\"$(cat /tmp/vsFile)\" && g++ $File -lm;./a.out;echo Hit Enter to EXIT;read lines;rm *.out' && exit",
"java": "cd $dir && echo $PWD > /tmp/vsDir && echo $fileName > /tmp/vsFile && echo $fileNameWithoutExt > /tmp/javaRun && gnome-terminal -- bash -c 'dir=\"$(cat /tmp/vsDir)\" && cd $dir;File=\"$(cat /tmp/vsFile)\" && javac $File;binary=\"$(cat /tmp/javaRun)\";java $binary;echo Hit Enter to EXIT;read lines;rm *.class' && exit",
"python": "cd $dir && echo $PWD > /tmp/vsDir && echo $fileName > /tmp/vsFile && gnome-terminal -- bash -c 'cd;source /home/$USER/anaconda3/bin/activate; conda activate MyPy38;dir=\"$(cat /tmp/vsDir)\" && cd $dir;File=\"$(cat /tmp/vsFile)\" && python -u $File;echo Hit Enter to EXIT;read lines' && exit",
},
"terminal.integrated.inheritEnv": false
If you don't want to remove the binary or exe or class file then remove rm *.out or rm *.outor similar commands from it.
For Anaconda Python source /home/$USER/anaconda3/bin/activate; is for activate base anaconda env and then active my env name MyPy38 at conda activate MyPy38;. If you run python from the default python3 and pip libreary then replace the command with
"python": "cd $dir && echo $PWD > /tmp/vsDir && echo $fileName > /tmp/vsFile && gnome-terminal -- bash -c 'cd;dir=\"$(cat /tmp/vsDir)\" && cd $dir;File=\"$(cat /tmp/vsFile)\" && python3 -u $File;echo Hit Enter to EXIT;read lines' && exit",
or, You can use project base python envs "Like suppose python interpreter directory is /From/Base/To/Python/Binary/ directory " so, It will be
"python": "cd $dir && echo $PWD > /tmp/vsDir && echo $fileName > /tmp/vsFile && gnome-terminal -- bash -c 'cd;dir=\"$(cat /tmp/vsDir)\" && cd $dir;File=\"$(cat /tmp/vsFile)\" && /From/Base/To/Python/Binary//python -u $File;echo Hit Enter to EXIT;read lines' && exit",
For those using Xfce terminal on Linux:
This will also pause the terminal after execution, requiring you to press any key to exit. Your program name and path can contain spaces as well.
You can change it to any other language with slight modifications.
"code-runner.executorMap": {
"cpp" : "cd $dir && g++ \"$fileName\" -o \"$fileNameWithoutExt\" && xfce4-terminal -e \"bash -c '\\\"./$fileNameWithoutExt\\\";echo;read -n 1 -s -r -p \\\"Press any key to exit...\\\"'\"",
}

How to fix 'VST (verified software toolchain)2.3 building error“ with coq 8.8.1

I want to install VST 2.3 with coq 8.8.1 to learn the VC volume on software foundation. but I encounter an error.
I using method A that is recommended in vst BUILD_ORGANIZATION.md and that does not work for me.
jon#jon-lab:~/Documents/vst$ make
Makefile:606: .depend: No such file or directory
coqdep ... >.depend
coqdep -R compcert/lib compcert.lib -R compcert/common compcert.common -R compcert/arm compcert.arm -R compcert/cfrontend compcert.cfrontend -R compcert/flocq compcert.flocq -R compcert/exportclight compcert.exportclight 2>&1 >.depend `find compcert/lib compcert/common compcert/arm compcert/cfrontend compcert/flocq compcert/exportclight -name "*.v"` | grep -v 'Warning:.*found in the loadpath' || true
find: ‘compcert/arm’: No such file or directory
Fatal error: exception Sys_error("compcert/arm: No such file or directory")
coqdep -Q msl VST.msl -Q sepcomp VST.sepcomp -Q veric VST.veric -Q floyd VST.floyd -Q progs VST.progs -Q compcert/lib compcert.lib -Q compcert/common compcert.common -Q compcert/arm compcert.arm -Q compcert/cfrontend compcert.cfrontend -Q compcert/flocq compcert.flocq -Q compcert/exportclight compcert.exportclight 2>&1 >>.depend `find compcert/lib compcert/common compcert/arm compcert/cfrontend compcert/flocq compcert/exportclight msl sepcomp veric floyd progs -name "*.v"` | grep -v 'Warning:.*found in the loadpath' || true
find: ‘compcert/arm’: No such file or directory
Fatal error: exception Sys_error("compcert/arm: No such file or directory")
echo -Q msl VST.msl -Q sepcomp VST.sepcomp -Q veric VST.veric -Q floyd VST.floyd -Q progs VST.progs -Q compcert/lib compcert.lib -Q compcert/common compcert.common -Q compcert/arm compcert.arm -Q compcert/cfrontend compcert.cfrontend -Q compcert/flocq compcert.flocq -Q compcert/exportclight compcert.exportclight > _CoqProject
util/coqflags > _CoqProject-export
COQC msl/Axioms.v
Warning: Cannot open compcert/arm [cannot-open-path,filesystem]
COQC msl/Extensionality.v
Warning: Cannot open compcert/arm [cannot-open-path,filesystem]
COQC msl/base.v
Warning: Cannot open compcert/arm [cannot-open-path,filesystem]
COQC msl/eq_dec.v
Warning: Cannot open compcert/arm [cannot-open-path,filesystem]
COQC msl/sig_isomorphism.v
Warning: Cannot open compcert/arm [cannot-open-path,filesystem]
COQC msl/ageable.v
Warning: Cannot open compcert/arm [cannot-open-path,filesystem]
COQC msl/sepalg.v
Warning: Cannot open compcert/arm [cannot-open-path,filesystem]
COQC msl/psepalg.v
Warning: Cannot open compcert/arm [cannot-open-path,filesystem]
File "./msl/psepalg.v", line 9, characters 15-40:
Error: Unable to locate library VST.msl.sepalg_generators.
Makefile:430: recipe for target 'msl/psepalg.vo' failed
make: *** [msl/psepalg.vo] Error 1
I using ubuntu 1804 64bit and I don't know why they're the vst want to open compcert/arm and the _CoqProject file is generated by Makefile.so I can't fix the unable to locate library error.

fail building ffmpeg for armv6-7

I've been trying to build ffmpeg in every possible way I can think of. I'm trying with the latest revision from their git repository and with a build script which I have confirmation that it works, it's from this question: iPhone SDK 4.3 libav compiling problem. The script was updated yesterday and apparently works for the guy in the question.
my problem is that it doesn't generate the .a files (or actually any files) for armv6 anc armv7. and therefor the lipo commands, to concat into universal libs, fail. I've also tried using the build scripts from iFrameExtractor without any success it also fails with the lipo-commands in the end, i get the following:
lipo: can't open input file: ./compiled/armv6/lib/libavcodec.a (No such file or directory)
lipo: can't open input file: ./compiled/armv6/lib/libavdevice.a (No such file or directory)
lipo: can't open input file: ./compiled/armv6/lib/libavfilter.a (No such file or directory)
lipo: can't open input file: ./compiled/armv6/lib/libavformat.a (No such file or directory)
lipo: can't open input file: ./compiled/armv6/lib/libavutil.a (No such file or directory)
lipo: can't open input file: ./compiled/armv6/lib/libpostproc.a (No such file or directory)
lipo: can't open input file: ./compiled/armv6/lib/libswscale.a (No such file or directory)
and i have also posted the entire output here if anyone has any idea what to look for there (because i don't know where to start, it almost 5000 lines of output.)
i should also mention that i'm compiling it for armv6, armv7 and i386. I want to import it in XCode to get H.264 frames from video feed.
when i try to build for armv6 i use the following configure:
./configure \
--enable-cross-compile \
--arch=arm \
--extra-cflags='-arch armv6' \
--extra-ldflags='-arch armv6' \
--target-os=darwin \
--cc=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc \
--sysroot=/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk \
--cpu=arm1176jzf-s \
--extra-ldflags=-L/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneSimulator4.3.sdk/usr/lib/system \
--prefix=compiled/armv6
and get the following output:
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc is unable to create an executable file.
C compiler test failed.
If you think configure made a mistake, make sure you are using the latest
version from Git.  If the latest version fails, report the problem to the
ffmpeg-user#ffmpeg.org mailing list or IRC #ffmpeg on irc.freenode.net.
Include the log file "config.log" produced by configure as this will help
solving the problem.
so the question, what c compiler should I use? i've tried different:
arm-apple-darwin10-gcc-4.2.1
arm-apple-darwin10-llvm-gcc-4.2
gcc
but with the same result. gcc works for both i386 and armv7 so i guess it should work for armv6 aswell
i used the following to compile only for armv6 and armv7. I couldn't get it working for i386, i receive errors that the cputype and subcputype are wrong. apparently the cputype is supposed to be x86 and subcputype should be intel.
anyhow i used the following build scripts to compile (i ended up using gcc and it worked, it was the configure flags that were wrong from the beginning i guess) for the arm architectures:
build script:
#!/bin/sh
set -e
SCRIPT_DIR=$( (cd -P $(dirname $0) && pwd) )
DIST_DIR_BASE=${DIST_DIR_BASE:="$SCRIPT_DIR/dist"}
if [ -d ffmpeg ]
then
echo "Found ffmpeg source directory, no need to fetch from git..."
else
echo "Fetching ffmpeg from git://git.videolan.org/ffmpeg.git..."
git clone git://git.videolan.org/ffmpeg.git
fi
ARCHS=${ARCHS:-"armv6 armv7"}
for ARCH in $ARCHS
do
FFMPEG_DIR=ffmpeg-$ARCH
if [ -d $FFMPEG_DIR ]
then
echo "Removing old directory $FFMPEG_DIR"
rm -rf $FFMPEG_DIR
fi
echo "Copying source for $ARCH to directory $FFMPEG_DIR"
cp -a ffmpeg $FFMPEG_DIR
cd $FFMPEG_DIR
DIST_DIR=$DIST_DIR_BASE-$ARCH
mkdir -p $DIST_DIR
case $ARCH in
armv6)
EXTRA_FLAGS="--enable-cross-compile --target-os=darwin --arch=arm --cpu=arm1176jzf-s"
EXTRA_CFLAGS="-arch $ARCH"
EXTRA_LDFLAGS="-arch $ARCH"
;;
armv7)
EXTRA_FLAGS="--enable-cross-compile --target-os=darwin --arch=arm --cpu=cortex-a8 --enable-pic"
EXTRA_CFLAGS="-arch $ARCH"
EXTRA_LDFLAGS="-arch $ARCH"
;;
x86_64)
EXTRA_CC_FLAGS="-mdynamic-no-pic"
;;
esac
echo "Configuring ffmpeg for $ARCH..."
./configure \
--prefix=$DIST_DIR \
--extra-ldflags=-L/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk/usr/lib/system \
--disable-bzlib \
--disable-doc \
--disable-ffmpeg \
--disable-ffplay \
--disable-ffserver \
--cc=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc \
--sysroot=/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk \
--extra-ldflags="$EXTRA_LDFLAGS" \
--extra-cflags="$EXTRA_CFLAGS" \
$EXTRA_FLAGS
echo "Installing ffmpeg for $ARCH..."
make && make install
cd $SCRIPT_DIR
if [ -d $DIST_DIR/bin ]
then
rm -rf $DIST_DIR/bin
fi
if [ -d $DIST_DIR/share ]
then
rm -rf $DIST_DIR/share
fi
done
and combine libs script:
#!/bin/bash
set -e
ARCHS="armv6 armv7"
for ARCH in $ARCHS
do
if [ -d dist-$ARCH ]
then
MAIN_ARCH=$ARCH
fi
done
if [ -z "$MAIN_ARCH" ]
then
echo "Please compile an architecture"
exit 1
fi
OUTPUT_DIR="dist-uarch"
rm -rf $OUTPUT_DIR
mkdir -p $OUTPUT_DIR/lib $OUTPUT_DIR/include
for LIB in dist-$MAIN_ARCH/lib/*.a
do
LIB=`basename $LIB`
LIPO_CREATE=""
for ARCH in $ARCHS
do
if [ -d dist-$ARCH ]
then
LIPO_CREATE="$LIPO_CREATE-arch $ARCH dist-$ARCH/lib/$LIB "
fi
done
OUTPUT="$OUTPUT_DIR/lib/$LIB"
echo "Creating: $OUTPUT"
lipo -create $LIPO_CREATE -output $OUTPUT
lipo -info $OUTPUT
done
echo "Copying headers from dist-$MAIN_ARCH..."
cp -R dist-$MAIN_ARCH/include/* $OUTPUT_DIR/include
then i import the .a files from BUILD-FOLDER/dist-uarch and it builds in xcode like a charm!