(C++) How to use OpenBlas libraries with C++? - c++

Sorry if this all seems too simple but I'm a beginner and I'm trying to use the OpenBlas libraries in my C++ IDE "CodeBlocks" on Windows. More specifically, I'm want to use the matrix-vector multiplication and solving of a tri-diagonal matrix system libraries. I've downloaded the files at the bottom of the page on the OpenBlas site. I'm not sure how I would even start, as there are little/no resources online for beginners such as myself. What libraries do I need to include in my .cpp file preamble, have I even downloaded the correct set of files, which files do I need to include in my working directory, etc?
Thanks in advance.
EDIT: I've downloaded the pre-built files as recommended and followed every step in the link below.
http://www.learncpp.com/cpp-tutorial/a3-using-libraries-with-codeblocks/
I have also included #include "cblas.h" in the preamble of my .cpp file but I am getting a undefined reference to 'cblas_XXXXX' error in my build messages. What is the reason for this?

Download the pre-built winodws library
https://sourceforge.net/projects/openblas/files/v0.2.15/OpenBLAS-v0.2.15-Win64-int32.zip/download

Related

How to convert .lib file to .a

I've spent the last 5 hours trying to link a binary file to my program, I am using eclipse + MinGW, and trying to include the FreeImage source (downloaded from internet), the thing is I am unable to include the .lib file since it doesn't work, so I am trying to convert it to .a file.
I used MSYS software in order to do it, but nothing is working, the errors go, but the the program just fails/crashes.
Is there a way to convert .lib files to .a files so I can include them to my program.
Please help me, I really need this, and I've looked so hard to find some solutions, nothing worked, someone please direct me.
Thanks in advance <3
See this answer. It recommends http://code.google.com/p/lib2a/
You must compile opencv with gcc-mingw. gcc-mingw compiles for a different operating system - mingw is a subset of Linux. Libraries compiled for Windows are simply not compatible.
You can easily find instructions for building opencv for mingw using google, or here:
Getting started with OpenCV 2.4 and MinGW on Windows 7
You'll also need to compile FreeImage, the source code for FreeImage is available at http://freeimage.sourceforge.net/download.html

Deploying a Rcpp package with external static libraries

What's the best way to compile and include a static library (in this case OpenCV) for use in a R package distributed as a binary package. Should I compile it as static outside of R and then put relevant .a files in "inst" or should I include all the source and header files of OpenCV in "inst" and compile from R?
I understand that CRAN will never accept this but it's more for the purpose of making deployment easier for users so they do not need to compile OpenCV or the package from source themselves.
If I get some good pointers on how to proceed or a package that have done something similar I intend to write up a short blog post for other people who want to do the same thing but with other large external libraries (both on Linux, OSX and Windows).
I apologies before hand if I've failed to appreciate that this question has been asked several times before.

How to install third party libraries

I'm sorta new to C++ and I've decided to try and use odeint to do some simulations because python is too slow for my needs.
I found this package, which I want to play with. I'm just not totally sure how to install or where to place these libraries. Is there something for C++ similar to python's pip install?
Side note: I'm trying to do this using Eclipse Kepler, but I'm not married to that idea.
I recommend not putting the code into your own project - that is a rather quick and dirty solution. The correct way to use a library in C++ (in fact, in any programming language that I know) is to keep all libraries separate from your own projects, at a separate location on your filesystem.
You then tell your environment where to find the library files and tell your project to use them. It's always the same basic idea, whether you are using Makefiles or Visual Studio project files.
Look at the documentation of this library. It says:
odeint is a header-only library, no linking against pre-compiled code
is required
This means that the "library files" I just mentioned are just header files. That makes it much easier for you, because you don't have to deal with linker options. In C++, the location where additional (project-external) header files can be found is usually called the "include path".
Your new problem should therefore be: How to tell Eclipse Kepler my include path?
Entering this new problem into Google (as "eclipse kepler include path") yields a few interesting results. It will eventually lead you to the Eclipse documentation about include paths, where you can learn how to edit the C++ include path.
Now that everything is set up, you can finally use the library's header files in your projects via lines like the following:
#include <boost/numeric/odeint.hpp>
Do you notice the < >? They make a big difference, because they are the C++ way of saying "this is not part of my project, please get it from my include path". Just like headers which are part of the language (e.g. <vector> or <iostream>).
All of this may appear troublesome at first, and perhaps you even gain little from it at the beginning, but in the long run, for many different projects and many different libraries, it's the only way to prevent chaos.
Since odeint is a header only library you can place it with your own source code. Simply copy odeint's boost directory where your main.cpp is (assuming you have a main.cpp, but you should get the idea):
your_sources/
main.cpp
boost/
numeric/
odeint/
odeint.hpp
Now you can use the library by including
#include "boost/numeric/odeint.hpp"

Adding library code to your project, or use precompiled binaries?

I need some advice on my project. I am going to use various C++ libraries to accomplish different tasks. I am using Visual Studio 2008. To me, it seems to get a little out of hand when I add the actual source code of the library to my project's path.
It seems easier to just use the include files of the library, and just link precompiled binaries to my application. So my question is this. Is it better for me to include the source code of each library to my project, compile and link, or will it be better to just compile the libraries separately (or download a precompiled version) and link it to my program? Are there any pitfalls of the second way?
Thanks
If a library is available use it.
With C++ and windows you may have to rebuild the library if it was built with a different compiler, there are issues linking C++ libs between gcc/mingw and visual studio.
but in general there is no reason to add the source to your code base.
Depending on the particular library, you might want to be able to debug it. Just downloading precompiled libraries and no source might make that difficult.

Trouble with boost and Code::Blocks

I've been trying to get the boost library working with Code::Blocks and am having some trouble.
When I first tried to get boost, all I did was download the latest zip file and extract it into the CodeBlocks folder. Then I set the compiler settings to look in the boost folder. This allowed me to compile, but not to link. I then read the BoostWindowsQuickReference. I removed everything I had related to boost from my machine, and started fresh.
I followed the instructions step by step, and the only thing that didn't go exactly as the instructions said was that the install-proper folder with the include\boost inside of it was in C: and not my CodeBlocks folder. So I simply copied it (just in case for some reason it needed to be there) to the CodeBlocks folder, which I thought odd because I already had a boost_1_40_0 folder there from downloading the .zip.
I then tried to compile a program and it came up with the exact same error. Then I realized that I forgot to put in the link library (Ex: boost_regex-mgw44-mt-1_40.lib). Now I get
error: ld.exe||cannot find -lboost_regex-mgw44-mt-1_40.lib|
I have a few questions:
Obviously, what am I doing wrong?
Will I need to put in a link library every time I want to use a boost facility (everything is separated into different files, there isn't just one big project.)
Was it necessary to build the library with the boost-jam or could I have just extracted it and used it? (Probably a dumb question, but a small seed of doubt was planted when I got the exact same error.)
Should I try nuwen's MinGW Distro? (Would it make things any easier?)
If any clarification is needed I'd be happy to do so. Thanks.
Edit: and now I can't compile regular programs. So I'm just starting fresh again.
1, it should be -lboost_regex-mgw44-mt-1_40
2, Read the document, most boost library doesn't require to link library
3,4, You should compile it yourself, or try nuwen's MinGW ( I'd installed it and it worked fine )
BoostPro has Windows binaries available for the Boost libraries. If you download just the Boost sources, you will have to compile it, if you are using any of the libraries that are not header-only (such as boost regex). The BoostPro binaries will allow you to link to these without having to build anything.
On Windows it doesn't really matter where you "install" Boost to. Just get the .7z, compile using bjam.exe and pass it the options you need. It will create a folder called "bin.v2" and put the resulting libs in there. In Code::Blocks, all you need to do is edit the project options and point the search path to boost_1_40_0\boost and manually input the libraries to link against (those from bin.v2). It should just work then.
Do not use a precompiled Boost library.