Trying to lead the build system on Sublime to my SDL directory but won't compile
{
"cmd": ["g++", "${file}", "-o", "${file_path}/${file_base_name}", "-L/usr/include/SDL", "-lSDLmain", "-lSDL", "-lSDL_ttf", "-lSDL_image"],
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${file_path}",
"selector": "source.c, source.c++",
"variants":
[
{
"name": "Run",
"cmd": ["bash", "-c", "g++ '${file}' -o '${file_path}/${file_base_name}' && '${file_path}/${file_base_name}'"]
}
]
}
Keep getting all my calls to SDL returned undefined references. Can't seem to get the directory called correctly on the command.
It seems like you're using incorrect path for the linker. In /usr/include/ there are only header files.
So I suppose you should modify it the following way :
-L<Where libraries are placed>
E.g. in Ubuntu:
-L/usr/lib/x86_64-linux-gnu // 64 bit libraries
-L/usr/lib/i386-linux-gnu // 32 bit libraries
In order to let the compiler new header directory you should use -I flag:
-I/usr/include
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 created a C++14.sublime-build file from tools>Build System>New Build System.
The code that I placed inside is:
{
"cmd":["bash", "-c", "g++ -std=c++14 -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.c++",
"variants":
[
{
"name": "Run",
"cmd":["bash", "-c", "g++ -std=c++14 '${file}' -o '${file_path}/${file_base_name}' && '${file_path}/${file_base_name}'"]
}
]
}
But whenever I select C++14 from tools> Build System, an error occurs saying /bin/bash: g++: command not found
Note: The program compiles and works properly when I select C++ Single File in tools>Build System.
Please help!
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.
For example, I have a project with 2 .cpp files and 2 .h files and also main.cpp .
I want to make Sublime compile main.cpp when I press control-B even if the editor if focused in one of the other .cpp or .h files.
I am not too familiar with JSON so I don't know how to modify the build file.
This is the default build file. The problem with this file is that it compiles the file the editor is focused on.
{
"shell_cmd": "g++ \"${file}\" -o \"${file_path}/${file_base_name}\"",
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${file_path}",
"selector": "source.c, source.c++",
"variants":
[
{
"name": "Run",
"shell_cmd": "g++ \"${file}\" -o \"${file_path}/${file_base_name}\" && \"${file_path}/${file_base_name}\""
}
]
}
Never mind. The solution was simple.
In both lines of
"shell_cmd":
change
${file}
to the file name you want to always compile.
For example:
"shell_cmd": "g++ \"main.cpp\" -o \"${file_path}/${file_base_name}\"",
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
}