I want to type "g++" instead of "i686-pc-cygwin-g++" on Cygwin64 Terminal? - c++

Everytime I have to compile with Cygwin64 Terminal, I have to write
$ i686-pc-cygwin-g++ myFile.cpp
Is there a way I can tell Cygwin that whenever I type g++ I'm actually referring to i686-pc-cygwin-g++ since it says -bash: g++: command not found
when I type g++ .

If there are no at all link to g++ in one of standard directories, like /usr/bin/g++, just create it.
Soft link:
ln -s 'path/to/i686-pc-cygwin-g++' '/usr/bin/g++`
Or even hard link:
ln 'path/to/i686-pc-cygwin-g++' '/usr/bin/g++'
Those are base commands, must be available in any bash shell.
The directory /usr/bin must be in the standard search path.
If link exists or if you use several compilers and want to switch between them, you can install and use update-alternatives, like
sudo update-alternatives --install /usr/bin/g++ g++ /path/to/i686-pc-cygwin-g++ 10
where 10 is priority.
Switch between them with:
sudo update-alternatives --config g++
remove all:
sudo update-alternatives --remove-all g++

As #Amadeus mentioned, it worked :
$ alias g++=i686-pc-cygwin-g++
Made me able to type g++ instead of i686-pc-cygwin-g++

Related

Why in my Linux, when current work directory is owned by root (e.g /usr/bin), then I cannot link any library while compiling c++?

If I write this code and saved as a.cpp at ~/Desktop
#include <memory>
int main(){}
then input to bash:
cd /usr/bin
g++ -g ~/Desktop/a.cpp -o ~/Desktop/a
then the g++ will output plenty of messy code of errors.
I have found the reason is because it don't have authority to link XX.so library.
But if I add a 'sudo' , or set CWD to the path owned by user, g++ will work properly, as follows:
sudo g++ -g ~/Desktop/a.cpp -o ~/Desktop/a
or
cd ~/Desktop
g++ -g ~/Desktop/a.cpp -o ~/Desktop/a
Why do this happen? or how can I fix this?
You don't want to generate code directly in /usr/bin.
You generate your code in your user folder, maybe create a sub-directory called cppwork or something like that.
cd
mkdir cppwork
cd cppwork
g++ -g a.cpp -o a
Once you compiled in your directory, then you copy the file using install which will also take care of stripping the debug if any (i.e. the -g says to keep debug info—stripping is not mandatory).
sudo install -s a /usr/bin/a
As you can see, the place where I use sudo is with the install command.
That being said, I never use those directly. Now a day, I use cmake which means everything works automatically. But that would be a different discussion.
Thanks for every one. I have found the reason. It's because there is an executable program named 'array' in /usr/bin. And when CWD is /usr/bin, the compiler regard this 'array' as the c++ header <array>, so compiling error.
Then I need to find out why the compiler includes /usr/bin by mistake.

Install gcc from source: bash: gcc -v /usr/bin/gcc: Is a directory

I just installed gcc-8.1 from source using those steps:
wget https://ftp.gnu.org/gnu/gcc/gcc-8.1.0/gcc-8.1.0.tar.gz
tar xvf gcc-8.1.0.tar.gz
cd gcc-8.1.0
apt build-dep gcc
./contrib/download_prerequisites
cd ..
mkdir objdir
cd objdir
$PWD/../gcc-8.1.0/configure --prefix=/usr/bin/gcc-8.1 --enable-languages=c,c++,fortran,go --disable-multilib
make -j8
make install
Everything is correct?
Then I add it to update-alternatives
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8.1 60 --slave /usr/bin/g++ g++ /usr/bin/g++-8.1
There are 3 choices for the alternative gcc (providing /usr/bin/gcc).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/bin/gcc-7 60 auto mode
1 /usr/bin/gcc-5 60 manual mode
* 2 /usr/bin/gcc-7 60 manual mode
3 /usr/bin/gcc-8.1 60 manual mode
Press <enter> to keep the current choice[*], or type selection number: 3
update-alternatives: using /usr/bin/gcc-8.1 to provide /usr/bin/gcc (gcc) in manual mode
update-alternatives: warning: skip creation of /usr/bin/g++ because associated file /usr/bin/g++-8.1 (of link group gcc) doesn't exist
My issue is when I type gcc -v, it said bash: /usr/bin/gcc: Is a directory
--prefix=/usr/bin/gcc-8.1 means that everything that is part of the installation will be placed in the /usr/bin/gcc-8.1/ directory.1
This means that your actual GCC binary is probably located at /usr/bin/gcc-8.1/bin/gcc (or some similarly-named executable, maybe it is actually called gcc-8 or gcc-8.1).
When you set the GCC binary to /usr/bin/gcc-8.1 using update-alternatives, you set the symlink that is normally used to resolve which GCC binary you want to a directory - resulting in the error that you are now getting.
To fix this issue, follow these steps:
Remove the wrong entry in update-alternatives:
update-alternatives --remove gcc /usr/bin/gcc-8.1
Add the right entry.2
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8.1/bin/gcc 60 \
--slave /usr/bin/g++ g++ /usr/bin/gcc-8.1/bin/g++
1 Well, mostly, anyways. Usual prefixes include / (binaries in /bin/), /usr/ (binaries in /usr/bin/) and /usr/local/ (binaries in /usr/local/bin/)
2 I am assuming you want to keep GCC installed at that awkward location. Recompiling and re-installing with --prefix=/opt/gcc-8.1 or something similar would probably be better, just modify the path as needed
This is a double edged sword. I am on windows so don't have the linux jargon. But located my gcc problem in a very wierd way. But maybe this will help someone from hours of digging and trying this and that. But cant say i have not learned a lot in the process.
gcc 10.4 release for windows
and that at least got me to here
Read down to the soundforge link

How to create alpha_encoder.exe (webm-tools) under msys2?

I'm trying to compile alpha_encoder) (little utility of The WebM Project, under webm-tools).
I have a previous installation of msys2 (downloaded and configured by build_locally_with_various_option_prompts.bat) under c:\FFcompiler. It took its time, but I managed to compile ffmpeg, so I decided to use it (I think it will do). That's what I've done till now.
First, I cloned webm-tools under /cygdrive/c/FFcompiler/ffmpeg_local_builds/sandbox/win32/libvpx-1.4.0/third_party/. There's a Makefile so I tried to run make:
$ cd /cygdrive/c/FFcompiler/ffmpeg_local_builds/sandbox/win32/libvpx-1.4.0/third_party/
$ git clone https://chromium.googlesource.com/webm/webm-tools.git
$ cd webm-tools/alpha_encoder/
$ make
But g++ complains mkvparser.hpp doesn't exist. The command is
g++ -c -W -Wall -O3 -g -I../../libwebm alpha_encoder.cc -o alpha_encoder.o
After searching the web, it seems that webm-tools depends on libwebm, and expect finding it as a sibling folder of webm-tools. So...
$ cd ../..
$ git clone https://chromium.googlesource.com/webm/libwebm.git
$ cd libwebm
Now, what? README.libwebm tells that 'to cross compile libwebm for Windows using mingw-w64' first I must run cmake like this cmake -DCMAKE_TOOLCHAIN_FILE=path/to/libwebm/build/mingw-w64_toolchain.cmake path/to/libwebm. In my case:
cmake -DCMAKE_TOOLCHAIN_FILE=build/mingw-w64_toolchain.cmake .
And cmake cannot find i686-w64-mingw32-g++. After googling more, it seems the easiest way to fix this is to add bin of mingw-w64-i686 to PATH.
$ export PATH=/cygdrive/c/FFcompiler/ffmpeg_local_builds/sandbox/cross_compilers/mingw-w64-i686/bin:$PATH
After this, now cmake finishes successfully and creates a Makefile, but make stops with an error:
/cygdrive/c/FFcompiler/ffmpeg_local_builds/sandbox/win32/libvpx-1.4.0/third_part
y/libwebm/common/file_util.cc:44:39: error: 'tmpnam_s' was not declared in this
scope
errno_t err = tmpnam_s(tmp_file_name);
^
I've searched about the error but I'm stuck. What am I missing?

"make[2]: g++: Command not found" in Netbeans

I get the error message:
make[2]: g++: Command not found
which I know means it cannot find the C++ compiler. However, in Netbeans if I go to the configuration to choose my C++ compiler it shows the following being in /usr/bin:
g++4.6
g++4.7
g++4.8
but it doesn't have just g++.
Tried sudo aptitude install g++ but it didnt work.
If I do g++ --version I get:
The program 'g++' can be found in the following packages:
* g++
* pentium-builder
1) Verify you can run "g++" from the command line,
2) type whereis g++ to get the path,
3) Make sure you have the NetBeans C++ plugin installed
Go to Tools->Options->C++->Build Tools
4) Configure the path in NetBeans
Usually, /usr/bin/g++ is a symlink to some /usr/bin/g++-4.7 (or g++-4.8 etc...); just make it again (which is usually provided by the g++ virtual package on Debian or Ubuntu), e.g.
% sudo -s
# cd /usr/bin
# ln -sv g++-4.8 g++
Above % and # are shell prompts that you should not type.
Of course, don't forget the sudo apt-get install g++ etc...
BTW, you might put that link from $HOME/bin/g++ to /usr/bin/g++-4.8 and you don't need root permission for that.
(sometimes, these symlinks go indirectly thru /etc/alternatives etc...)
Your issue is a sysadmin issue; you should rather ask it (with a big lot more details) on askubuntu or superuser; it is off-topic on Stack Overflow.
BTW, NetBeans is not a compiler, but an editor (sometimes called IDE). You could use something better/simpler (e.g. emacs or vim) with e.g. make as a builder (to be run inside a terminal). Before using NetBeans ensure that g++ -v is working alone in some terminal

How to install CLang using precompiled binaries?

How do I install CLang on Ubuntu, using precompiled binaries of CLang that I downloaded?
Here's how I downloaded CLang: "LLVM Download Page" -> "Download LLVM 3.2" -> "Clang Binaries for Ubuntu-12.04/x86_64" ( http://llvm.org/releases/3.2/clang+llvm-3.2-x86_64-linux-ubuntu-12.04.tar.gz .)
Then, I expanded the archive into a folder on my Ubuntu 12.04 LTS 64-bit machine. The contents of the expanded folder look like this:
$ ls clang+llvm-3.2-x86_64-linux-ubuntu-12.04
bin docs include lib share
Question: What do I do next? Do I have to copy these into some folders myself, and if so, which ones exactly? Most instructions I found online are for building CLang from source, which doesn't apply here.
I am a newbie to most of these tools. I created a basic hello-world C++ program, and was able to compile and run it, using GCC and autotools. Now, I want to compile the same program with CLang.
You can follow the same step as mentioned in https://askubuntu.com/questions/89615/how-do-i-install-llvm-clang-3-0
using GNU tar:
wget <clang-binaries-tarball-url> # or `curl -O <url>`
tar xf clang*
cd clang*
sudo cp -R * /usr/local/
If your tar isn't GNU and
the archive you get is .tar.gz, you can use tar -xzf;
if you have .tar.xz archive, you can use tar -xJf;
for .tar.bz2 archive, you can use tar -xjf.
Assuming you compiled your program with g++ hello.cpp
The equivalents of gcc and g++ are clang and clang++ accordingly. They are found in the bin folder.
It doesn't matter where you place the folders of clang, what matters is you don't move them later. So place them somewhere (I prefer $HOME and I'll assume this for the next)
Then:
Prepend it to $PATH variable
export PATH=~/clang+llvm-3.2-x86_64-linux-ubuntu-12.04/bin/:$PATH
Make this permanent by adding it to ~/.bashrc
echo "export PATH=~/clang+llvm-3.2-x86_64-linux-ubuntu-12.04/bin/:\$PATH" >> ~/.bashrc
Now you can do clang++ hello.cpp
I would like to install clang in /home/s. i.e.,
/home/s
bin
lib
include
...
I did the following in Ubuntu:
wget <clang-binaries-tarball-url>
sudo tar -xf <clang+llvm-..tar.xz> --strip-components=1 -C /home/s
# Set the path environmental variable
export PATH=/home/s/bin:$PATH
# Tell ldconfig about new shared library in /home/s/lib
cd /home/s
cat > libs.conf << "END"
/home/s/lib
END
sudo mv libs.conf /etc/ld.so.conf.d/libs.conf
sudo ldconfig
To test it:
clang --version
The output is:
clang version 7.0.0 (tags/RELEASE_700/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/s/bin
Let's test C++17 Filesystem withex1.cpp
#include <iostream>
#include <filesystem>
int main() {
for(auto &file : std::filesystem::recursive_directory_iterator("./")) {
std::cout << file.path() << '\n';
}
}
Compile it
clang++ -std=c++17 -stdlib=libc++ -Wall -pedantic ex1.cpp -o ex1 -lc++fs
Run it
./ex1
The output:
"./ex1"
"./ex1.cpp"