Compile MQ5 file with VS Code extension on linux

Compile MQ5 file with VS Code extension on linux

Manage alerts

Loading saved threads...

MageScript · External communityPost link
External question — Stack Overflow Stack Exchange Author: MageScript Original post: https://stackoverflow.com/questions/76391990 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. I'd like to compile a mq5 file by using Visual Studio Code on linux operating system. Would be great to use an extension like "MQL tools" but, this extension seems to be working on Windows only. My Metatrader runs by using Wine. Thanks.
Quote
Report
Juan · External communityPost link
External answer — Stack Overflow Stack Exchange Author: Juan Original post: https://stackoverflow.com/a/77816868 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. You can compile MQL5 manually from the terminal in Linux using Wine like this: wine /path/to/editor.exe /compile:path/to/file.mq5 /log:$/path/to/log.log Mine looks like this for example: wine /home/juan/.wine/PUPrime/MetaEditor64.exe /compile:/home/juan/.wine/PUPrime/MQL5/Experts/test.mq5 /log:/home/juan/.wine/PUPrime/MQL5/loggity.log ⚠️ Important note ⚠️ : MQL will not compile if you have any spaces anywhere in the file path. Because the Program Files directory in Wine and my MetaTrader directory, PU Prime MT5 Terminal , both have spaces I ran this command to create a symlink and have a directory path without spaces: ln -s "${HOME}/.wine/drive_c/Program Files/PU Prime MT5 Terminal" "${HOME}/.wine/PUPrime" /home/juan/.wine/drive_c/Program Files/PU Prime MT5 Terminal becomes /home/juan/.wine/PUPrime If you actually want to see what happened when you compiled you can do something like this: echo -n '' > /home/juan/.wine/PUPrime/MQL5/loggity.log wine /home/juan/.wine/PUPrime/MetaEditor64.exe /compile:/home/juan/.wine/PUPrime/MQL5/Experts/test.mq5 /log:/home/juan/.wine/PUPrime/MQL5/loggity.log cat /home/juan/.wine/PUPrime/MQL5/loggity.log *The first line just clears the compiler log and the last line reads the log into terminal If you want to be able to do it directly from VSCode you could save above into a bash script and then use a VSCode Task to call it like this: tasks.json: { "version": "2.0.0", "tasks": [ { "label": "MQL COMPILE", "type": "shell", "command": "/home/juan/.wine/PUPrime/MQL5/compile_script.sh", "args": [ "${relativeFile}" ] } ] } compile_script.sh: #!/bin/bash # Check if a filename is provided & extract it if [ -z "$1" ]; then echo "Error: Missing filename argument." exit 1 fi filename="$1" # First Task: Clear log echo "Running MQL: clear log" echo -n '' > /home/juan/.wine/PUPrime/MQL5/loggity.log # Second Task: Compile file echo "Running MQL: compilel" wine /home/juan/.wine/PUPrime/MetaEditor64.exe /compile:/home/juan/.wine/PUPrime/MQL5/${filename} /log:/home/juan/.wine/PUPrime/MQL5/loggity.log # Third task: Real log echo "Running MQL: read log" cat /home/juan/.wine/PUPrime/MQL5/loggity.log My Setup Here is the bash script I use instead of the one above: #!/bin/bash clear # Set filename and syntax flag arg1_filename="$1" arg2_syntax_flag="${2:-}" # Paths LogFullPath="/home/juan/.wine/MQL5/loggity.log" EditorFullPath="/home/juan/.wine/PUPrime/MetaEditor64.exe" CompileFullPath="/home/juan/.wine/PUPrime/MQL5/${arg1_filename}" # Clear log > "$LogFullPath" # Compile or check syntax wine "$EditorFullPath" "/compile:$CompileFullPath" "/log:$LogFullPath" "$arg2_syntax_flag" > /dev/null 2>&1 # Read log printf " ⌛ %s: %s\n" "$([ -n "$arg2_syntax_flag" ] && echo "Checking Syntax" || echo "Compiling")" "$arg1_filename" Log=$(iconv -f UTF-16LE -t UTF-8 "$LogFullPath" | tac) # Convert to UTF-8, reverse order while IFS= read -r line; do # Read log line by line if [[ "$line" =~ 0\ errors,\ 0\ warning ]]; then printf "\e[38:5:114m ✅ 0 Errors, 0 Warnings!\e[0m\n" # Green Line: no errors, no warnings exit 0 elif [[ "$line" =~ :\ error|:\ warning ]]; then num=$(echo "$line" | sed -n 's/.*(\([0-9]\+\),.*/\1/p') # Extract error/warning line number msg=$(echo "$line" | sed -n 's/.*[0-9]\+:\ \(.*\)$/\1/p') # Extract error/warning message loc=$(echo "$line" | sed -n 's/.*[\\\/]\(.*\)([0-9]*,[0-9]*).*$/\1/p') # Extract error/warning location if [[ "$line" == *": error"* ]]; then printf "\e[0;38;5;196m❌ %s\t%s %s\e[0m\n" "$num" "$loc" "$msg" # Red Line: error else printf "\e[0;38;5;220m🖐️ %s\t%s %s\e[0m\n" "$num" "$loc" "$msg" #Yellow Line: warning fi fi done <<< "$Log" exit 0 *Note that this hides a lot of information, just tells you if your file compiles correctly and if not shows only the errors and warnings. Formatted for easier readability and also accepts the syntax check flag Syntax check only The MetaTrader compiler lets you also just check the syntax of your file instead of a doing a full compile by adding a /s flag to the command. This is nice because it's much faster than a full compile, especially if you project has a lot of includes in it. The compile code can take /s flag as argument as well to run the syntax check. tasks.json Here we have a separate task just for the syntax check: { "version": "2.0.0", "tasks": [ { "label": "MQL COMPILE", "type": "shell", "command": "${workspaceFolder}/compile_script.sh", "args": [ "${relativeFile}" ], "presentation": { "showReuseMessage": false, "panel": "dedicated", "clear": true }, "problemMatcher": [], "group": { "kind": "build", "isDefault": true } }, { "label": "MQL SYNTAX CHECK", "type": "shell", "command": "${workspaceFolder}/compile_script.sh", "args": [ "${relativeFile}", "/s" ], "presentation": { "showReuseMessage": false, "panel": "dedicated", "clear": true }, "problemMatcher": [] } ] } Keybinding The compile task is set as the default build task so it has an automatic keybinding. But the syntax check task needs its own keybinding in keybinding.json: { "key": "ctrl+shift+enter ctrl+shift+enter", // Specify your desired key combination "command": "workbench.action.tasks.runTask", "args": "MQL SYNTAX CHECK", // Replace with the label of your task "when": "resourceExtname == '.mq4' || resourceExtname == '.mq5' || resourceExtname == '.mqh'" }
Quote
Report

Post Reply

Quoted from Forex.com.bd-Editorial External answer — Stack Overflow Stack Exchange Author: Juan Source score (net votes, not local likes): 4 Original post: https://stackoverflow.com/a/77816868 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. You can compile MQL5 manually from the terminal in Linux using Wine like this: wine /path/to/editor.exe /compile:path/to/file.mq5 /log:$/path/to/log.log Mine looks like this for example: wine /home/juan/.wine/PUPrime/MetaEditor64.exe /compile:/home/juan/.wine/PUPrime/MQL5/Experts/test.mq5 /log:/home/juan/.wine/PUPrime/MQL5/loggity.log ⚠️ Important note ⚠️ : MQL will not compile if you have any spaces anywhere in the file path. Because the Program Files directory in Wine and my MetaTrader directory, PU Prime MT5 Terminal , both have spaces I ran this command to create a symlink and have a directory path without spaces: ln -s "${HOME}/.wine/drive_c/Program Files/PU Prime MT5 Terminal" "${HOME}/.wine/PUPrime" /home/juan/.wine/drive_c/Program Files/PU Prime MT5 Terminal becomes /home/juan/.wine/PUPrime If you actually want to see what happened when you compiled you can do something like this: echo -n '' > /home/juan/.wine/PUPrime/MQL5/loggity.log wine /home/juan/.wine/PUPrime/MetaEditor64.exe /compile:/home/juan/.wine/PUPrime/MQL5/Experts/test.mq5 /log:/home/juan/.wine/PUPrime/MQL5/loggity.log cat /home/juan/.wine/PUPrime/MQL5/loggity.log *The first line just clears the compiler log and the last line reads the log into terminal If you want to be able to do it directly from VSCode you could save above into a bash script and then use a VSCode Task to call it like this: tasks.json: { "version": "2.0.0", "tasks": [ { "label": "MQL COMPILE", "type": "shell", "command": "/home/juan/.wine/PUPrime/MQL5/compile_script.sh", "args": [ "${relativeFile}" ] } ] } compile_script.sh: #!/bin/bash # Check if a filename is provided & extract it if [ -z "$1" ]; then echo "Error: Missing filename argument." exit 1 fi filename="$1" # First Task: Clear log echo "Running MQL: clear log" echo -n '' > /home/juan/.wine/PUPrime/MQL5/loggity.log # Second Task: Compile file echo "Running MQL: compilel" wine /home/juan/.wine/PUPrime/MetaEditor64.exe /compile:/home/juan/.wine/PUPrime/MQL5/${filename} /log:/home/juan/.wine/PUPrime/MQL5/loggity.log # Third task: Real log echo "Running MQL: read log" cat /home/juan/.wine/PUPrime/MQL5/loggity.log My Setup Here is the bash script I use instead of the one above: #!/bin/bash clear # Set filename and syntax flag arg1_filename="$1" arg2_syntax_flag="${2:-}" # Paths LogFullPath="/home/juan/.wine/MQL5/loggity.log" EditorFullPath="/home/juan/.wine/PUPrime/MetaEditor64.exe" CompileFullPath="/home/juan/.wine/PUPrime/MQL5/${arg1_filename}" # Clear log > "$LogFullPath" # Compile or check syntax wine "$EditorFullPath" "/compile:$CompileFullPath" "/log:$LogFullPath" "$arg2_syntax_flag" > /dev/null 2>&1 # Read log printf " ⌛ %s: %s\n" "$([ -n "$arg2_syntax_flag" ] && echo "Checking Syntax" || echo "Compiling")" "$arg1_filename" Log=$(iconv -f UTF-16LE -t UTF-8 "$LogFullPath" | tac) # Convert to UTF-8, reverse order while IFS= read -r line; do # Read log line by line if [[ "$line" =~ 0\ errors,\ 0\ warning ]]; then printf "\e[38:5:114m ✅ 0 Errors, 0 Warnings!\e[0m\n" # Green Line: no errors, no warnings exit 0 elif [[ "$line" =~ :\ error|:\ warning ]]; then num=$(echo "$line" | sed -n 's/.*(\([0-9]\+\),.*/\1/p') # Extract error/warning line number msg=$(echo "$line" | sed -n 's/.*[0-9]\+:\ \(.*\)$/\1/p') # Extract error/warning message loc=$(echo "$line" | sed -n 's/.*[\\\/]\(.*\)([0-9]*,[0-9]*).*$/\1/p') # Extract error/warning location if [[ "$line" == *": error"* ]]; then printf "\e[0;38;5;196m❌ %s\t%s %s\e[0m\n" "$num" "$loc" "$msg" # Red Line: error else printf "\e[0;38;5;220m🖐️ %s\t%s %s\e[0m\n" "$num" "$loc" "$msg" #Yellow Line: warning fi fi done <<< "$Log" exit 0 *Note that this hides a lot of information, just tells you if your file compiles correctly and if not shows only the errors and warnings. Formatted for easier readability and also accepts the syntax check flag Syntax check only The MetaTrader compiler lets you also just check the syntax of your file instead of a doing a full compile by adding a /s flag to the command. This is nice because it's much faster than a full compile, especially if you project has a lot of includes in it. The compile code can take /s flag as argument as well to run the syntax check. tasks.json Here we have a separate task just for the syntax check: { "version": "2.0.0", "tasks": [ { "label": "MQL COMPILE", "type": "shell", "command": "${workspaceFolder}/compile_script.sh", "args": [ "${relativeFile}" ], "presentation": { "showReuseMessage": false, "panel": "dedicated", "clear": true }, "problemMatcher": [], "group": { "kind": "build", "isDefault": true } }, { "label": "MQL SYNTAX CHECK", "type": "shell", "command": "${workspaceFolder}/compile_script.sh", "args": [ "${relativeFile}", "/s" ], "presentation": { "showReuseMessage": false, "panel": "dedicated", "clear": true }, "problemMatcher": [] } ] } Keybinding The compile task is set as the default build task so it has an automatic keybinding. But the syntax check task needs its own keybinding in keybinding.json: { "key": "ctrl+shift+enter ctrl+shift+enter", // Specify your desired key combination "command": "workbench.action.tasks.runTask", "args": "MQL SYNTAX CHECK", // Replace with the label of your task "when": "resourceExtname == '.mq4' || resourceExtname == '.mq5' || resourceExtname == '.mqh'" }

Cancel quote

Checking account access…