Mac How to compile C# on a mac?

Astralogic

macrumors newbie
Original poster
Apr 12, 2018
15
2
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.
 
Last edited:

Senor Cuete

macrumors 6502
Nov 9, 2011
303
12
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
[doublepost=1523553460][/doublepost]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.
 

Astralogic

macrumors newbie
Original poster
Apr 12, 2018
15
2
But if I wrote it in C, how would I compile it? Wouldn't I have the same problem?
 

lloyddean

macrumors 65816
May 10, 2009
1,002
16
Des Moines, WA
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.

Post the code here and we'll see what comes of it.
 

D.T.

macrumors G4
Sep 15, 2011
10,861
11,277
Vilano Beach, FL
But if I wrote it in C, how would I compile it? Wouldn't I have the same problem?
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.
 

Senor Cuete

macrumors 6502
Nov 9, 2011
303
12
But if I wrote it in C, how would I compile it? Wouldn't I have the same problem?
NO. Xcode has a built-in C/Objective C compiler.
[doublepost=1523569236][/doublepost]
...you can knock out a simple program in C and compile it in terminal using GCC (which might not be installed)...
Personally I would use XCode because of the debugger, etc.
 

Astralogic

macrumors newbie
Original poster
Apr 12, 2018
15
2
List those solutions so people don't reply with them and waste your time.
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.

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).
If nothing comes of getting the C# version working, I guess this will have to be done.

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.
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.

NO. Xcode has a built-in C/Objective C compiler.
[doublepost=1523569236][/doublepost]

Personally I would use XCode because of the debugger, etc.
Unfortunately, my OS version is too low.

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 :)
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.

Post the code here and we'll see what comes of it.
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.
 

danius

macrumors newbie
Oct 13, 2016
3
0
Dublin, Ireland
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.
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.
 

lloyddean

macrumors 65816
May 10, 2009
1,002
16
Des Moines, WA
You get lost or is it something I said?

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.
 

Astralogic

macrumors newbie
Original poster
Apr 12, 2018
15
2
You could always get a free Apple developer account and download Xcode 5.1.1 that works on your version of Mac OS.

<https://developer.apple.com/download/more/>
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".

You get lost or is it something I said?
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.
 

lloyddean

macrumors 65816
May 10, 2009
1,002
16
Des Moines, WA
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.
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?
 
Last edited:

padams35

macrumors 6502
Nov 10, 2016
269
145
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.
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.
 
  • Like
Reactions: pier and MC6800

NoBoMac

Moderator
Staff member
Jul 1, 2014
2,887
1,216
It's there, scroll thru the list looking for "Xcode 5.1.1" with a date of "Apr 9, 2014".
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.
 

lloyddean

macrumors 65816
May 10, 2009
1,002
16
Des Moines, WA
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.
That is the link I posted above!
[doublepost=1523843988][/doublepost]
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.

That was mentioned in the link of the first response as well.
 

lloyddean

macrumors 65816
May 10, 2009
1,002
16
Des Moines, WA
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.
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
 
Last edited:

Astralogic

macrumors newbie
Original poster
Apr 12, 2018
15
2
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?
 

lloyddean

macrumors 65816
May 10, 2009
1,002
16
Des Moines, WA
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("")
    }
}
 

Attachments

Last edited:

Astralogic

macrumors newbie
Original poster
Apr 12, 2018
15
2
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
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
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.