C++ codes on Linux and MAC

Discussion in 'Programming' started by fr33d0m, Aug 30, 2007.

  1. #1
    Hi, i need some help here :)
    I've a C++ source code that i compiled on Linux, but when i pass the binary files to my friend whom are using MAC. He said that he couldn't run the binary files, he needs to recompile it on his MAC then he is able to run the code.
    Is there any way so the binary files from Linux can run directly on MAC without recompiling it again?
    Can someone guide me, pls? Thx
    Below is my code :
    
    #include <stdio.h>
    #include <stdlib.h>
    #include <iostream>
    #include <fstream>
    #include <unistd.h>
    using namespace std;
    
    int main()  {
    	const char *filePath = "/usr/share/ss/myfile.txt";
    	
    	char *msg;
    
    	if(remove(filePath) != 0) {
    		msg = "Uninstallation Unsuccessful, Please Contact Admin";
    		cout << msg << endl;
    		cout << "Press [Enter] to continue" << endl;
    		cin.get(); 
    		return 1;
    	}
    	else {
    		msg = "Uninstallation Successful";
    		cout << msg << endl;
    		cout << "Press [Enter] to continue" << endl;
    		cin.get(); 
    		return 1;
    	}
    	
    	return 0;
    }
    
    Code (markup):

     
    fr33d0m, Aug 30, 2007 IP
  2. zac439

    zac439 Notable Member

    Messages:
    3,074
    Likes Received:
    214
    Best Answers:
    0
    Trophy Points:
    260
    #2
    Couldn't you just give him the project file?

    Go to where your project is located and try giving him the entire folder's worth of files. It should work, otherwise let me know and I'll get to the bottom of it :)
     
    zac439, Aug 30, 2007 IP
  3. fr33d0m

    fr33d0m Peon

    Messages:
    24
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Rrrr, actually.
    We will need the binary files to be included in our installer file :D
    It has to be general, so when user run the file. It will delete the installation folder, no matter user run on Linux or Mac platform.
    Does binary files that is compiled on Linux cant run on Mac?
    Pls give me advice, thx. We are doing our final year project
     
    fr33d0m, Aug 31, 2007 IP
  4. m0nkeymafia

    m0nkeymafia Well-Known Member

    Messages:
    399
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    125
    #4
    MAC, Linux and Windows all compile into different code so you would have to recompile every time.

    The best thing you can do is PImpl your code to make it compile faster.

    P.s.
    You shouldnt use "using namespace" as it dilutes the current namespace
    You probably only need half those header files.
     
    m0nkeymafia, Aug 31, 2007 IP
  5. zac439

    zac439 Notable Member

    Messages:
    3,074
    Likes Received:
    214
    Best Answers:
    0
    Trophy Points:
    260
    #5
    I was under the impression "using namespace std;" was a required statement? It isn't?
     
    zac439, Aug 31, 2007 IP
  6. m0nkeymafia

    m0nkeymafia Well-Known Member

    Messages:
    399
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    125
    #6
    nope
    your MUCH better off prefixing those functions with std::

    it has the same effect but with some noticeable differences.
    Firstly the namespaces arent polluted with functions you dont need
    and secondly when you look at the code again after 6 months youll know that they are std functions rather than other functions

    it also helps greatly when you start creating large projects with many namespaces in!

    just good practices to get into dude!
     
    m0nkeymafia, Aug 31, 2007 IP
  7. noppid

    noppid gunnin' for the quota

    Messages:
    4,246
    Likes Received:
    232
    Best Answers:
    0
    Trophy Points:
    135
    #7
    That C code looks like it could be duplicated in a simpler scripting language for each platform.

    Perhaps that could simplify things?
     
    noppid, Aug 31, 2007 IP
  8. zac439

    zac439 Notable Member

    Messages:
    3,074
    Likes Received:
    214
    Best Answers:
    0
    Trophy Points:
    260
    #8
    Why not just copy the source code to a text file, send him the text file, and then have him compile it on Linux?
     
    zac439, Aug 31, 2007 IP