Applying a Patch to a library using MinGW? - c++

There's a similarenter link description here It's on the below link.
I have been given a patch on an email and I need to create a patch file. I have just pasted the contents into a text file and saved it as 'All Files' as file.patch. As far as I can tell this is correct.
This patch will apply to multiple files in a library.
I'm not sure how to apply the patch. I'm guessing that this is done using MinGW but I'm not sure how. I have set the above directory to the library in the command line like this..
cd c:\library
I place the patch file in this libraries base director and write the name of the patch.
file.patch
When I do this (I have tortoise svn installed on my pc) a the patch file opens up with a bunch of colors (Red/Yellor/Green) highlighting some of the text in the file.
Does this mean the patch automatically applies or am I going about this completely the wrong way?
I can't put the patch on the internet but the explanation above is clear.
If I have it all wrong would someone mind explaining how I apply a patch using MinGW on Windows? Thanks

Related

Using connector c++ to access MYSQL database (How to add a path to my standard search directory)

I am relatively new to programming&C++ and just began learning about MYSQL. I have been searching for a couple of days but couldn't find a solution. I usually use Cygwin&VIM&g++ to write, compile and run codes that I write.
My goal is to retrieve data from MYSQL database that I've set up on my laptop and be able to run a simple algorithm on that data and possibly update the database.
I went into MYSQL's website and went through tutorials and found an example here. I have Boost, Connector, MYSQL server lib downloaded. When I run it, I get an error saying 'connection.h' was not found. I'm sure this is because when I compile it, g++ does not have the location of the library added to the search path that it goes through. The example has something like:
#include <cppconn/conneciton.h>
where these angled brackets means it is going to search (after the current directory) the standard search directory. I am guessing I have to add a new path (the location of where the libraries are) so that the compiler looks at that standard directory and compiles the header.
Through googling I am thinking in g++ I can use -Ldir -I to add a new search path but I don't get how to use it. Can anyone kindly explain/show me (by example) how to get over with this problem? :(
An #include issue would be solved with -I (-L is for a library if it is needed but first you have to get through the compile).
You need to figure out where the headers were installed (likely somewhere under either /usr/include or /usr/local/include/), and then add a -I with that directory, it may also be that you need to install a development package, many *nix distributions split based on runtime-build time distinctions.
And note also with the -I that the package may do something like install to /usr/include/libraryname/libname_version/libname in such a case you would only want to add -I/usr/include/libraryname/libname_version/ and then in your source file have #include

Get .stl format 3D mesh from Binary Mask (Segmentation)

I am currently able to get mesh files of these formats however I would like to save the mesh file as .stl. I found documentation about this STL MeshIO Class, however, I can't seem to find the header to "include".
Additionally, if I follow from this, it still asks me to enter proper file extension, as in it doesn't work when I give .stl extension.
Any help or work around?
P.S. ITK-4.11.0, VS 13 Update 5, CMake - 3.8.0.
Let me know if you need the code, I don't see a requirement here.
Just adding the procedure here for someone who might be interested.
Get git executable.
In CMake go to advanced and add the path to the git executable
In Modules, add Module_IOSTL
Configure and Generate.
Build the ITK.sln file. (If using VS)
Configure and Generate your project.
Add #include "itkSTLMeshIOFactory.h"
Add itk::STLMeshIOFactory::RegisterOneFactory(); before you initialize the MeshType.
Give file extension for MeshFileWriter as .stl, and voila!
IOSTL is a remote module. When configuring ITK with CMake, you need to enable Module_IOSTL in group Module. Rebuild ITK, rebuild your program, and now you should be able to read and write .stl just the same as .vtk, .off etc. Hopefully, without any code changes.

Need help applying MinGW patches for std string, getting unexpected ends

I'm trying to apply these patches:
http://tehsausage.com/mingw-to-string
So that I can use std string stuff that I should have access to anyways.
I have MinGW 4.7.2, and at first, I tried copying the zip files with no luck.
Now I'm trying to manually apply the patches. I copied the patch information into a file.patch, placed it in the same folder as the file I am patching, and ran
patch < file.patch
and then I get:
patching file stdio.h
patch unexpectedly ends in middle of line
Hunk #1 FAILED at 574.
patch unexpectedly ends in middle of line
1 out of 1 hunk FAILED -- saving rejects to file stdio.h.rej
patch unexpectedly ends in middle of line
I made sure that there is no extra white space at the end..
Please help!
OK, installed the latest mingw from the web-site, downloaded the patch files and made sure they were clean.
I applied each one individually, and they worked without issue. There was a warning that it was 'Stripping the trailing CRs from the file', but it worked without issue.
each patch is applied in the appropriate directory; e.g. the stdio.patch is applied to stdio.h which is in /mingw/include using:
patch </path/to/stdio.patch
ditto for wchar.patch
The os_defines.h file is found at /mingw/lib/gcc/mingw32/4.7.2/include/c++/mingw32/bits, and the patch works properly for that one as well.
I created a github with the patches at https://github.com/petesh/mingwpatches.git - you can clone the repository, or download the individual files from there. Each of them should work correctly without more than a complaint about the trailing CR warning.
After looking at the patch files, you probably need to use the -c option to the patch command. This tells patch that the patch-files are from a context diff.
E.g.
$ patch -c < file.patch

Vim YouCompleteMe configuration

i just installed YouCompleteMe for Vim through vundle. It works, but it shows only the words contained in the current file. I want to use it to develop c++ programs, how can i configure it to show autocompletion from c++ headers file in /usr/include for example? Thanks a lot.
You need to navigate to ~/.vim/bundles/YouCompleteMe and run the installation script with --clang-completer, so do ./install.sh --clang-completer. After it finishes you should have support for C like languages.
You may also need to place let g:ycm_global_ycm_extra_conf = '~/.vim/bundle/YouCompleteMe/cpp/ycm/.ycm_extra_conf.py' in your ~/.vimrc.
I have installed with pathogen. I tried the above instructions with ./install.sh --clang-complete. After this, it did not work, and I indeed had to add the path. But it was different than in another reply here, namely
let g:ycm_global_ycm_extra_conf = '.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py'
so there is an extra "third_party/ycmd" in the path.
While the suggestions here might work in the beginning, I am not sure it's the proper way to go. According to YCM developer, whenever you start a project, you need a new .ycm_extra_conf.py file
From https://valloric.github.io/YouCompleteMe/#ubuntu-linux-x64-super-quick-installation
YCM looks for a .ycm_extra_conf.py file in the directory of the opened file or in any directory above it in the hierarchy (recursively); when the file is found, it is loaded (only once!) as a Python module. YCM calls a FlagsForFile method in that module which should provide it with the information necessary to compile the current file. You can also provide a path to a global .ycm_extra_conf.py file, which will be used as a fallback. To prevent the execution of malicious code from a file you didn't write YCM will ask you once per .ycm_extra_conf.py if it is safe to load. This can be disabled and you can white-/blacklist files. See the Options section for more details.
While you might only need to modify the compile flags from the vanilla .ycm_extra_conf.py, I feel it is advisable to create a new file for every project you start.
Everything that the folks here have said is correct. I just want to add that as of 2017, the "install.sh" script is deprecated. Now, you have to use the install.py script instead by typing
./install.py --clang-completer
Also, in your .vimrc file, instead of ".vim/bundle/blahblahblah", you'll need to add a "~/" in front of the address by adding:
let g:ycm_global_ycm_extra_conf = "~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py"
to your .vimrc file, to give it an absolute path from the Home directory so that Vim can find the ".ycm_extra_conf.py" file. Otherwise, you might experience some funny behavior.
I just wanted to add if you don't want to manually define a config file there is this neat little repository that will auto generate it. https://github.com/rdnetto/YCM-Generator

How can I make LLVM display graphs in a different viewer?

LLVM can create graphs in Graphviz's "dot" format, and automatically invoke a viewer to display them. By default it uses dotty to display those graphs. I know that I can change it to use a different viewer, but I was not able to find precise instructions on how to do so.
How can I make it open the graphs with a different viewer?
I'm running on Linux but would be interested in an answer for Windows as well.
I found out I'm supposed to change the CMakeCache.txt file in my build folder. For instance, to use XDot instead of dotty, I edited the LLVM_PATH_XDOT_P property in that file to point to the full path of my xdot.py file.
It now opens the alternative viewer successfully, after rebuilding the project.
I just needed to do this.
I managed to do this with a workaround: made a backup of dotty (just in case) and created a link from dotty to XDot.
cp /usr/bin/dotty /usr/bin/dotty_copy
ln -s /usr/bin/dotty /usr/bin/xdot
I believe you could also set some variable during configuration step (possibly LLVM_PATH_DOTTY), but I never tried this as I didn't want to recompile LLVM.
You may try hacking the DisplayGraph function or fidging with the makefiles until you manage to enable one of the #ifdefs in DisplayGraph.