Transfer c++ executable from desktop linux distribution to a linux board one - c++

I'm developing a c++ app in Ubuntu Desktop 16.04. I have created an executable c++ file with eclipse. Furthermore I'm using external libraries like poco and avro which I link dynamically. I need to try my app on a cubietruck that runs on Lubuntu Desktop 12.10. My approach it to install only the desired g++ compiler on Lubuntu because I want to install as less as possible on the board. Then to transfer there the same folder structure which resides in Ubuntu that contains the executable file as well as the external libraries'.so files and its headers. Since I have almost no experience in boards and transfer between linux distro's is my approach an efficient one?

I think the main problem is the different architecture. Your board is ARM while your Desktop is x86. Your application needs to be compiled on the board. Also you need to get the library files for arm.

Related

Build and run Android native application (executable) on Ubuntu

I have code base written in C++. Build system uses Android's ndk-build script with makefiles defined for shared lib and executable. Binary runs on Android device.
My Question is: is there possibility to use current build configuration and build this executable to run on my local host e.g. Ubuntu?
I tried (with simple example as "hello world") with ABI change to x86_64 but this doesn't work. Executable file uses dynamic linker from Android' environment.
Do you have any idea how to setup this?
Not with the same build system. ndk-build can only build Android binaries.
If you migrate your build to another system (make, cmake, whatever) then your code might work. If the only pieces of the NDK you're using are libc/libm/libdl, then it should work (although there are a few Android extensions in libc and libdl). If you're relying on any of the Android framework libraries then it won't work because those don't exist on an Ubuntu system.

Running linux g++ compiled code on Mac

Is is possible to compile c++ code on linux using g++ and run the code on Mac OSX? I have a few c++ programs that use one .cpp file, a few .h files, and a MakeFile altogether that produces a .o file that I typically run through the terminal. However, I'd like to find a way to send only the executable to my partner's home mac so he may review my program locally. (I've also use a few of these programs for automated math calculations, so it would be very convenient to run locally). I understand OSX typically uses .app bundles, but I'm not extremely familiar with how this works. Will the .o file (or ./a.out that's more common around here) simply run on OSX? I'd rather not install xCode on this machine if I don't have to.
Thanks a ton
It is possible to compile C++ on Linux and produce an executable on OS X. However you have to compile the code in a special way, called 'cross compilation'. It's not particularly simple to set up cross compilation and you need certain files from the platform you're targeting.
It's much simpler to just compile directly on the target platform.
If the Mac has a recent version of OS X installed you can easily install the necessary command line tools: Just try to run one of them or run the command xcode-select --install and OS X will ask to install the command line tools. (This will install just the necessary tools for compilation on the command line, and not the entire Xcode applicaiton.)
I understand OSX typically uses .app bundles, but I'm not extremely familiar with how this works.
You don't need to worry about .app bundles for simple C++ programs. OS X can run regular executable files just like linux. (Though the executable file format is different: OS X uses the Mach-O format instead of Linux's ELF format.)
Will the .o file (or ./a.out that's more common around here) simply run on OSX?
.o files, called 'object' files, don't run on their own anyway; They have to be 'linked' into an executable file. The default name for executable files created by the gcc toolchain is 'a.out' (as specified in the POSIX standard).
If you set up cross compilation to OS X then, yes, you could produce a.out files that would just run on OS X. The a.out files you produce normally for Linux , i.e. without cross compilation, won't run on OS X.
I'd rather not install xCode on this machine if I don't have to.
Xcode doesn't run on Linux anyway, so you couldn't run it. Instead you'd get a version of gcc that cross-compiles to OS X, or you'd install a different compiler, clang (and linker, lld instead of ld or gold).
A simple answer to your question is no. You cannot compile a program under linux and expect it to run on MacOSX.
However, MacOSX is just another UNIX OS under the hood and you can build your project with Make and GCC. If your partner doesn't know how to do this, I would suggest asking him to let you SSH into his machine.
However, if you're building executable on a mac you will want to install XCode. Even if you're using GCC from brew.
Another alternative is have your partner install a linux VM. He can use oracles virtual box to install linux and run your code w/in macosx.
I would suggest you sign up at Amazon for a free EC2 (Elastic Compute Cloud) account and take the free Basic Linux box. Install and build your software on Linux on there and then let your partner log into it and run it using just ssh which is already on OSX anyway. So no need to install anything on his Mac.
That way there is no need to transfer files between yourselves and update stuff when you make changes - just one environment to manage and keep up to date that you can both access from anywhere, any time.

"Cannot execute binary file" when running compiled c++ programs with Eclipse on Ubuntu for Windows platform

I would like to move from Visual Studio on Windows platform to Eclipse on Ubuntu for c++ development, since I develop almost all my programs on Java, with Eclipse, and I just use a Windows virtual machine in order to develop C++ programs for Win OS. So if I would be happy being able to not use Windows VM at all. However, I've managed to configure MinGW and Eclipse successfully enough to compile programs, but not to execute them.
Steps I've gone through so far:
I've installed mingw32 package and dependencies:
$ sudo apt-get install mingw32
I've installed Eclipse Mars for C/C++ development (manually, to keep this installation isolated from other Eclipses I have) and created a new project in this way:
- New C++ project.
- [...]
- Cross-prefix: i586-mingw32msvc-
- Cross path: /usr/bin/
With this configuration I'm able to correctly build a .exe which I can successfully execute on Windows, but when trying to debug it or execute it under Eclipse I get this error: "cannot execute binary file".
Googleing I've seen some posts suggesting to use wine in order to execute the .exe, but I thought mingw32 would be able to execute it. Am I wrong and this is not possible or just doing something wrong?
Mingw32 is a windows compiler, and will compile source to a Windows executable file. Additionally, the compiler cannot execute files (as worded in the question), it just compiles the source code to an executable form, in this case the windows executable (*.exe). So yes, in order to run the .exe in Ubuntu you would need something like Wine which emulates a Windows environment
mingw is a set of GNU tools for building native Windows executables.
It does not execute anything.
If you really want to cross-compile for Windows, you need Windows or an emulator for the execution.
To build for Ubuntu you can just use the native compilers.
sudo apt-get install gcc

Run cygwin built exe in windows without cygwin's environment

I'm trying to port a linux software in Windows.
My software depends on gtk, boost and libgerbv (which I've manually compiled on cygwin)
I've successfully compiled it and it works if I run it in the cygwin's terminal, but if I copy the .exe in a folder with cygwin1.dll and I run it, it terminates silently
Same result if I run it within cmd.exe.
How can I "export" this executable outside the cygwin environment? I want to distribute it with just the needed shared libraries and cygwin1.dll
Thanks
"How can I "export" this executable outside the cygwin environment?"
In short: That's not possible. You'll need to have a cygwin environment installed on the target machine, and run the programs created in cygwin from a cygwin shell.
Cygwin requires a number of it's own .dll files, to bind to the underlying Windows OS. These cannot be just copied to another windows system without having a complete installation of cygwin.
Here're some more details about this: What is the difference between Cygwin and MinGW?
That's why I prefer to use MinGW to target windows systems portably. Cygwin has it's powers and right to exist, when it comes to cross compile code for different (e.g. embedded) targets running on windows as host.

How to set up cross platform compliation for C++ (NetBeans in win7 and make in linux)

I would like to set up a gcc C++ project using my preferred editro NetBeans (since it works with gcc), that would depend on some external libraries. I want it to compile in NetBeans with gcc chain, and in production - using command line make under linux. Preferably, first create project in NetBeans and then modify something to accept it in Linux.
The libraries will be the same but located in different folders, so I need to separate include pathes for these, and during compile time correct pathes must be picked.
Also, I might need to use minor amount of conditional compilation, as under windows and linux some #include directives might or might not contain library sub-pathes.
Is there any useful guide how to make this happen?
Assuming you are developping with Netbeans on Win7 and you have a Linux machine (lets call it a server) accessible by TCP/IP with all packages proprely installed (gcc and you program depedencies).
You need to:
Add a Build Host in Netbeans Services and setup the ssh connection (you server needs deamon sshd active of course). Netbeans will seek for a toolchain. If everything worked out: this is your remote build host;
If you have all your packages installed on your linux server (I mean installed form the package manager), sources will be located in /usr/include and libraries in /usr/lib;
In your project properties, define a new profiles for your server application (choosing the proper build host) and resolve dependecies.
Then, when compiling for Win7 target use default profiles Netbeans created for you (build host is localhost) and when compiling for Linux target use new profiles you created (build host is your linux server).
To minimize conditional pre-porcessor codes when including, you just need to use relative paths and keep on Win7 the same file hierarchy for your dependencies that your linux server has.
Additionnaly, you can run on linux server development tools such has gprof and valgrind to check your work.
This should work easily.