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

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.

Related

Reusing Slightly Altered Makefile for Slightly Altered Program Gives Error

I made a copy of a makefile that worked for program A for a new program called program B. To keep things simple program B has all of the same include directives as program A. The only changes made to the new makefile are the obvious changes to the list of object files and the name of the created executable. I can also be sure that the compilation error is not caused by anything in main() or any of the functions of program B. Yet somehow I have an error when I use the make command that goes:
/usr/local/triclops/lib/libtriclops.a(triclops.o): In function `triclopsGetDynamicLibPath':
triclops.cpp:(.text+0x198): undefined reference to `dladdr'
In my makeflie I have the following relevant lines:
CPPFLAGS+=-I/usr/local/triclops/include
LDLIBS+=-L/usr/local/triclops/lib
LDLIBS+=-lpgrlibdcstereo -ltriclops -lpnmutils
I appreciate you help, so thanks in advance. I do not know a lot about makeflies, so I am just trying to reuse the code effectively.
EDIT
Both program A and program B have the same include directives
#include "stereoCamera.h"
#include "Aria.h"
#include <iostream>
#include <cstdio>
#include <cv.h>
#include <highgui.h>
#include <cmath>
#include <vector>
#include <opencv2/highgui/highgui.hpp>
Program B can be thought of essentially as this plus an empty int main(){ return0;} while program A does contain much code and has been working for quite some time now.
You could try linking against libdl with -ldl added to your second LDLIBS+= line. You may also need to add the path of libdl.so typically /usr/lib/ to the first LDLIBS+= line.
I cannot answer why program A compiles with the 'same' makefile while program B fails without looking at the programs or the makefiles though.

Linking error while using Armadillo and Lapack

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

Compile C++ with static lib

this will probably a dumb question for you guy's but I have no experience in C++ what so ever. I'm using an open source project osrm (which is awesome). Still to request a route, you have make an http request. To reduce the running time, I would like to build a wrapper around the code and call it using the command line. So I googled a bit and found that osrm already creates a static lib (.a file) when compiling the project. I also found a piece of code that points me in the right directions for building a wrapper. So to begin I build a simple hello world program (see below) that includes some files from that static lib. To compile I followed this tutorial.
My directory structure looks like this:
./helloWorld.cpp
./libs/libOSRM.a
And the command to compile is this:
gcc –static helloworld.cpp –L ./libs –l libOSRM.a
The code it selve:
#include "Router.h"
#include "boost/filesystem/path.hpp"
#include "ServerPaths.h"
#include "ProgramOptions.h"
#include <InternalDataFacade.h>
#include <viaroute.hpp>
#include <iostream.h>
main()
{
cout << "Hello World!";
return 0;
}
the exact error I got:
fatal error: ServerPaths.h: No such file or directory #include "ServerPaths.h"
Add the -IPathToTheHeaderFiles to the compiler options. So it will find the files to be included. Replace PathToTheHeaderFiles with the path where your file ServPaths.h resides.
Edit: Add as many -I as you need for further header files.
Additionally it would be worth to read a book about C++ or/and the GCC manual1
1 Section 3.11 will help.

Eclipse CDT does not resolve variables initialized in #include files

The problem occurs when trying to use CDT for editing files in OpenFOAM, a popular computational fluid dynamics software package. I am using Eclipse Kepler SR2 Build id: 20140224-0627 and CDT 8.3.0.201402142303 The following is a simplified version of the problem.
Given the following hello.cpp
#include <iostream>
#include <string>
int main(){
#include "hello.H"
std::cout << hello << std::endl;
}
and the following hello.H
std::string hello("Hello world!");
Indexing can't resolve hello in hello.cpp. However, if I change hello.H to hello.inc it does work. This isn't a feasible solution for OpenFOAM. How could I make the indexing and autocomplete work with the given structure?
Note: I did try Eclipse Luna too, and the same happened.
Edit: I think this might be a bug. After more experimenting, the following happened. When I named the hello.H to hello.inc, the hello in hello.cpp was recognized. However, when I rebuild index it wasn't. Then I resaved hello.inc without functional changes, and behold, it was recognized again. However, if I turned off automatic indexing it no longer got resolved after rebuilding the index.
Edit 2: After further research on the problem, I found the following duplicates, without the random behavior:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=418085
and to my shame:
#include inside function body doesn't work (CDT/Eclipse C++)
Thus this question can be closed as a duplicate. To those interested, CDT indexer is not actually designed to do this, as this is bad coding style. The main message to me was that I should use some other IDE with OpenFoam.

OpenGL SOIL Undefined reference to glBindTexture, glTexImage2d, etc

I'm using C++ and Opengl, and I'm trying to use SOIL, but when I compile, I get undefined reference to glBindTexture, glTexImage2D, etc. However, this is only coming from SOIL.c, not my own source code. This is what the error produces:
http://pastebin.com/sKrQaBhz
My graphics card is NVIDIA GeForce GTX 680 and my drivers are fully updated. I have everything linked and I'm using premake to manage my project. I'm developing on a linux machine, however, I'm trying to cross compile it onto my windows machine, which gives this error. If I compile it on linux, it's completely fine. This is my premake4.lua file:
http://pastebin.com/T4hsbdz0
My include files is this:
#include "opengl/gl_core_3_3.hpp"
#include <GLFW/glfw3.h>
#include <SOIL/SOIL.h>
#include <glm/glm.hpp>
#include <glm/gtx/transform.hpp>
#include <glm/gtc/type_ptr.hpp>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include "loadshader.hpp"
I'm using mingw32 to compile my code. Before I was using SOIL, everything was fine. I downloaded SOIL from their webpage at lonesock.net, which I then copied over the libSOIL.a and their include files, but it just doesn't work.
Links order matters for g++.
Try this order:
links { "SOIL", "glfw3", "opengl32", "gdi32", "glu32" }
(edit: fixed the OP answer according to the duplicated question in Premake forum: http://industriousone.com/topic/how-use-premake-compile-static-library)
Looking at SOIL homepage, they said that it must be linked staticly. So, instead of using dynamic linking ('-l' in gcc compiler), try to specify the full path of the library.
This post illustrate what I want to say: https://stackoverflow.com/a/4156190/2293156
gcc -lsome_dynamic_lib some_static_lib.a code.c