Search code examples
c#xcodecocoaprogram-entry-pointvisual-studio-mac

Struggling to get started in Visual Studio and Xcode - "undefined symbol _main"


I am a beginner when it comes to coding, and I have been struggling with a very annoying problem this entire day. I hope you can help me relieve this awful headache.

My idea is to create a very simple app for my Mac, so I downloaded Visual Studio and Xcode. I followed this tutorial from Youtube to get started, but halfway in the film I see that I am not able to get the same "outputs" as this Youtuber gets ( https://youtu.be/rj_n4W_mDN0?t=340 ). In my case it doesn't automatically provide "NSTextField*LabelInfo", but I can attach the button and label to the script and make them show when I run Visual Studio. I am not provided this autofill either ( https://youtu.be/rj_n4W_mDN0?t=420 ) or the option of calling the "HelloPressed" function in Visual Studio.

Then I discovered that I have an error message in Xcode when I try to build it: "undefined symbol _main" (which the Youtube person doesn't have).

It also reads:

"Undefined symbols for architecture x86_64:

"_main", referenced from: implicit entry/start for main executable

ld: symbol(s) not found for architecture x86_64

clang: error: linker command failed with exit code 1 (use -v to see invocation)"

I deleted my code and restarted the program, but the same message popped up. I deleted both Xcode and Visual Studio, and reinstalled it, but it still came up. This time I didn't add or do anything other than opening a new projects (in Cocoa app), and still I was greeted with this annoyance. I see that my "Main.cs" in Visual Studio is not appearing in Xcode project (all the other ones are), but I don't know if this is relevant. I have tried to add different Frameworks to Xcode (AppKit), but I still receive this message. Maybe there is something I have to do in the Build section of Visual Studio, but I don't know what.

I have absolutely no clue what to do and how to proceed. I find it so strange and annoying that the Xcode gives me an Error without me doing anything else then starting up the program. My Macbook pro is very new so that cannot be the cause, the softwares are newly updated: Xcode 11.5 and Visual Studio 8.6.5 (build 23). I am programming in C sharp

I hope you are able to advice me in what to do. I am a beginner so I would appreciate easy-to-follow assistance or instructions.

Thank you very much,

August


Solution

  • Sorry I can't offer a definitive answer but hopefully the following will help you find your issue. I don't usually use VS for Mac and installed it just to see if I could figure out your issues. It is not as intuitive as one may like...

    • Visual Studio for Mac on both Mojave & Catalina does not work appear to work as the video you found seems to show.
    • Double-clicking on a .storyboard file generally seems to open the file in VS's XML editor rather than in Xcode. There might be a setting to control this somewhere. To open in Xcode right-click (or control-click) the file name and select Open With… -> Xcode Interface Builder in the menu that appears. – Once over in Xcode you may find you have two open windows, one is just the .storyboard file and the other is a dummy Xcode project containing it. Close the first of these and just edit within the Xcode project window. If you don't do this you cannot create bindings between the controls and the source. If you look at the Xcode windows in the video you found you will see that when the bindings are being made it is in the project window, but there is nothing to show how/why that window opened up at the front.
    • Do not try to compile the "project" in Xcode. It is not meant to be compiled and appears to just be the bare minimum scaffolding required to enable VS to use Xcode for UI editing. All the errors you got are related to this.

    Searching the internet for Visual Studio for Mac and storyboard files turns up plenty of hits and these files failing to open correctly seems a common problem from a scan of the titles. Do some research and you'll probably get it to work smoothly, but it does work as is albeit a little fiddly. HTH