SFML 1.6 without admin priviliges - c++

So I have this SFML 1.6 application that works well on Mac OS X Lion. Currently the way I have it is that the SFML frameworks are in /Library/Frameworks and it works well, however to install on other machines it requires admin privileges. So I want to do one of the following:
Be able to install the libraries in /User/idk/Library/Frameworks or similar
Package the libraries and the app into a Mac disk image and have it reference the libraries from there
Statically link the libraries
Now since the program is built using the Terminal with makefiles, I would prefer the solution to be in the Terminal rather than XCode, but if absolutely necessary then I guess I could somehow import the project to XCode.
So can anyone explain (precisely) how to do any of the three above, whichever is the easiest to do?
By the way I'm using the LLVM GCC 4.2 that ships with XCode 4.1 for the compilation.
EDIT:
How about someone tries the other two, aside from statically linking?

I solved it so... kind of a waste of bounty points... SUCKS FOR YOU! :P
I did something quite simple and was surprised no one else had suggested it:
I used install_name_tool to change the names and dependencies of the SFML dynamic libraries so that they can be placed in the same directory as the executable, or in a special folder, but that's relative to the executable's directory. So it requires no admin privileges, and I easily packaged it all into an application bundle.

You should probably statically link to SFML. To do this you will have to compile SFML as a static library. The easiest way to do this is probably to modify the Xcode project that comes with SFML ("SFML with Intel 64 bits.xcodeproj"). You need to change the Mach-O type of the libraries to Static Library.
I've uploaded the modified version of SFML with Intel 64 bits.xcodeproj that I use, you can get it here. (This project requires GCC4.2, and so only works with Xcode 3).
Statically linking to SFML is very similar to dynamically linking to it, just remember that you also need to link to Cocoa.framework, OpenGL.framework, and CoreFoundation.framework.
Also note that if you want to deploy to OSX 10.4 or earlier, you should statically link to libfreetype. The libfreetype that is supplied with the OS is in a different location in 10.4 and earlier, and this causes problems when it is dynamically linked.

Related

How to package c++ dependencies on linux

I'm developing a c++ program on Ubuntu 16.04 using cmake, compiling with g++5 and clang++-3.8.
Now I'd like to make this Program availabile for 14.04, too, but as I'm using a lot of c++14 features I can't just recompile it on that system. Instead, I wanted to ask if/how it is possible to package all dependencies (in particular the c++ standard library) in a way that I can just unpack a folder on the target system and run the app.
Ideally I'm looking for some automated/scripted solution that I can add to my cmake build.
Bonus Question:
For now, this is just a simple command line program for which I can easily recompile all 3rd party dependencies (and in fact I do). In the long run however, I'd also like to port a QT application. Ideally the solution would also work for that scenario.
The worst part of your contitions is an incompatible standard library.
You have to link it statically anyway (see comments to your answer).
A number of options:
Completely static linking:
I think it's easiest way for you, but it requires that you can build (or get by any way) all third-party libs as static. If you can't for some reason it's not your option.
You just build your app as usual and then link it with all libs you need statically (see documentation for your compiler). Thus you get completely dependencies-free executable, it will work on any ABI-compatible system (you may need to check if x86 executable works on x86_64).
Partially static linking
You link statically everything you can and dynamically other. So you distribute all dynamic libs (*.so) along with you app (in path/to/app/lib or path/to/app/ folder), so you don't depend on system libraries. Create your deb package which brings all files into /opt or $HOME/appname folder. You have to load all dynamic libs either "by hand" or ask compiler to do it on linking stage (see documentation).
Docker container
I don't know much about it but I know exactly it requires that docker be installed on target system (not your option).
Useful links:
g++ link options
static linking manual
Finding Dynamic or Shared Libraries
There are similar docs for clang, google it.

how to deploy netbeans Qt project to stand-alone executable

I'm working on a netbeans c++ Qt project in Ubuntu. I would like to deploy this program to a stand-alone executable that can be run from Windows machines.
I can't find anything online on how to do this. Is it possible?
You will have to compile the source on a Windows machine or set up a cross compiling toolchain.
I highly suggest the first option as the second isn't any fun.
Then you will either have to statically link the proper Qt dlls and compile them into the final executable or simply copy the required dlls into the path of the executable. What's the easiest way to figure out the required dlls? Try to run the program, it will fail and tell you which libraries you need to link to it. (Or run an ldd on ubuntu and keep track of the list)
(Note:I think statically linking the libraries may have licensing implications. It has been a while since I looked at the Qt licenses.)

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.

Running Qt program without IDE

How can i run a program which already has been built and compiled before on Qt IDE, so that i can take that program and run on any computer I want without recompiling it on that computer. I am a beginner so bare answering this question.:)
Thanks
There are a few parts to your problem.
1) You need to compile it for each architecture you want it to be used on.
2) Each architecture will have a set of Qt dynamic libraries associated with it too that need to be available.
3) Some architectures have an easy-to-deploy mechanism. EG, on a mac you can run "macdeployqt" to get the libraries into the application directory. For nokia phones (symbian, harmattan (N9), etc) QtCreator has a deploy step that will build a package for the phone and even include an icon.
4) For systems without such a feature, like linux and windows, you'll either need to distribute the binary and require the user to have Qt available or to package up a directory/zip containing the needed Qt libraries and distribute that.
It doesn't launch because it cannot find the dependencies. As you are on Windows, these libraries can be moved in the same directory as your application. To find which library is missing, use dependency walker
I am pretty sure these libraries are not found:
The Qt dynamic libraries (can be found on Qt bin directory, take the dll)
The C dynamic libraries used for compilation. If you are on creator and use default setting it will be mingw-xxx(can be found in the Qt installation directory, don t know exactly where)
Every Architect has a set of CPU Instructions.
so it's like when you hear a language that you don't understand. like when i speak Arabic To Someone who don't Understand The Language.
Every Architect Has a set of Processor Instructions, The Compiler only convert the code into instruction only understood by The Architecture that your CPU is.
That's Why Python and the most of High level languages Use Interpreter Instead of a Compiler.
But There are some cross compilers like MinGw that Support Cross compiling To Windows (.exe files)
Simply QT Have some libraries important to be in the working directory for your project.

Static and Dynamic Libraries

I am using SFML, and I am building an application in Code::Blocks and mingw32. I have have added the SFML libraries (sfml-whatever.a) to my project, and it runs nicely.
BUT iIrc, the static libraries get 'compiled' into the executable. If this is so, then why do I have to place all the SFML DLL's next to the executable for it to run anywhere outside of Code::Blocks? And if I were to somehow 'dynamically link' the DLL's from within Code::Blocks to my project, (I don't know how to do that), would I still have to ship my executable with all the .a files for it to run properly?
Thanks in advance, I am not quite familiar with libraries, static or dynamic. If it makes any difference, I am working on Ubuntu linux, and I am using mingw32 for cross-compiling.
With SFML you can link statically to their libraries as mentioned in the comments above. This way its all compiled into the executable and you won't need to ship it with the DLL's. How this is done depends on whether you are using SFML 1.6 or 2.0.
1.6 doesn't require any preprocessor definitions, but 2.0 requires you to build a solution/makefile using cmake for your compiler and then #define SFML_STATIC in your preprocessor definitions.
In this case, the static libraries simply contain the code that interfaces to the dynamic libraries, it's not the actual library code.