Moving around the lblas library and using it with the g++ compiler - c++

So on my current computer I Have a library to use BLAS functions, but I need to run my c++ program on an external server. I know how to transfer files to the server, but I'm having trouble figuring out how to find my blas library that's on my current computer and then how to link it to the compiler.
So here's the command I use current on my computer g++ program -lblas
And this works great. I run the program and everything is swell. How do I move this library to the external server?
Ideally, I'd like to move this library to the same folder as where my program resides and then link the compiler to that library somehow. Does anyone know how to do this?
If it helps, I know how to download a blas library and get a ".a" file out. I have no idea what to do from there though.

Never mind, simple question. I thought it was a lot more complicated.
For anyone that stumbles upon this, here's what you do:
Get your .a file. For me, I downloaded all the Makefile components necessary to make the .a file from here for blas: http://www.netlib.org/blas/
Next, put it in the same folder as your program if you want to do what I'm doing.
Finally, the command! Compiler, code, library
For me, this was g++ program.cpp blas.a

Related

open cv and c++ compile release without need library for run

first i have simple code with c++ and opencv
its no matter what is the code
now in windows i used visual studio and i add the open cv library to visual stuio and compile it and its work but when i send it to another pc its need open cv library its hard to send all library so i find the program need some files like
opencv_highgui2410.dll
..... .dll
opencv_objdetect2410.dll
that's make my program run without the library
now i turned to ubuntu linux after i compile with codeblocks
this photo will show you how i linker the library
and
and i build the program and run it its work now when i sent the program to another pc its give an error some files not found like
error while loading shared libraries: libopencv_core.so.2.4
i copy this file libopencv_core.so.2.4 and add it beside the program still same error seems not like windows
any solution made me compile opencv program and run program without need full library just some of its file
or any idea to add files (libs) that's project needed to run beside program just like windows
I think this should help you.
But from the comments, i fear you have very little linux experience, I hope this will help, anyway:
https://s1meonov.wordpress.com/2010/12/27/opencv-static-linking-gnulinux-gcc/
(first, be sure to understand what shared and static libraries, how they work and how they impact on software licenses, and also be sure to understand how to install programs in linux. For installing have a look at this link: http://www.makeuseof.com/tag/beginners-guide-installing-software-ubuntu-apt/)

How can I compile a C++ project (with g++) to use on other computers?

This may be obvious, but I want to make sure what to do before I do anything rash. I want to compile my C++ program, libraries and all, to a release executable such that the file can be run on any computer (running the same OS). Right now, I'm on Mac OS X (10.7.4) and I need to be able to run my executable on other Macs. The problem is I am using the OpenCV library in my project, and I only have it installed on this computer. Is there a way to compile with g++ such that if I open this program on a computer that doesn't have the OpenCV library installed, it will work anyway? As in, build all the dependencies into the executable. Or does this happen automatically?
I am also quite new to the ".o" object files, so can those have anything to do with it? I would prefer a way to get it all into a single file, but I'll settle for a package as long as it works.
Thank you.
To expand on molbdnilo's answer, you'll need to create an application bundle (see the Apple Bundle Programming guide). You'll need to move your console application to MyApp.app/Contents/MacOS/MyApp. There's also a Frameworks directory in which you'll need to add the OpenCV library as a framework. See the OpenCV Wiki for some information on the OpenCV framework. A framework (at its simplest) is pretty much a dynamic library wrapped in a particular directory structure.
I would suggest looking into using Xcode on the mac as it simplifies the construction of bundles and linking to frameworks compared to doing it yourself via scripting and Makefiles.
There are two ways to do this. You can static link if you aren't going to run into licensing issues with any of the libraries you are linking to. This is pretty easily handled by using g++ -o myApp -static -lopencv myapp.cpp However, this also depends on static libraries existing for the libraries you want to link to. Most distribute static libs with the shared libs these days.
The other way is to distribute the shared libraries and tell your application to force it to look in a certain spot for the shared library using -rpath. Note: I am telling you the Linux way to do this, it will probably work on a Mac but I have no way to test.
So say all of your shared libraries are in the same directory as your executable, you can compile with: g++ -rpath ./ -lopencv -o YourApp yourApp.cpp
I hope this helps.

Using 3rd Party Libraries in C++

I'm totally spinning my wheels with getting a couple of 3rd party libraries to work with my c++ programs. I'm looking for some general advice (40,000 foot level) about the general steps that one needs to take when implementing libraries.
First, some specifics: I am using code::blocks in Windows as my IDE. I like this IDE and really don't want to switch to anything else if I don't have to (I've tried visual c++ and also some things in linux). The libraries that I am trying to use are GMP and crypto++.
OK. What I think I know is this: After downloading the library, I unzip the file to a folder. I've been unzipping directly to C:\ with each zip file extracted to its own folder (e.g. c:\cryptopp and c:\gmp). I think that the next step is to build the library, but this is where I get totally stuck. How is this done? There are no executable files among those extracted. From what I can tell, I believe that I do this in code::blocks, but I have no idea how?
Finally, assuming that I can get this done, which I believe creates the .lib files, the last step before actually using the library in my code, is to link into the library. This part, I believe that I understand.
So, my question is broad: do I understand this process overall? And if so, how do I go about building these libraries, if in fact that it the thing that I am missing.
Thanks very much for indulging my ignorance. I'm totally rudderless right now and despite hours and hours on google, I'm making no progress. Also, feel free to correct anything that I have stated as fact that is not correct. Thanks a lot!
Usually libraries have a special file called makefile in them, and are built with a utility called Make (or one of it's variations, whatever works uder windows).
Usually all you have to do is to run Make in the directory where you have unpacked the source files, and it will do the rest itself.
If those libraries you mention (GMP and crypto++; disclaimer: I'm not familiar with either of them) don't have project files for code::blocks then you may still be able to compile them under Windows with MinGW.
If you have installed MinGW you use the MinGW shell to navigate to the appropriate directories which would be /c/cryptopp/ and /c/gmp in your examples - The MinGW shell works like a Unix shell, and has different naming conventions.
Then you need to compile the libraries. Check whether there's a Makefile in those directories, if there isn't you can check whether there's a configure script, which will generate the Makefile. If you have the Makefile you can type make which will compile the libraries with MinGW's port of the GCC compiler.
When the compilation is complete you should have a library in the form of a .a file (say libcryptopp.a) that you can link to your project. In code::blocks you would set the linker path (the -L command line option in GCC) to C:\cryptopp\bin or wherever the library has been compiled, and then add libcryptopp.a to the list of libraries you want to link (this is associated with the -l option in GCC). The convention is to leave out the lib prefix and the .a extension, so you would just add cryptopp to your library list. In the end your linker options should look like -LC:\cryptopp\bin -lcryptopp along with the
Also, to be able to use the libraries you need to add the path to the headers directory to the include path of your project. This is associated to the -I command line option in GCC, so your compiler's command line options would have something like -IC:\cryptopp\include somewhere.
Of course, all of the above assumes that you use code::blocks with GCC. If you're using it with VisualC++ then the principles are the same, but the specific steps differ.

streaming c++ program and shared libraries

I have a C++ program which I am trying to run as a streaming job on hadoop (it has only mappers, no reducers). While a simple C++ program works correctly. Another C++ program which links with lot of shared libraries is not working on the grid. ldd on this C++ program shows following: (it uses lot of third party libraries like opencv and boost_serialization)
/usr/local/lib/libboost_serialization.so.1.48.0 /usr/local/lib/libfftw3f.so.3 /usr/local/lib/libconfig++.so.9 /usr/local/lib/liblog4cpp.so.4 /usr/local/lib/libopencv_core.so.2.3 /usr/local/lib/libopencv_contrib.so.2.3
I think because these shared libraries are not installed on data-nodes, its failing. I tried to put these libraries in a tarball and specified this to streaming job using -archives option (Distributed cache). This also did not work (I am not sure if contents from tarball were installed in the appropriate directory on data-nodes).
Any idea how to go about this?
Compile your C++ program statically. Basically:
g++ -o <progra> -static <object-files>
This will produce a binary that has no dependencies. It will be bulky (run strip on it!) but if it runs continuously you shouldn't have a problem.

I'm lost in boost libraries (specifically boost_program_options)

Hi all I've been banging my head against the wall all day now.
So I want to move my program onto the university supercomputer, but it doesn't have boost (and I used boost program_options in my code). On my pc, I just have -lboost_program_options and that works fine, but obviously won't work anymore.
So, I need to package the necessary stuff along with my code so that it will compile on the supercomputer (using intel icpc)
My first hurdle was compiling the line in my makefile that had the code that wanted to include the boost header, but I ran the following in my code folder:
bcp --scan --boost=/usr/include/ main.cpp destination_folder/
And put the resulting files in my include directory. which solved that.
Boost program options isn't a header only package unfortunately, so i need something else. I need to get a library or something. Because i get errors when the compiler gets to the last task on my makefile (doing all the object files)
In my travels I found this question:
extractin/building boost program_options
I tried what the answer suggests, but putting "build" in my command doesn't generate any extra files...
Now totally stuck, don't know how to get this library thing. I've read so much stuff on bjam my head is spinning, I just don't have the level of understanding to process it all in my head.
OS: Linux both systems
One option is to build boost on that machine. Install it in your home. Change your CXXFLAGS and LDDFLAGS to point to the proper header and library directories and build your code there.
The other option is to cross compile both on your PC (if you have such a cross toolchain). Link your code statically to boost and take the final binary to the super computer.
Since both systems are linux, you'll just want to use the binaries. If both systems run on the same CPU, just compile your program statically. If not, download the debian package for the architecture your supercomputer runs on and rip headers and binaries from that.
I've build boost from bjam for cross-compiling to windows, and if there ever was a reason to use the autotools in a project, it's the mess of boost and bjam. Avoid it if possible, and try to adapt the debian package source if you can't.
Instead of building Boost.ProgramOptions you could include and compile all its .cpp files within your project.