Cannot open shared GCC library - c++

This question should be simple for those familiar with GCC. I'm hoping to be soon.
/usr/lib/gcc/i686-pc-cygwin/4.5.3/cc1plus.exe: error while loading shared libraries: ?: cannot open shared object file: No such file or directory
I'm launching this GCC doohickey from Sublime Text 2, directly calling g++-4.exe instead of the g++.exe (which wasn't recognised as a program).
Apparently the recommended fix is to add the folder that contains whatever library is missing to the LD_LIBRARY_PATH variable using export LD_LIBRARY_PATH=somefolder. However, no library is being specified, just a '?' in its place.
I'm following instructions to install clang, and I'm using Windows 7 Pro, 64-bit. The code being compiled is a single C++ file.
Cheers...

Hah, I met the same problem when I am trying to use the g++ of my cygwin as a compiler in sublime. Eventually I found this simple solution: Insert the following line to C++.sublime-build.
"path": "D:/Tools/Cygwin/bin/",
After this edition, my C++.sublime-build has the following content:
{
"cmd": ["g++","${file}", "-o", "${file_path}/${file_base_name}"],
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${file_path}",
"selector": "source.c, source.c++, source.cpp",
"path": "D:/Tools/Cygwin/bin/",
"variants":
[
{
"name": "Run",
"cmd": ["bash", "-c", "g++ '${file}' -o '${file_path}/${file_base_name}' && '${file_path}/${file_base_name}'"]
}
]
}
At least this works for me!
How to find C++.sublime-build?
Preferences > Browse Packages > C++ > C++.sublime-build

Cygwin applications are built in a shell that renders the Windows files system as a virtual Unix style file system. In Windows the "C:\" drive maps to /cygdrive/c in cygwin. I'm not aware of any way to emulate this mapping within a Windows command shell, or any Windows application.
All of the paths embedded in gcc and g++ have references to the path in the virtual file system. For simple apps with no external dependencies this isn't a problem. But for g++ and others they must be run from a Cygwin shell. It might be possible to run 'bash -c g++ ...' from a Windows command, but I don't have access to a setup to try it.

Related

Sublime Text 3 intel oneAPI Fortran build system

Has anyone figured out how to write the build system for the oneAPI Fortran compiler?
Previously, i was using Parallel Studio XE ifort, and i managed to get it working using the solution here:
{
"cmd": ["cmd", "/e:on", "/v:on", "/k", "ipsxe-comp-vars intel64 vs2013 && ifort ${file}"],
"file_regex": "^.*\\\\([0-9A-Za-z_]+\\.[A-Za-z0-9]+)\\(([0-9]+)\\):[ ]+error[ ]+#([0-9]+):[ ]+(.*)$",
"working_dir":"${file_path}",
"selector":"source.f ,source.for ,source.ftn ,source.f90 ,source.fpp ,source.i ,source.i90",
"encoding":"cp936",
"path":"C:\\Program Files (x86)\\IntelSWTools\\compilers_and_libraries_2017.4.210\\windows\\bin;${path}",
"variants":
[
{
"name": "Run",
"cmd": ["cmd", "/e:on", "/v:on", "/c", "ipsxe-comp-vars intel64 vs2013 && ifort ${file} && ${file_base_name}"]
}
]
}
I tried changing the paths to the new ones but it doesn't work. I get the following error:
"ipsxe-comp-vars" is not recognized as an internal or external command,
program o executable.
I found the answer. Explanation below. Posting the working build system here for visibility.
This should be the build system:
{
"cmd": ["cmd", "/e:on", "/v:on", "/S", "/k", "C:\\\"Program Files (x86)\"\\Intel\\oneAPI\\setvars.bat intel64 vs2022 && ifort ${file}"],
"file_regex": "^.*\\\\([0-9A-Za-z_]+\\.[A-Za-z0-9]+)\\(([0-9]+)\\):[ ]+error[ ]+#([0-9]+):[ ]+(.*)$",
"working_dir":"${file_path}",
"selector":"source.f ,source.for ,source.ftn ,source.f90 ,source.fpp ,source.i ,source.i90",
"encoding":"cp936",
"path":"C:\\Program Files (x86)\\Intel\\oneAPI\\compiler\\latest\\windows\\bin\\intel64;${path}",
"variants":
[
{
"name": "Run",
"cmd": ["cmd", "/e:on", "/v:on", "/s", "/c", "C:\\\"Program Files (x86)\"\\Intel\\oneAPI\\setvars.bat intel64 vs2022 && ifort ${file} && ${file_base_name}"]
}
]
}
Why the problem happens
For starters, ipsxe-comp-vars is a batch file which when run, sets up environment variables required to execute the intel compilers. This file is specific to Intel Parallel Studio XE (IPSXE). Now, when installing IPSXE, it would add this batch file to your PATH, meaning you could simply call ipsxe-comp-vars from any directory to set up the required environment variables.
Intel oneAPI has a differently named file, that essentially does the same thing, called setvars.bat. This file is stored in:
C:\Program Files (x86)\Intel\oneAPI\setvars.bat
So, at first it seems that calling ipsxe-comp-vars fails because the file is named differently. However, unlike IPSXE did with ipsxe-comp-vars, oneAPI does not add setvars to PATH, so you cannot simply call setvars, you have to usethe full path.
How to solve it
With IPSXE, you could call ipsxe-comp-vars and it would run the batch file that sets up environment variables, but with oneAPI either you add the file to PATH (not reccomended because it has a generic name), or you use the full path when calling it (same as above):
C:\Program Files (x86)\Intel\oneAPI\setvars.bat
Now, because you have to plug this in into the build system config, you need to format it correctly. ST runs the commands in a cmd.exe, so you have to use the correct options and format the path in a way that cmd can understand it:
options (you can get a full list by opening a cmd prompt, typing cmd /? and hitting return):
- /e:on Enables command extensions
- /v:on Enables extension of environment variables
- /s Modifies how the string following a /c or /k is read
- /k Executes the string command and continues
The path to the setvars.bat file must be formatted as follows:
C:\\\"Program Files (x86)\"\\Intel\\oneAPI\\setvars.bat
Each \ separating dirs needs to be escaped (using \ as well)
needs to be enclosed in double quotes, since it contains a whitespace. Each double quote needs to escaped as well (once again with )
The following options are specific to the setvars.bat file:
- intel64 specifies 64-bit configuration
- vs2022 specifies Visual Studio 2022 as the developer cmd or
powershell version to use
Finally, ifort is called on the current file with ifort ${file}
Additionally, the build system is completed with a variant "Run". This variant runs the output file once it has been compiled(&& ${file_base_name}), and will show the output in the Sublime Text 3 console (does not accept inputs, if anyone knows how to setup up sublimeREPL for Fortran please tell me)

Sublime Text 3 Build System for Ubuntu

I'm running an Ubuntu 16.04 machine. I want to compile and run C++ programs in Sublime Text 3. A few months ago I came across a build system that compiled and ran the program in terminal in a single command. Due to some reasons I no longer have the build system.
This is what I have in place:
{
"cmd": ["g++", "$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",
"shell": true,
"cmd": ["gnome-terminal -e 'bash -c \"${file_path}/${file_base_name};echo;echo; echo Press enter to continue....; read line;exit; exec bash\"'"]
}
]
}
It works fine but I have to compile and run the program separately. Is it possible to modify this to achieve what I've mentioned above? Or maybe another build system that could do this?
Not sure if it's irrelevant, I tried using sublime to compile c++ but couldn't. Then tried switching to atom and have been using it since. It can compile code from the editor. You can give it a try.

How to compile and run c++ programs with sublime text 3?

I want to compile and run a c++ program in cmd every time I hit CTRL+B in Sublime Text 3. Also I need to keep the window alive after the program is fully executed. I particularly love the build system which code-block uses. Can I implement the same system in Sublime?
So far, I have following build system:
{
"cmd": ["mingw32-g++", "-o", "$file_base_name", "$file"],
"path": "C:\\MinGW\\bin\\",
"variants": [
{
"cmd": ["start", "cmd", "/k", "$file_base_name"],
"shell": true,
"name": "Run"
}
]
}
The only problem here is that I have to compile first and then run it. I want to have it compiled and run in a single operation.
Edit:
I have solved this problem by the following build system:
{
"cmd": ["g++.exe", "-std=c++11", "-o", "$file_base_name", "$file", "&&", "start", "cmd", "/c", "$file_base_name & echo. & echo. & pause"],
"shell": true,
"selector": "source.c++"
}
Sublime Text is a text editor wherein you can use different languages under the same hood.
Regarding your c++ program you have to install some packages for the version of c++ you are using. I recommend to watch some tutorials to get a step by step procedure and better understanding.
{
"shell_cmd": "g++ -std=c++11 -Wall \"${file}\" -o \"${file_path}/${file_base_name}\" && start cmd /k \"$file_base_name\"",
"working_dir": "${file_path}",
"selector": "source.cpp, source.cxx, source.cc, source.c++"
}
go to Tools -> build system -> new build system -> Paste It -> save it as "C++", then close it.
now save your C++/C code with .cpp extention (important .c extention is not supported) then to compile it go to tools -> build with Select "C++"
file download link:https://github.com/mahirx/configurations/blob/master/sublime_text/c_and_c%2B%2Bv2/C%2B%2B.sublime-build
please notify me if you found any mistakes.
Configure your editor to run make (or ninja ...) for CTRL B and use a Makefile, a build.ninja, or some other build automation tool. So you could add the appropriate rule (to your Makefile etc....) to run something else.
(both GNU make and ninja have good documentation and tutorials, and you could ask questions about them on SO, with some MCVE)
Source code editors are tools to edit source code. Configure them to run the external programs (compilers, debuggers, your own thing, ... or make or ninja) appropriately.
The only problem here is that I have to compile first and then run it. I want to have it compiled and run in a single operation.
So build with a good enough build automation tool. Configure your editor to run make, and edit your Makefile to make "compile then run" the default target (and likewise with ninja and its build.ninja file). Remember that compilers like GCC (even started from IDEs) are command line programs (and your mingw32-g++ is a GCC compiler).
Take also the good habit to compile with all warnings and debug info, so pass -Wall -Wextra -g to your GCC that is your mingw32-g++ (hence, edit appropriately your Makefile or build.ninja file).
In other words, an IDE - that is just a buzzword - is a source code editor suitably configured to run other programs. My preference is emacs

Unexpected fail when running C++ code with Sublime Text 2 on Windows8

I just begin to use sublime text 2 on my laptop. I want to compile and run C++ code using sublime text 2.
I installed MinGW and g++, and changed the path environment to include the path where MinGW was installed.
I opened sublime text 2 and wrote a simple C++ program, named test.c, to do the test.
#include "stdio.h"
# test.c
int main()
{
printf("hello");
}
I did Ctrl+B to compile and got the message:
[Finished in 0.8s].
I used Ctrl+Shift+B to run it and got the following message.
[Error 2] The system cannot find the file specified
[cmd: [u'bash', u'-c', u"g++ 'C:\Users\me\Desktop\test.c' -o 'C:\Users\me\Desktop/test' && 'C:\Users\me\Desktop/test'"]]
[dir: C:\Users\me\Desktop]
[path: C:\Python27\Lib\site-packages\PyQt4;C:\MinGW\bin;]
[Finished]
I tried to solve this problem and did the following things.
i. Sublime Text 2 --> Tools --> Build System --> New Build System
ii. in the newly opened window in sublime, I input the following commands.
{
"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",
"cmd" : ["${file_path}/${file_base_name}"]
}
]
}
iii. I saved the file as gcc.sublime-build and went back to run test.c.
However, the test.exe was not run appropriately and Win8 showed this window, which says
test.exe has stopped working
A problem caused the program to stop working correctly.
Windows will close the program and notify you if a solution is available.
I got this message from sublime text after closing the window:
[Finished in 7.6s with exit code 255].
I don't why and how to fix it.
Why don't you simply install Visual Studio? It includes both compiler and code editor, so you don't need to waste your time on setting up buggy software like Sublime.

How to build and run c++ programs in Sublime Text 2, Windows 8?

I installed Codeblocks with mingw, chose default compiler, and could build and run a simple hello program without errors.
I installed Sublime Text 2, copy pasted the same hello world program:
// my first program in C++
#include <iostream>
using namespace std;
int main ()
{
cout << "Hello World!";
return 0;
}
Upon building, I get the error message:
[Error 2] The system cannot find the file specified
[cmd: [u'bash', u'-c', u"g++ '' -o '/' && '/'"]]
[dir: C:\Windows\system32]
[path: C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\]
[Finished]
What do I need to do in order to build and run a simple program using Sublime Text 2?
First, make sure you save the file you're working on, wherever on your drive, before building and running.
Sublime Text 2 needs g++, bash, etc in order to compile. These packages need to be installed on your computer, as per the instructions on this page:
http://mjiang.com/mec/cs244/files/Installing%20c++_g++_on_Windows.pdf
For WINDOWS:
If you have Dev C++ (Bloodshed) then,
OPEN SUBLIME TEXT 2 and creat a new file to write your code (change build system to c++ through Tools> Build System> C++ as SublimeText2 doesn't come with build-system for c)
After that, you save that file to bin folder contained in Dev-Cpp folder and press ctrl+b
If your code is correct (bug free) then you'll found a corresponding file (in .exe format) on same directory which will show you
Hello World!
REMEMBER: SUBLIME TEXT 2 is an Editor, not a COMPILER
You could use my working C++.sublime-build file for Windows:
https://gist.github.com/trietptm/4950038
just create new Build-system (TOOLS->BUILD SYSTEM->NEW BUILD SYSTEM)
{
"windows":
{
"cmd": ["g++", "$file_name","-o", "${file_base_name}.exe", "-lm", "-Wall", "&","start", "${file_base_name}.exe"]
},
"selector": "source.c++",
"shell": true,
"working_dir": "${file_path}"
}
and save it as (name_you_can_provide).sublime-build and use that build system. :)
(I assume you already have installed MingW in your computer.)
You need to go to
Preferences->Browse Packages->C++ folder->C++.sublime-build;
bring this C++.sublime build file into the sublime text editor and now paste this code :
{ "cmd": ["g++", "$file", "-o", "$file_base_name"], "selector": "source.c++", "working_dir": "$file_path", "variants": [ { "name": "Run", "cmd": ["g++", "$file", "-o", "$file_base_name", "&&", "$file_path/$file_base_name"], "shell": true } ]
}
Hope this helps you.
You must install MinGW, then add path to MinGW to PATH variable.