I've trying to compile a simple gtkmm program with Sublime Text, but the default C++ build system does not work as it doesn't point to the gtkmm library folder:
fatal error: gtkmm.h: No such file or directory
However, after customizing C++.sublime-build and changing the "cmd" line to:
"cmd": ["g++", "$file", "-o", "$file_base_name `pkg-config gtkmm-3.0 --cflags --libs`"],
I get the error:
g++: error: `pkg-config gtkmm-3.0 --cflags --libs`: No such file or directory
Apparently ST2 is not running the pkg-config command prior to g++, which the back quotes usually do in the command shell. How do I force ST2 to do just that, in order to correctly include gtkmm folder?
I found the "sublime-build" code some days ago on the stackoverflow, but I can't find it again, so I am attaching the .sublime-build file that works for me.
{
"cmd": ["g++ -o ${file_base_name} ${file} `pkg-config --libs --cflags gtk+-3.0` && ./${file_base_name}"],
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${file_path}",
"shell":true
}
Related
So I have following problem, I installed MinGW and it works I can manually compile my program using this g++ filename in cmd, and it crates exe file which I can run in cmd and see result. But when I try to use sublime text 3 and run it from there there is following error "[WinError 2] The specified file could not be found".
This is build system which I found and tried to use:
{
"shell_cmd": "g++ -Wall -Wextra -O2 -fwrapv -Wfloat-equal -Wconversion -std=c++17 \"${file}\" -o \"${file_path}/${file_base_name}\"",
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${file_path}",
"selector": "source.c++",
"variants":
[
{
"name": "Run",
"shell_cmd": "g++ -Wall -Wextra -O2 -fwrapv -Wfloat-equal -Wconversion -std=c++17 \"${file}\" -o \"${file_path}/${file_base_name}\" && \"${file_path}/${file_base_name}\""
}
]
}
Which I found here Sublime Text C++ Build System
Im not sure if I describe my problem correctly so if you have more question feel free to ask.
Thanks :)
I have just switched from Python to C++ for implementing Data Structures and Algorithms. I found that Sublime Text 3 was quiet powerful. I installed it, added my Mingw-64 compiler to the path and also added a "build system". I hoped it would be suffice to build and run any basic C++ program. But when I run
#include <iostream>
using namespace std;
int main() {
int n;
cin>>n;
cout<<n<<endl;
return 0;
}
I know, there is some problem either in the build part or the compiler settings. I tried different compilers, from code blocks to independent Mingw-64 compiler without any success. In the past, I have used Code Blocks, it never required me to create an exe file or reference it. If I restart the program, it will show permission denied error which I know why it occurs.
Here is the error:
The system cannot find the file G:\Programming\C++\second.exe.
[Finished in 15.0s with exit code 1]
[shell_cmd: g++ "G:\Programming\C++\second.cpp" -o
"G:\Programming\C++/second" && "G:\Programming\C++/second"] [dir:
G:\Programming\C++] [path: C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\ProgramData\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program
Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Program
Files\Intel\WiFi\bin\;C:\Program Files\Common
Files\Intel\WirelessCommon\;C:\Program Files (x86)\Windows
Live\Shared;C:\Program Files\MATLAB\MATLAB Production
Server\R2015a\runtime\win64;C:\Program Files\MATLAB\MATLAB Production
Server\R2015a\bin;C:\Program Files\MATLAB\MATLAB Production
Server\R2015a\polyspace\bin;C:\Python27\;C:\Python27\Lib\site-packages\PyQt4;C:\Program
Files\Git\cmd;C:\Program Files
(x86)\mingw-w64\i686-7.1.0-posix-dwarf-rt_v5-rev0\mingw32\bin;C:\Users\80LM0141IH\Anaconda3;C:\Users\80LM0141IH\Anaconda3\Library\mingw-w64\bin;C:\Users\80LM0141IH\Anaconda3\Library\usr\bin;C:\Users\80LM0141IH\Anaconda3\Library\bin;C:\Users\80LM0141IH\Anaconda3\Scripts;C:\Users\80LM0141IH\AppData\Local\Programs\Python\Python36\Scripts\;C:\Users\80LM0141IH\AppData\Local\Programs\Python\Python36\;C:\Users\80LM0141IH\AppData\Local\Microsoft\WindowsApps;G:\Microsoft
VS
Code\bin;C:\Users\80LM0141IH\AppData\Local\GitHubDesktop\bin;C:\Users\80LM0141IH\AppData\Local\Microsoft\WindowsApps;";C:\Program
Files (x86)\Graphviz2.38\bin";C:\Program Files
(x86)\Graphviz2.34\bin;]
Before we start, you need to make sure that you have installed a C++ compiler and configured its path correctly. Make sure that you can invoke g++ command in the command line.
I see from your code that you need input from the standard input. Sublime Text's console can not accept input. So that maybe that is the problem. You need to run this program in a terminal
Try to replace your build system with following settings:
{
"shell_cmd": "g++ -std=c++11 -Wall \"${file}\" -o \"${file_path}/${file_base_name}\" && \"${file_path}/${file_base_name}\"",
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${file_path}",
"selector": "source.c++, source.cpp, source.cc, source.cxx",
"variants":
[
{
"name": "Run in Terminal",
"linux": {
"shell_cmd": "g++ -std=c++11 -Wall \"${file}\" -o \"${file_path}/${file_base_name}\" && xterm -e '${file_path}/${file_base_name} && echo && echo Press ENTER to continue && read line && exit'",
// "shell_cmd": "g++ -std=c++11 -Wall \"${file}\" -o \"${file_path}/${file_base_name}\" && gnome-terminal -e 'bash -c \"${file_path}/${file_base_name}&& echo && echo Press ENTER to continue && read line && exit\"'", // for gnome-terminal
// "shell_cmd": "g++ -std=c++11 -Wall \"${file}\" -o \"${file_path}/${file_base_name}\" && xterm -e '${file_path}/${file_base_name}; bash'", // for xterm
// "shell_cmd": "g++ -std=c++11 -Wall \"${file}\" -o \"${file_path}/${file_base_name}\" && xterm -hold -e ${file_path}/${file_base_name}", // for xterm
// "shell_cmd": "g++ -std=c++11 -Wall \"${file}\" -o \"${file_path}/${file_base_name}\" && konsole --hold -e ${file_path}/./${file_base_name}", // for konsole
},
"windows":{
"shell_cmd": "g++ -std=c++11 -Wall \"${file}\" -o \"${file_path}/${file_base_name}\" && start cmd /k $file_base_name "
// "shell_cmd": "g++ -std=c++11 -Wall \"${file}\" -o \"${file_path}/${file_base_name}\" && start \"$file_base_name\" call $file_base_name"
},
"osx":{
"shell_cmd": "g++ -std=c++11 -Wall \"${file}\" -o \"${file_path}/${file_base_name}\" && xterm -e '${file_path}/${file_base_name} && echo && echo Press ENTER to continue && read line && exit'",
},
"shell": true,
},
]
}
Press Ctrl + Shift + B and choose C++ - Run in Terminal. It will compile and run the program in your cmd.
I can run your code snippet correctly in my environment. Let me know if you encounter any problem.
I can compile the sample continuous.c file by this command inside Ubuntu terminal:
gcc -o continuous continuous.c -DMODELDIR=\"`pkg-config --variable=modeldir pocketsphinx`\" `pkg-config --cflags --libs pocketsphinx sphinxbase`
But if I want to build it inside codeblocks how should I do it?
I'm trying to compile C++ with G++ in 64 bit.
I'm using sublime text 3. This is my build system file :
{
"cmd": ["g++ ", "-m64", "-std=c++0x", "$file", "-o", "${file_path}/${file_base_name}"],
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${file_path}",
"selector": "source.c, source.c++, source.cxx, source.cpp",
"variants":
[
{
"name": "Run",
"cmd": ["bash", "-c", "g++ -m64 -std=c++0x '${file}' -o '${file_path}/${file_base_name}.exe' && xterm -e bash -c '\"${file_path}/${file_base_name}.exe\" ; read'"]
}
]
}
Compiled files are still created as 32 bit.
When I run g++ --print-multi-lib I get:
32;#m32
x32;#mx32
I'm sure this has something to do with it, but I'm not sure how to fix it, (Pretty new to this), I've tried installing multilib 64 but nothing has changed.
Any help appreciated. Thank you :)
Your sublime text 3 IDE is confusing and spoiling you and you misconfigured it.
I hope that you are using some POSIX operating system, e.g. Linux.
Learn first to compile on the command line (in some terminal, outside of your editor or IDE). You absolutely need to understand how to invoke the GCC compiler (with commands in a terminal). Here are a few hints.
Be sure to have a recent GCC compiler, at least GCC 6 if you want C++11 or better. Perhaps you need to upgrade your compiler.
compiling a simple single-source program
To compile a single-source C++ program in single.cc into tinyprog executable, use
g++ -std=c++11 -Wall -g single.cc -o tinyprog
FYI, -std=c++11 sets your C++ standard, -Wall ask for almost all warnings (and you might even add -Wextra to get more of them), -g is for debug information (in DWARF) and -o tinyprog sets the output executable. Do ls -l tinyprog, ldd tinyprog, file tinyprog to understand more about your executable.
compiling a simple multi-source program
To compile a small multi-source C++ program, e.g. made of first.cc and second.cc into a smallprog executable
compile each of these into object files
g++ -std=c++11 -Wall -g -c first.cc -o first.o
g++ -std=c++11 -Wall -g -c second.cc -o second.o
link these object files into your executable
g++ -std=c++11 -Wall -g first.o second.o -o smallprog
building more complex programs
If you are using extra libraries, you may need to add some extra -I includedir option at compile time, and some extra -L libdir and -l libname options at link time. You might want to use pkg-config to help you. You could, if curious, add -v after g++ to be shown the actual steps done by g++
I run g++ --print-multi-lib
This just queries how your g++ compiler has been configured. You could also try g++ -v alone.
Once you are able to compile by (one or several) commands, consider using some build automation tool. To build a single program using GNU make, you could take inspiration from this.
Once you are fluent with compiling thru commands (either directly or thru some build automation tool like make or ninja or thru your script), read the documentation of your editor or IDE to configure it suitably.
How can I configure the tasks.json file so that when I press Ctrl + Shift + B the copier will use pkg-config gtkmm-3.0 --cflags --libs.
My file looks like this:
"version": "0.1.0",
"command": "g++ `pkg-config gtkmm-3.0 --cflags --libs`",
"isShellCommand": true,
"args": ["main.cpp"]
But it returns this message:
Failed to launch external program g++ pkg-config gtkmm-3.0 --cflags --libs main.cpp. spawn g++ pkg-config gtkmm-3.0 --cflags --libs ENOENT
If I put it as an argument, like this:
"version": "0.1.0",
"command": "g++",
"isShellCommand": true,
"args": ["main.cpp", "pkg-config gtkmm-3.0 --cflags --libs`"]
Returns this message:
g++: error: pkg-config gtkmm-3.0 --cflags --libs`:
File or directory not found
you can try this!
"version": "0.1.0"
"command": "g++",
"isShellCommand": true,
"args": [
"main.cpp",
"`pkg-config", "--libs", "--cflags", "gtkmm-3.0`",
]
you should control how the argument is quoted.
more information: Task in Visual Studio Code