How to compile C# on a mac?

Discussion in 'Mac Programming' started by Astralogic, Apr 12, 2018.

  1. Astralogic, Apr 12, 2018
    Last edited: Apr 12, 2018

    Astralogic macrumors newbie

    Astralogic

    Joined:
    Apr 12, 2018
    #1
    Hi, I have written a simple console application in C#. I wrote it in windows using VS.

    I have the source code and want to compile it for mac. What is the quickest, simplest way to compile this source code?

    I am completely lost on a mac, and was told that my simple console application would compile and run fine on a mac but I don't know what I'm doing :/

    Edit: I want to mention I have found several solutions, but all require a higher version of the OS then what I have (10.8).

    Edit 2: If I find no way to compile this code, would someone mind doing it for me? It's a very small simple program that compiles in less then one second.
     
  2. Senor Cuete macrumors 6502

    Joined:
    Nov 9, 2011
    #3
    I searched for C# at the Mac developer site:

    https://developer.apple.com/search/?q=C#and I don't see anything useful.

    Also I searched for "C# translators". I don't see anything useful.

    Searching for "C# on the Mac" lists a lot of sites. It looks like running Windows on the Mac using an emulator like Bootcamp is what they recommend.

    Apparently there is an xCode plug-in for C#:

    https://code.google.com/archive/p/cocoa-sharp-dev/wikis/CSharpPlugin.wiki
    --- Post Merged, Apr 12, 2018 ---
    If it's a small, simple, console program, you could just write it in C. All of the encapsulation, etc. in an object-oriented language isn't really needed in a small console app. XCode will deal with C easily.
     
  3. Astralogic thread starter macrumors newbie

    Astralogic

    Joined:
    Apr 12, 2018
    #4
    But if I wrote it in C, how would I compile it? Wouldn't I have the same problem?
     
  4. szymczyk macrumors regular

    Joined:
    Mar 5, 2006
    #5
    List those solutions so people don't reply with them and waste your time.
     
  5. lloyddean macrumors 6502a

    Joined:
    May 10, 2009
    Location:
    Des Moines, WA
    #6

    Post the code here and we'll see what comes of it.
     
  6. D.T. macrumors G3

    D.T.

    Joined:
    Sep 15, 2011
    Location:
    Vilano Beach, FL
    #7
    You're crossing a lot of topics, languages vs. IDEs, you can knock out a simple program in C and compile it in terminal using GCC (which might not be installed).

    Are you trying to learn how to code, or doing some kind of school assignment? If you're going to code on the Mac, I'd get a good editor and start with something like Python or Ruby to get some core coding foundation.
     
  7. Senor Cuete macrumors 6502

    Joined:
    Nov 9, 2011
    #8
    NO. Xcode has a built-in C/Objective C compiler.
    --- Post Merged, Apr 12, 2018 ---
    Personally I would use XCode because of the debugger, etc.
     
  8. D.T. macrumors G3

    D.T.

    Joined:
    Sep 15, 2011
    Location:
    Vilano Beach, FL
    #9
    Oh yeah, I was just trying to take a few steps back, frame things in the simplest way possible, I'm still not even sure of the goal :)
     
  9. Astralogic thread starter macrumors newbie

    Astralogic

    Joined:
    Apr 12, 2018
    #10
    Everything really, I searched a lot, and everything seems to require an OS higher then 10.8. (mono, visual studio code, etc).

    It's my low OS version that is causing the issues and I can't upgrade since I'm using a VM.

    If nothing comes of getting the C# version working, I guess this will have to be done.

    I'm learning to code, but not on a mac. This mac "port" is a one off thing, once done I will be in Windows elusively.

    Unfortunately, my OS version is too low.

    I just have a simple console C# program I'd like compiled on a mac. I'm not learning to code on a mac, but on Windows. This is a one off thing, once done, I will only be programming in Windows.

    I will return shortly with the code. It is two .cs files, the main program source code, and a file containing a class used in the program. The main file is less then 100 lines. The class is less then 200. I will zip them up and reply shortly.
     
  10. lloyddean, Apr 13, 2018
    Last edited: Apr 13, 2018

    lloyddean macrumors 6502a

    Joined:
    May 10, 2009
    Location:
    Des Moines, WA
    #11
  11. danius macrumors newbie

    danius

    Joined:
    Oct 13, 2016
    Location:
    Dublin, Ireland
    #12
    It will not run on mac unless it's targeting .net core and target machine will have it installed. You can compile it using visual studio for mac.
    if't it's only targeting full .net then you need VMWare fusion with windows and visual studio for windows. this application will not run on mac however.

    Daniel.
     
  12. lloyddean macrumors 6502a

    Joined:
    May 10, 2009
    Location:
    Des Moines, WA
    #13
    You get lost or is it something I said?

     
  13. Astralogic thread starter macrumors newbie

    Astralogic

    Joined:
    Apr 12, 2018
    #14
    I just tried this and the "Xcode developer tools" app requires a higher version of the OS. I couldn't see anything called "Xcode 5.1.1" nor any way to select a different version of "Xcode developer tools".

    I ran into an issue with my visual c# version, I couldn't figure out how to detect when enter was pressed and the msdn docs were giving me the wrong syntax, well, they weren't, I was looking at the wrong thing :/

    Here is the zip. Let me know if it looks doable.
     
  14. lloyddean, Apr 15, 2018
    Last edited: Apr 15, 2018

    lloyddean macrumors 6502a

    Joined:
    May 10, 2009
    Location:
    Des Moines, WA
    #15
    It's there, scroll thru the list looking for "Xcode 5.1.1" with a date of "Apr 9, 2014".

    This will get you a C, C++ and Objective C development environment allowing you to redevelop the utility in any of these languages as C# is NOT supported.

    But I get the impression you're more interested in the result than the process correct?

    If you have a Windows dev environment why the request for a Mac console version?
     
  15. Senor Cuete macrumors 6502

    Joined:
    Nov 9, 2011
    #16
    That is a link to a VERY questionable site that asks the user to download software. Forget it.
     
  16. lloyddean macrumors 6502a

    Joined:
    May 10, 2009
    Location:
    Des Moines, WA
    #17
    My concern as well but I downloaded and unzipped it anyway from the Power Mac G5.
    Very low chance of problems there now a days.
     
  17. padams35 macrumors regular

    Joined:
    Nov 10, 2016
    #18
    For a simple console application try installing Mono itself (not the full MonoDevelop IDE) and then compile & run in terminal.

    Alternatively rewrite your simple console program in Python. Python is useful language for console applications on both Mac and Windows anyway.
     
  18. NoBoMac macrumors 68000

    Joined:
    Jul 1, 2014
    #19
    More specifically, scroll down the first/main page to see the "More Downloads" link. Click that, then upper-left search box, enter "Xcode 5.1.1" to get you right to the download.
     
  19. lloyddean macrumors 6502a

    Joined:
    May 10, 2009
    Location:
    Des Moines, WA
    #20
    That is the link I posted above!
    --- Post Merged, Apr 15, 2018 ---

    That was mentioned in the link of the first response as well.
     
  20. lloyddean, Apr 16, 2018
    Last edited: Apr 16, 2018

    lloyddean macrumors 6502a

    Joined:
    May 10, 2009
    Location:
    Des Moines, WA
    #21
    Can you verify this -

    Code:
    Astralogic
    
            God Cipher:        355              Rev. God:        415               Masonic:        425          Rev. Masonic:        485
        Master Number:        205    Rev. Master Number:        265        Master Builder:        315    Rev. Master Number:        375
                Vortex:        151           Rev. Vortex:        239            Foundation:        535       Rev. Foundation:        595
          God Level 2:        605      Rev. God Level 2:        665           God Level 3:        855      Rev. God Level 3:        915
    
     
  21. Astralogic thread starter macrumors newbie

    Astralogic

    Joined:
    Apr 12, 2018
    #22
    Verified! :D

    Sorry, I lost all my browser tabs and forgot I made this thread.

    Did that run on a mac? Could you send me the mac "exe" file or whatever it is? Did you make any changes to the code to get it to work?
     
  22. lloyddean, Apr 17, 2018
    Last edited: Apr 17, 2018

    lloyddean macrumors 6502a

    Joined:
    May 10, 2009
    Location:
    Des Moines, WA
    #23
    I had no need for doing C# development myself, and chose instead to rewrite the utility based on your code in something I needed to get some familiararity with, so I rewrote it using Swift 4.1 as a simple command-line tool.

    Source code inlined, the zipped executable is attached. Swift is something I've no real experience with so those critical of the source make constructive not corrosive comments.

    EDIT: In case you're wondering why such a simple utility produces such a large executable it's because Swift packages in the Swift Standard Library in order to be executable on older systems such as yours.

    Be aware that this has NOT been tested on anything other than macOS 10.13.5


    Code:
    //
    //  main.swift
    //
    //  Astralogic
    // <https://forums.macrumors.com/threads/how-to-compile-c-on-a-mac.2114710/>
    
    import Foundation
    
    extension String {
        func encrypt(using: String) -> UInt32 {
    
            let tables: [String: [UInt8]] = [
                  "god":                  [  26,  27,  28,  29,  30,  31,  32,  33,  34,  35,  36,  37,  38
                                          ,  39,  40,  41,  42,  43,  44,  45,  46,  47,  48,  49,  50,  51]
                , "reverseGod":           [  51,  50,  49,  48,  47,  46,  45,  44,  43,  42,  41,  40,  39
                                          ,  38,  37,  36,  35,  34,  33,  32,  31,  30,  29,  28,  27,  26]
                , "masonic":              [  33,  34,  35,  36,  37,  38,  39,  40,  41,  42,  43,  44,  45
                                          ,  46,  47,  48,  49,  50,  51,  52,  53,  54,  55,  56,  57,  58]
                , "reverseMasonic":       [  58,  57,  56,  55,  54,  53,  52,  51,  50,  49,  48,  47,  46
                                          ,  45,  44,  43,  42,  41,  40,  39,  38,  37,  36,  35,  34,  33]
                , "masterNumber":         [  11,  12,  13,  14,  15,  16,  17,  18,  19,  20,  21,  22,  23
                                          ,  24,  25,  26,  27,  28,  29,  30,  31,  32,  33,  34,  35,  36]
                , "reverseMasterNumber":  [  36,  35,  34,  33,  32,  31,  30,  29,  28,  27,  26,  25,  24
                                          ,  23,  22,  21,  20,  19,  18,  17,  16,  15,  14,  13,  12,  11]
                , "masterBuilder":        [  22,  23,  24,  25,  26,  27,  28,  29,  30,  31,  32,  33,  34
                                          ,  35,  36,  37,  38,  39,  40,  41,  42,  43,  44,  45,  46,  47]
                , "reverseMasterBuilder": [  47,  46,  45,  44,  43,  42,  41,  40,  39,  38,  37,  36,  35
                                          ,  34,  33,  32,  31,  30,  29,  28,  27,  26,  25,  24,  23,  22]
                , "vortex":               [   1,   2,   4,   5,   7,   8,  10,  11,  13,  14,  16,  17,  19
                                          ,  20,  22,  23,  25,  26,  28,  29,  31,  32,  34,  35,  37,  38]
                , "reverseVortex":        [  38,  37,  35,  34,  32,  31,  29,  28,  26,  25,  23,  22,  20
                                          ,  19,  17,  16,  14,  13,  11,  10,   8,   7,   5,   4,   2,   1]
                , "foundation":           [  44,  45,  46,  47,  48,  49,  50,  51,  52,  53,  54,  55,  56
                                          ,  57,  58,  59,  60,  61,  62,  63,  64,  65,  66,  67,  68,  69]
                , "reverseFoundation":    [  69,  68,  67,  66,  65,  64,  63,  62,  61,  60,  59,  58,  57
                                          ,  56,  55,  54,  53,  52,  51,  50,  49,  48,  47,  46,  45,  44]
                , "god2ndLevel":          [  51,  52,  53,  54,  55,  56,  57,  58,  59,  60,  61,  62,  63
                                          ,  64,  65,  66,  67,  68,  69,  70,  71,  72,  73,  74,  75,  76]
                , "reverseGod2ndLevel":   [  76,  75,  74,  73,  72,  71,  70,  69,  68,  67,  66,  65,  64
                                          ,  63,  62,  61,  60,  59,  58,  57,  56,  55,  54,  53,  52,  51]
                , "god3rdLevel":          [  76,  77,  78,  79,  80,  81,  82,  83,  84,  85,  86,  87,  88
                                          ,  89,  90,  91,  92,  93,  94,  95,  96,  97,  98,  99, 100, 101]
                , "reverseGod3rdLevel":   [ 101, 100,  99,  98,  97,  96,  95,  94,  93,  92,  91,  90,  89
                                          ,  88,  87,  86,  85,  84,  83,  82,  81,  80,  79,  78,  77,  76]
            ]
    
            let message = self.trimmingCharacters(in: .whitespacesAndNewlines).lowercased().utf8
            let table   = tables[using]
    
            var value: UInt32 = 0
            for element in message {
                let index   = element.hashValue - String("a").utf8.first!.hashValue
                value      += UInt32(table![index])
            }
    
            return value
        }
    
        public var isAlphabetic: Bool {
            guard !isEmpty else { return false }
    
            let characterSet = CharacterSet(charactersIn: "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
            guard nil == rangeOfCharacter(from: characterSet.inverted) else {
                return false
            }
            return true
        }
    }
    
    let encryptors = [
          ("        God Cipher:", "god"                 ) //  0
        , ("          Rev. God:", "reverseGod"          ) //  1
        , ("           Masonic:", "masonic"             ) //  2
        , ("      Rev. Masonic:", "reverseMasonic"      ) //  3
        , ("     Master Number:", "masterNumber"        ) //  4
        , ("Rev. Master Number:", "reverseMasterNumber" ) //  5
        , ("    Master Builder:", "masterBuilder"       ) //  6
        , ("Rev. Master Number:", "reverseMasterBuilder") //  7
        , ("            Vortex:", "vortex"              ) //  8
        , ("       Rev. Vortex:", "reverseVortex"       ) //  9
        , ("        Foundation:", "foundation"          ) // 10
        , ("   Rev. Foundation:", "reverseFoundation"   ) // 11
        , ("       God Level 2:", "god2ndLevel"         ) // 12
        , ("  Rev. God Level 2:", "reverseGod2ndLevel"  ) // 13
        , ("       God Level 3:", "god3rdLevel"         ) // 14
        , ("  Rev. God Level 3:", "reverseGod3rdLevel"  ) // 15
    ]
    
    let width  = String(UInt32.max).count
    while ( true ) {
        let line = readLine(strippingNewline: true)
        if let line = line {
            if !line.isAlphabetic {
                print("Invalid characters, must use a-zA-Z only!")
                continue
            }
    
            for (index, encryptor) in encryptors.enumerated() {
                let encrypted   = line.encrypt(using: encryptor.1)
                let lead        = (index % 4) == 0 ? "\n" : "    "
                let formatting  = lead + "%@%\(width)d"
                print(String(format: formatting, encryptor.0, encrypted), separator: "", terminator: "")
            }
    
            print("")
        }
    }
    
    
     

    Attached Files:

  23. D.T. macrumors G3

    D.T.

    Joined:
    Sep 15, 2011
    Location:
    Vilano Beach, FL
    #24
    Hahaha, outstanding. :D
     
  24. Astralogic thread starter macrumors newbie

    Astralogic

    Joined:
    Apr 12, 2018
    #25
    You're the man Lloyd, thank you.

    The program itself doesn't work in this old OS which is absolutely fine. I'm not asking for help to get it working on this old OS in any way. I'd just like to know if the error that was displayed looks normal, i.e. is this error confirmation that the program doesn't work just because the OS is old?

    Also are there any software requirements needed to run a swift program? I just want to make sure that something unexpected or unusual hasn't happened.

    image_334.png
     

Share This Page