How do you use Clang-format on Emacs, Ubuntu? - c++

I'm new to Ubuntu and Linux, so I'm sorry if this question seems to be too stupid. I hoped to have a function that can automatically format my C++ codes, so I installed clang-format by the following terminal command:
sudo aptitude install clang-format
To make it work with Emacs, I searched on the Internet for a solution and modified my "~/.emacs" file, adding the following line:
(setq clang-format-executable "/usr/bin/clang-format-6.0")
Now in Emacs, when I used the command M-x clang-format-buffer or similar commands on a C++ file, it succeeded, but the source code didn't seem to be formatted at all (sorry that I can't directly post images for some reason):
https://i.stack.imgur.com/gNIvn.png
https://i.stack.imgur.com/eKLXl.png
Is there anything else I'm missing in setting up clang-format, or what's the proper way to set it up?
I appreciate any help!

I got it.
First, installing Clang-format this way was unnecessary. The proper way to do it was by using Emacs' package-install command.
package-install clang-format
Then I did this in the .emacs file:
(load "/usr/share/emacs/site-lisp/clang-format-6.0/clang-format.el")
Hope this helps anyone facing the same problem.

Related

svm-scale: command not found

I am running a cpp code in xcode along with opencv. Inside the cpp code, there is a command line:
system("svm-scale -r allrange test_ind>> test_ind_scaled")
When i run the code, it's give a error like svm-scale: command not found
But when i run this command line (svm-scale -r allrange test_ind>> test_ind_scaled) from terminal, it's giving no error.
Any suggestion how to run this command line from inside the cpp code ?
Any suggestions would be greatly appreciated.
Try running svm-scale with its full path. Reading other xcode-related questions hinted that xcode might not use your PATH variable, so system doesn't know where to look for the specific command.

gdb tui, dl-debug.c:74 no such file or directory

If I start gdb -tui or gdbtui with an -g flag compiled file, then set b main and press r I get the hint dl-debug.c:74 no such file or directory and the output while stepping through the source window will be written to the source window at the bottom, which also messes up this window so that is not really readable. I've already looked at askubuntu.com and Sourceware Bugzilla – Bug List and at this site but found no solution.
I also tried out sudo apt-get install ddd on another machine to go to the trouble out of the way, but then I only get authentication failure, which I also already asked without response on ask ubuntu.
Any help or hint is appreciated.
dl-debug.c:74 no such file or directory
This message means that you've tried to step into GLIBC (more precisely the dynamic loader) source, which you didn't install.
Solution: don't try to step into it, or install GLIBC source and make GDB find it (help directory).

How to permanently override HOMEBREW_CC and HOMEBREW_CXX settings?

Since I installed gcc-49 on my Mac I can't get Homebrew to find the C++ compiler anymore. It always fails with error messages like:
configure: error: C++ preprocessor "/lib/cpp" fails sanity check
Running "brew upgrade -v" spits out this:
...
==> ENV
HOMEBREW_CC: llvm-gcc
HOMEBREW_CXX: llvm-g++
...
I have no idea why Homebrew wants to use these compilers. Why can't it use the normal CC/CXX environment variables like everything else?
I already found, that by editing the formula directly like described in Using Homebrew with alternate GCC, I can change the HOMEBREW_CXX to use /usr/local/bin/g++ for example, which makes compiling formulas that need C++ work again.
But I don't want to edit every single formula by hand for the rest of my days. How can I change this HOMEBREW_CXX environment variable permanently? I tried setting them in my .bash_profile and running "export HOMEBREW_CXX=..." in the console and neither of those work, only editing the formula directly.
Does anyone have an idea?
A poor man's solution, to be sure, but this works: put an alias in your .bashrc or .bash_profile:
alias brew='HOMEBREW_CC=gcc-4.8 HOMEBREW_CXX=g++-4.8 brew'
Now, whenever you use brew it will use the compilers you want. Check that it works by doing:
brew --env
HOMEBREW_CC: gcc-4.8
HOMEBREW_CXX: g++-4.8
...
HTH

Astyle is adding new lines to the end of the file everytime

I just installed vim-autoformat and astyle to format my c/c++ code inside vim. Everything seems to work, but it puts a newline to the end of the file everytime I run it. Even if there is one (or multiple). I tried to find the option in astyle -h and search the web, but didn't find anything. What do I do?
It looks like it's a bug in astyle that's been fixed. See http://astyle.sourceforge.net/subversion.html for help getting the latest development version. I'm using version 2.05 beta and it seems to be working correctly now.

xtk-deps.js file missing?

I am ref to https://github.com/xtk/X/wiki/X:DevelopersHeadsUp
I tried Running XTK during development.
I did the following steps
1) Fork XTK on Github to get the latest sources http://github.com/XTK/X
2) Clone it to your hard drive
But i couldn't find the xtk-deps.js file in the folder.
When i try
./build.py -d
Its complaining that "The command line is too long" and not generating xtk-deps.js file. Can some one help me where i went wrong ?
Yep, the error comes from the python script builds via a shell command line which is too long for the Windows prompt. The best is using Linux or Mac, or we can give you one and then you'll have to edit it manualy when you add/remove classes but it's not the easiest !