I would like to compile and run fortran subprograms using Visual Studio code.
When I try debugging the code, I get an error stating that the "prelaunch task 'gfortran' terminated with exit code 1", with the following console message:
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../libmingw32.a(main.o):(.text.startup+0xa0): undefined reference to `WinMain#16'
collect2.exe: error: ld returned 1 exit status
The terminal process "C:\MinGW\bin\gfortran.exe '-g', 'D:\......\params.f95', '-o', 'D:\.......\params.exe'" terminated with exit code: 1.
When I click 'show errors' it says that 'no problems have been detected in the worskpace so far'
My json file configurations for the folder are as follows:
Launch.json
{
"version": "2.0.0",
"configurations": [
{
"name": "Fortran Launch (GDB)",
"type": "cppdbg",
"request": "launch",
"targetArchitecture": "x86",
"program": "${workspaceRoot}\\${fileBasenameNoExtension}.exe",
"miDebuggerPath": "gdb.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceRoot}",
"externalConsole": true,
"preLaunchTask": "gfortran"
}
]
}
tasks.json
{
"version": "2.0.0",
"command": "gfortran",
"args": [
"-g",
"${file}",
"-o",
"${workspaceRoot}\\${fileBasenameNoExtension}.exe"
]
}
I tried many of the fixes found from the web, such as changing the default setting to save file before run, reinstalling gfortran etc., but to no avail. When I try compiling from the command prompt, I do not have any errors, but when I use the flag -g, I have the same error about 'undefined reference to WinMain#16'. Also, I have no problem using the settings to run a single fortran code (without subprograms).
I have a Windows-32 architecture, and I have used MinGW to install gfortran. I have set the System Environment Variable 'Path' to include this folder.
I hope the problem is clear, please help me with this.
Related
I'm getting a Task 'run' not found in root project 'Project-Name' whenever I try to do gradle run.
It was built successfully. I did see however, in my tasks.json file it does contain the run task.
In the documentation visual studio has this:
"version": "2.0.0",
"tasks": [
{
"type": "typescript",
"tsconfig": "tsconfig.json",
"problemMatcher": ["$tsc"],
"group": {
"kind": "build",
"isDefault": true
}
I have something similar, but there is a yellow line under:
"group": {
"kind": "build",
"isDefault": true
}
With the error showing up as
"Incorrect type. Expected "string".
Documentation shows this is correct - could this be the issue on why it can't locate the Run task or is it something else?
Thank you
I have configured my task.json and c_cpp_properties.json so that I may compile my main.cpp program. In order to proceed, I must press
Ctrl + Shift + B
As soon as I do a terminal pops up and alters me of an error:
Executing task in folder C++: C:\MinGW\bin\g++.exe -g main.cpp -o c:\Users\Me\Desktop\C++\.vscode\tasks.exe <
/bin/bash: C:MinGWbing++.exe: command not found
The terminal process terminated with exit code: 127
Terminal will be reused by tasks, press any key to close it.
I don't why this is happening since I've already checked that MinGW is installed in my computer with the correct PATH. To ensure that I do I typed the following in the terminal:
g++ --version
g++ (MinGW.org GCC-8.2.0-3) 8.2.0
Copyright (C) 2018 Free Software Foundation, Inc.
I also checked the path according to this figure
The only closest problem related to mine is in this Github link. I've also already tried changing the file directory shown in the code below using this thread but I still encounter this error.
Here are my JSON files which are inside my .vscode file:
tasks.json:
{
"version": "2.0.0",
"tasks": [
{
"label": "echo",
"type": "shell",
"command": "C:\\MinGW\\bin\\g++.exe",
"args": [
"-g",
"main.cpp",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": []
}
]
}
c_cpp_properties.json:
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.17134.0",
"compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.14.26428/bin/Hostx64/x64/cl.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "msvc-x64",
"browse": {
"path": [
"${workspaceRoot}",
"C:\\MinGW\\lib\\gcc\\mingw32\\8.2.0\\include\\c++"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
}
}
],
"version": 4
}
I should expect to see a ".exe" after compiling but I can't due to the error.
After spending two days messing around with this I've finally able to correct setup C++ on VS Code and resolved the error.
According to the png image from above, I've included "C:\MinGW\bin" within the user variable "Path" under the dialogue box "User variables for Me". After a simple restart on my computer, I was able to build my project (Shift + Ctrl + B) with no problems.
I'm having trouble getting anaconda prompt to work with VSCode shell launcher.
Im trying to set up the Shell Launcher Extension for VSCode to run the following terminals on windows 10:
Git Bash,
CMD,
Powershell,
Anaconda Prompt
I have configured my settings. json with the following code:
{
"terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe",
"shellLauncher.shells.windows": [
{
"shell": "C:\\Program Files\\Git\\bin\\bash.exe",
"args": [],
"label": "bash"
},
{
"shell": "cmd",
"args": [],
"label": "cmd"
},
{
"shell": "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
"args": [],
"label": "PowerShell"
},
{
"shell": "cmd",
"args": [
"/K",
"C:\\ProgramData\\Anaconda3\\Scripts\\activate.bat C:\\ProgramData\\Anaconda3"
],
"label": "Conda"
}
]
}
As you can see Bash is my default terminal that opens with ctrl+` and my shell launcher opens with ctrl+shift+t .
The Shell launcher lists my all of the entries above, and all terminals launch through Shell Launcher except Anaconda Prompt.
From what I understand according to this blog post: How to Add Anaconda Prompt to VSCode Integrated Terminal,
Anaconda Prompt extends windows cmd and I just need to pass in the Arguments that run the script.
I pulled the args out of the properties of Anaconda menu, but when I try to launch the anaconda prompt I get the following error message:
The terminal process command 'cmd /K 'C:\ProgramData\Anaconda3\Scripts\activate.bat C:\ProgramData\Anaconda3'' failed to launch (exit code: 2)
Here is the path from the properties menu of the anaconda prompt desktop icon that works normally.
%windir%\System32\cmd.exe "/K" C:\ProgramData\Anaconda3\Scripts\activate.bat C:\ProgramData\Anaconda3
I have tried adding the actual path of cmd as:
%windir%\\System32\\cmd.exe
, but this just removes the Anaconda prompt from the Shell Launcher drop-down menu completely.
How can I fix this?
Any help will be appreciated. :)
I fixed it. "cmd.exe" was the path that worked.
For anyone else who want's to set up multiple integrated terminals in VScode for windows 10 here's the settings for the Shell Launcher extension that I am using.
This sets the my default terminal to Git Bash and allows me to open bash, cmd, Anaconda prompt and powershell with Shell Launcher.
"terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe",
"shellLauncher.shells.windows": [
{
"shell": "C:\\Program Files\\Git\\bin\\bash.exe",
"args": [],
"label": "bash"
},
{
"shell": "cmd.exe",
"args": [],
"label": "cmd"
},
{
"shell": "cmd.exe",
"args": [
"/K",
"C:\\ProgramData\\Anaconda3\\Scripts\\activate C:\\ProgramData\\Anaconda3"
],
"label": "Conda"
},
{
"shell": "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
"args": [],
"label": "PowerShell"
}
]
Happy Hacking. ;)
I set up a tasks.json file to build my C code in VS Code, which also includes a problem matcher.
{
"version": "0.1.0",
"command": "gcc",
"args": ["-Wall", "-o", "${fileBasenameNoExtension}", "${fileBasename}"],
"problemMatcher": {
"owner": "cpp",
"fileLocation": ["relative", "${workspaceRoot}"],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
}
Since I use variable substitution for the source file and the executable, it would work as portable solution for comfortable compilation of single source files. Unfortunately, VSC requires the tasks.json to be defined separately for each project, i.e. each folder. Is there any way to derive the suitable build task from file extension globally for any file?
I have a program, which is using what they called wmake to build the code and it's very convenient. Suppose I have a folder and a C++ file: /path/to/file.C, all I have to do is go to /path/to folder and then type the wmake command and return and all is set.
When I am using sublimetext, I would like to open this file.C file and then ctrl+B to build it, but it doesn't work. Currently I customized a build system like:
{
"cmd": "wmake"
}
the error shows as
[Errno 2] No such file or directory
[cmd: wmake]
[dir: /path/to/file.C]
[path: /home/meee/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/bin]
[Finished]
Anyone knows how to customize a build system in sublimetext2? I read the online mannual but still have no clue. Thanks
My aim
All I want to do is to get the same effect as I type in shell window a simple
wmake /path/to
Edit-1
I tried this, it's not working either, the same error. I dont understand why "no such file"?
{
"cmd": "wmake",
"selector" : "source.C",
"shell": false,
"working_dir" : "$file_path",
"variants":
[
{
"name": "Run",
"cmd": ["bash", "-c", "wmake '${file_path}'"]
}
]
}
Edit-2
I tried using full path of wmake, and the error complains environment variable $WM_OPTIONS not set. So in shell, every time the ~/.bashrc is auto loaded, and to initialize all the environment variables, but this is not so in Sublime!!!!!!!!!!!!! What should I do???
{
"cmd": "/fullpath/to/wmake",
"selector" : "source.C",
"shell": false,
"working_dir" : "$file_path",
"variants":
[
{
"name": "Run",
"cmd": ["bash", "-c", "/fullpath/to/wmake '${file_path}'"]
}
]
}
Your build command isn't complete. See my customized C build:
{
"cmd" : ["/usr/local/gfortran/bin/gcc", "$file_name", "-o", "${file_base_name}", "-lgsl","-lgslcblas", "-lm" , "-Wall"],
"selector" : "source.c",
"shell":false,
"working_dir" : "$file_path",
"variants":
[
{
"name": "Run",
"cmd": ["bash", "-c", "/usr/local/gfortran/bin/gcc '${file}' -lgsl -lgslcblas -lm -Wall -o '${file_path}/${file_base_name}' && '${file_path}/${file_base_name}'"]
}
]
}