简体   繁体   中英

C++ Compile code on Mac OS X and run it on Linux x86

I am working on a simulator, which I coded on my Mac OS 10.6 using XCode , and the Boost library. I want to run it on my university server (some Linux Red Hat x86 ), but when running the executable produced by XCode on the server: " ./simulator: Exec format error. Wrong Architecture ." is displayed.

I cannot compile my code on the server, because Boost is not installed and I do not have the right to install it.

How can I generate an executable that would run on this Linux server? Using XCode, or command lines?

NB: I can run my code on my computer, but it would be so much faster on the server.

If you're feeling moderately adventurous you could install a VM such as virtualbox, install the same version of Linux in the VM and you'll have the full capability to install any packages you want. Build an executable in your VM and run it on your school server.

Just make sure you match the version of RH and the compiler and C/C++ libraries or your executable might not run

You don't need to install Boost in order to use it; especially if you're using Boost libraries that are entirely contained in header files, which is the majority of Boost's libraries. You only need to include those Boost headers with your source code and it should compile just fine.

For an easy way to bundle the needed Boost headers together with your source code, have a look at Boost's BCP tool.

You need to "cross compile". ie Build a linux exe on a different platform.

Some compilers will do it - others won't. Not sure about Mac ones.

As others have said: if your compiler won't cross compile to linux, doing it all in a VM is probably the easiest solution.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM