Linking error while using Armadillo and Lapack - c++

my name is Ulrich and I just started writing my bachelor thesis, which includes a part where i write a program, which needs a Singular Value Decompostion.
At first i need to say, English is my 2nd language and I'm totally new to programming. So please help me with easy words ;)
After some research, I found that Armadillo offers a good SVD()-function, which is based on the Lapack library, so I downloaded them both and tried to install them correctly, and I think i failed at that part:
So here is the relevant parts of my written code:
#include <iostream>
#include <vector>
#include <random>
#include <time.h>
#include <math.h>
#include <fstream>
#include <cmath>
#include <sstream>
#include <armadillo>
using namespace std;
using namespace arma;
mat A(N,2*N+1, fill::zeros); //the zeroess will be replaced later, don't worry i know a SVD of zeroes is stupid ;)
mat U;
mat V;
vec S=svd(A);
The compilation error is:
undefined reference to 'dgesdd_'
What I use:
Code Blocks with MinGW compiler (Probably latest version; I installed it 3 days ago).
Armadillo Library 4.650.4
Lapack Library 3.5.0
Windows 8.1
What I have done:
I linked in the settings of Codeblocks the compiler with the Folder containing a lot of .header files from Armadillo (.../include/armadillo_bits/)
and i linked in the same way the Lapack folder with 4 .header files(.../lapacke/include/)
Furthermore the readme from armadillo said I shall comment out certain lines from a file called config.hpp
i looked through the whole file, but i think i don't have to uncomment anything. but just in case you need to see it, I can upload the file for you.
PS: while searching for a solution I came across this question which looked quite similar to my problem and seems to be easy fixable, but unfortunately I don't understand anything of it:
Question from stackoverflow
i hope you can help me with this,
Ulli

Related

Why do R packages using C++ use #include <R.h>, #include <Rdefines.h> and #include <Rmath.h>?

I am working on a massive R package with a lot of old C++ files in it. Only one function is called by .Call in R.
At the beginning there is a lot a #include call, that I'm removing by commenting and compiling, but one thing I don't understand is the difference between:
#include <R.h>
#include <Rdefines.h>
#include <Rmath.h>
I want to clean this part of every files to remove useless libraries, but in most examples I see, there is both R.h and Rdefines.h, although commenting R.h return no warnings during the compilation. Is it usefull ?
PS : The final objective is to only use Rcpp, but for now I first need to understand and clean the project.

C++ Boost and ImageMagick++ API issue

While developing Raspberry Pi library compiled by g++4.9.2 I have met compability issue between boost (1.6.2) and ImageMagick++ API (7.0). When compiling this code:
#include <Magick++.h>
#include <boost/filesystem.hpp>
#include <boost/foreach.hpp>
I got these boost errors:
__assert_fail was not declared in this scope (path_trails.hpp)
...
__assert_fail was not declared in this scope (path.hpp)
...
__assert_fail was not declared in this scope (shared_ptr.hpp)
When deleting #include <Magick++.h> line everything runs fine. Unfortunately I need boost and ImageMagick as well in this source file. How to solve this issue?
A simple workaround is to include Magick++.h after boost.
#include <boost/filesystem.hpp>
#include <boost/foreach.hpp>
#include <Magick++.h>
I don't have a proper explanation for this problem but it seems to come from a clash when using different headers including assert.h (I had the same problem using the assimp library and ImageMagick) but I don't get why the order matters.
Reproducing your case, assert.h is included in:
cassert for boost
MagickCore/pixel-accessor.h for Magick++.h
If someone has an explanation for this problem feel free to edit.

c++: How to remove libstdc++.so.6 dependencies

I have 2 program I wrote on my windows computer using Visual Studio 2013. They run fine and work perfectly on my computer, but when I brought them over to my school account that is on a Linux machine, a problem arose. They compile and 1 ran, but the other did not. The one that did not run gave me an error:
.../lib/compat/libstdc++.so.6: version CXXABI_1.3.2 required by...
I have been doing research and I can't seem to find out what in my program would be using libstdc++.so.6, I'm not even really sure what it is or does. Since I am on a student account I can't go installing it using sudo, and it is a homework so I can't submit it using my own libraries.
Any Idea on what my program might be using that would require libstdc++.so.6?
I have 3 files: main.cpp, LinkedList.cpp and LinkedList.h.
I think it might be in main.cpp because I think it stems from a library I am including and main.cpp is the only one that uses outside libraries. Here is the list of libraries it uses:
#include <iomanip>
#include <stdio.h>
#include <fstream>
#include <ctype.h>
#include <string>
#include <iostream>
#include <vector>
#include <sstream>
#include <bitset>
#include <algorithm>
#include "LinkedList.h"
Thanks in advance!
You are trying to run a program linked against one version of the libraries under another set. That should work fine as long as the library versions aren't too far apart. In your case, the difference between libraries is just too large.
GCC (C++ in particular) has changed quite a bit lately, some programs that used to compile and run fine now blow up or don't compile at all (due to language changes, compiler bugs accepting broken code, ...), and the library ABI has also changed. Your best bet is to carry source code around, and make sure you got compatible language versions on both ends. If that is inconvenient, a solution is to make sure you have the same compiler (and other environment) at both places. The easiest way to get this is to install the same distribution and version.
First you can't remove the dependencies of libstdc++.so.6, because it's a standard C++ library.
To solve your problem you have to check whether your libstdc++.so have the right version
strings /usr/lib64/libstdc++.so.6|grep GXXABI_1.3.1
if there have no matching version, you will have 2 methods like these:
update your gcc on your school's linux OS
yum intsall gcc
download a matching libstdc++.so from this website:
download gcc || download matching libstdc++
then replace the libstdc++.so to /usr/lib64/libstdc++.so.6.*
SOLUTION
I went through a few steps to find my solution. Originally I could compile my program but could not run it.
1) My first step to solve the issue was to change my method of compiling. Originally I compiled my program with the following: g++ main.cpp LinkedList.cpp -o output. I changed it to: g++ -static main.cpp LinkedList.cpp -o output which allowed me to compile and run. This worked but static is a method to dynamically link libraries. This prevents linking with the shared libraries. This is not a good solution because it takes a lot longer and increases the file size of the executable, so I wanted to improve.
2) The second thing I did was remove using namespace std. Yes, I cheated and used it. So I went through my program and added std:: to the appropriate places.
3) The last thing I did was clean up my code. I was using a lot of libraries because my program was a large and complicated program. I was using all of the libraries I had listed in my original post. I went through my code and anywhere I was using a function from a library I would try and write my own code that would do the same thing which would result in my program not depending on those libraries. I was able to replicate a decent amount of these dependent foreign functions with my own which added lot of code, but it allowing me to remove some of these includes. My list of includes is now:
#include <fstream>
#include <string>
#include <iostream>
#include <vector>
#include <algorithm>
#include "LinkedList.h"
#include <math.h>
I am not sure exactly which step resolved my issue, but now I can compile with my preferred method, g++ main.cpp LinkedList.cpp -o output, and my program runs fine.
I hope this helps someone.

C++ #include not working in Microsoft Visual Studio 2010

I have been using Visual Studio and I think I must have messed with some setting. I can't include basic things like <iostream>. How can I fix this?
#include <iostream> // for standard I/O
#include <string> // for strings
#include <iomanip> // for controlling float print precision
#include <sstream> // string to number conversion
#include <opencv2/imgproc/imgproc.hpp> // Gaussian Blur
#include <opencv2/core/core.hpp> // Basic OpenCV structures (cv::Mat, Scalar)
#include <opencv2/highgui/highgui.hpp> // OpenCV window I/O
using namespace std;
using namespace cv;
All the above lines are in red squiggle below. My guess is while trying to configure Visual Studio to use OpenCv, I messed with some setting.
More than likely, you forgot to add 'using namespace std' as pretty much nothing in iostream is really useful without it. If you are getting 'cant find ...', then you have a setup problem and should reinstall Visual Studio because the headers were not properly placed.
Hope this helps, feel free to post your code and I can tell you for sure what the problem is, but that is the most likely of them.

How to #include hash with ext, tr1, or __gnu_cxx in XCode, C++

I'm trying to work with the google-sparsehash library and I'd like to include the hash library described in the link,
using ext::hash; // or __gnu_cxx::hash, or maybe tr1::hash, depending on your OS
and I've tried one of each:
#include <ext/hash>
#include <ext>
#include <__gnu_cxx>
#include <tr1>
which none worked with XCode. I've also "using", where I was told that __gnu_cxx does not contain "hash". How do I describe this library to XCode (3.2.6) on OS X (10.6.8)?
Or more generally, where is this hash function described in a Mac / XCode?
In C++11:
#include <functional>
using std::hash;
In C++03 with TR1:
#include <tr1/functional>
using std::tr1::hash;
So far as I can tell, it doesn't seem possible to get at the hash functors without also pulling in definitions for the various hash tables. At least not without fooling around with library internal headers.
Try:
#include <ext/hash_map>
using __gnu_cxx::hash;
or:
#include <tr1/unordered_map>
using std::tr1::hash;