Continuous Xcode Error

Can anyone else explain as to why I would always receive the error of "Entry point (_main) undefined. for architecture arm64" when I ran the build?


import Foundation


import CoreLocation




func getLocation(from address: String, completion: @escaping (Result<(latitude: Double, longitude: Double), Error>) -> Void) {


    let geocoder = CLGeocoder()


    geocoder.geocodeAddressString(address) { placemarks, error in


        guard let placemark = placemarks?.first, error == nil else {


            completion(.failure(error ?? NSError(domain: "getLocation", code: 0, userInfo: nil)))


            return


        }


        let locationCoords = (placemark.location?.coordinate.latitude ?? 0, placemark.location?.coordinate.longitude ?? 0)


        completion(.success(locationCoords))


    }


}




func getNearbyServices(latitude: Double, longitude: Double, serviceType: String, completion: @escaping (Result<[String], Error>) -> Void) {


    let url = "https://api.openstreetmap.org/api/0.6/\(serviceType).json?lat=\(latitude)&***=\(longitude)"


    let request = URLRequest(url: URL(string: url)!)


    URLSession.shared.dataTask(with: request) { data, response, error in


        guard let data = data, error == nil else {


            completion(.failure(error ?? NSError(domain: "getNearbyServices", code: 0, userInfo: nil)))


            return


        }


        do {


            let json = try JSONSerialization.jsonObject(with: data, options: [])


            if let jsonDictionary = json as? [String: Any], let elements = jsonDictionary["elements"] as? [[String: Any]] {


                var serviceNames: [String] = []


                for element in elements {


                    if let name = element["tags"] as? [String: String], let serviceName = name["name"], let phoneNumber = name["phone"] {


                        serviceNames.append("\(serviceName) (\(phoneNumber))")


                    }


                }


                completion(.success(serviceNames))


            }


        } catch {


            completion(.failure(error))


        }


    }.resume()


}




func teachAboutStrokes() {


    // ...


    print("Let's locate nearby emergency services.")


    if let address = readLine() {


        getLocation(from: address) { result in


            switch result {


            case .success(let location):


                let serviceType = "amenity=emergency"


                getNearbyServices(latitude: location.latitude, longitude: location.longitude, serviceType: serviceType) { result in


                    switch result {


                    case .success(let services):


                        print("Here are the nearby emergency services:")


                        for service in services {


                            print("- \(service)")


                        }


                    case .failure(let error):


                        print("Error getting nearby services: \(error.localizedDescription)")


                    }


                }


            case .failure(let error):


                print("Error getting location: \(error.localizedDescription)")


            }


        }


    }


}


func main() {


    teachAboutStrokes()


}

MacBook Air Apple Silicon

Posted on Mar 5, 2023 3:39 PM

Reply
Question marked as Top-ranking reply

Posted on Mar 7, 2023 8:18 AM

So what might be the best recommendation towards trying to get this to run correctly? I do see now where using ChatGPT might've created the code incorrectly, but is there any possibility of salvaging this or would it be better to just start from scratch?

My only issue is, I'm very beginner when it comes to creating Xcode/Swift, so I'm not entirely sure still on what would need to be entered in to get things rolling.

14 replies
Question marked as Top-ranking reply

Mar 7, 2023 8:18 AM in response to MrHoffman

So what might be the best recommendation towards trying to get this to run correctly? I do see now where using ChatGPT might've created the code incorrectly, but is there any possibility of salvaging this or would it be better to just start from scratch?

My only issue is, I'm very beginner when it comes to creating Xcode/Swift, so I'm not entirely sure still on what would need to be entered in to get things rolling.

Mar 6, 2023 9:14 AM in response to IbsinRG

IbsinRG wrote:

I even checked the error with ChatGPT as well, and it had responded with the following:

OMG


Stop with AI garbage. Create a new project using the Xcode template for whatever you want to build. Build the template. Then add your own code. If there already is a main function, don't replace it. If there isn't a main, don't add one.

Mar 6, 2023 9:08 AM in response to MrHoffman

I even checked the error with ChatGPT as well, and it had responded with the following:


This error message typically occurs when there is a problem with linking your project's object files and libraries during the build process.

Specifically, the error message is indicating that there is an issue with the architecture of the main executable for the "Locator2" scheme on arm64 (a 64-bit processor architecture commonly used in Apple devices). The linker is unable to find the "_main" symbol, which is the entry point for the main executable of your application.

This can happen for a few different reasons, such as missing or outdated dependencies, incorrect build settings, or issues with the code itself. You can use the -v flag to get more verbose output from the linker, which can sometimes provide additional information about the specific cause of the error.

To fix this error, you may need to review your project's build settings, ensure that all required dependencies are included and up-to-date, and check your code for any syntax or logical errors that may be causing the issue.


However, I checked the build architecture in the build settings, and it is arm64 by default and doesn't give any other options to change it.

Mar 6, 2023 9:51 AM in response to IbsinRG

Again, what you have posted here works correctly here, so we’re chasing some issue in your system.


Build the app from the command line.


The following is an example of the Swift code, here starting with the source code in a file named test12.swift, built at the command line, as well as also showing the command output, and showing the local configuration information:



Issue the same commands (the commands are the text after the $, and don’t include the $, and don’t include the command output) and post that here.


The posted Swift code also doesn’t do anything useful when run here, but that’s another discussion.


ChatGPT is overhyped hot garbage, all too capable of generating mixtures of both plausible and correct text and complete and utter fiction, with truth and fiction and misinterpretations interspersed freely, and all presented with equal veneer of correctness and certainty.

Mar 5, 2023 5:17 PM in response to IbsinRG

Building this as a macOS command-line app in Swift using Xcode 14.2 on Monterey 12.6.3 on Intel builds the code without errors, using Xcode defaults.


Could you provide a little more detail on your development configuration, project type, etc.?


The code reposted, using format tags, and reformatted using SwiftFormat for Xcode (defaults)...


import CoreLocation
import Foundation
func getLocation(from address: String, completion: @escaping (Result<(latitude: Double, longitude: Double), Error>) -> Void) {
    let geocoder = CLGeocoder()
    geocoder.geocodeAddressString(address) { placemarks, error in
        guard let placemark = placemarks?.first, error == nil else {
            completion(.failure(error ?? NSError(domain: "getLocation", code: 0, userInfo: nil)))
            return
        }
        let locationCoords = (placemark.location?.coordinate.latitude ?? 0, placemark.location?.coordinate.longitude ?? 0)
        completion(.success(locationCoords))
    }
}

func getNearbyServices(latitude: Double, longitude: Double, serviceType: String, completion: @escaping (Result<[String], Error>) -> Void) {
    let url = "https://api.openstreetmap.org/api/0.6/\(serviceType).json?lat=\(latitude)&***=\(longitude)"
    let request = URLRequest(url: URL(string: url)!)
    URLSession.shared.dataTask(with: request) { data, _, error in
        guard let data = data, error == nil else {
            completion(.failure(error ?? NSError(domain: "getNearbyServices", code: 0, userInfo: nil)))
            return
        }
        do {
            let json = try JSONSerialization.jsonObject(with: data, options: [])
            if let jsonDictionary = json as? [String: Any], let elements = jsonDictionary["elements"] as? [[String: Any]] {
                var serviceNames: [String] = []
                for element in elements {
                    if let name = element["tags"] as? [String: String], let serviceName = name["name"], let phoneNumber = name["phone"] {
                        serviceNames.append("\(serviceName) (\(phoneNumber))")
                    }
                }
                completion(.success(serviceNames))
            }
        } catch {
            completion(.failure(error))
        }
    }.resume()
}

func teachAboutStrokes() {
    // ...
    print("Let's locate nearby emergency services.")
    if let address = readLine() {
        getLocation(from: address) { result in
            
            switch result {
            case .success(let location):
                
                let serviceType = "amenity=emergency"
                
                getNearbyServices(latitude: location.latitude, longitude: location.longitude, serviceType: serviceType) { result in
                    
                    switch result {
                    case .success(let services):
                        
                        print("Here are the nearby emergency services:")
                        
                        for service in services {
                            print("- \(service)")
                        }
                        
                    case .failure(let error):
                        
                        print("Error getting nearby services: \(error.localizedDescription)")
                    }
                }
                
            case .failure(let error):
                
                print("Error getting location: \(error.localizedDescription)")
            }
        }
    }
}

func main() {
    teachAboutStrokes()
}


Mar 5, 2023 7:29 PM in response to MrHoffman

That actually really helps, I appreciate it. However, now I have a different error this time after inputting that. I didn't realize it was written in macOS format, I had assumed it was done as iOS.


The error I'm seeing now, however, is:


linker command failed with exit code 1 (use -v to see invocation)




----------------------------------------




SchemeBuildError: Failed to build the scheme "StrokeLocator"




linker command failed with exit code 1 (use -v to see invocation)




Link StrokeLocator (arm64):


ld: entry point (_main) undefined. for architecture arm64


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


Could this be due to because it was formatted as macOS?

Mar 6, 2023 9:04 AM in response to MrHoffman

So I tried that just now, created a new project as a macOS app, inputted the code, and got the following error report.


linker command failed with exit code 1 (use -v to see invocation)




----------------------------------------




SchemeBuildError: Failed to build the scheme "Locator2"




linker command failed with exit code 1 (use -v to see invocation)




Link Locator2 (arm64):


Undefined symbols for architecture arm64:


  "_main", referenced from:


     implicit entry/start for main executable


ld: symbol(s) not found for architecture arm64


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

Mar 7, 2023 8:44 AM in response to IbsinRG

IbsinRG wrote:

I do see now where using ChatGPT might've created the code incorrectly, but is there any possibility of salvaging this or would it be better to just start from scratch?

Straight answer requested - was this code generated by ChatGPT?

I'm very beginner when it comes to creating Xcode/Swift, so I'm not entirely sure still on what would need to be entered in to get things rolling.

Start with your name, on the application form for a local college or university. There are no shortcuts. The first thing you need to learn is that the internet is a source of lies, not information, just lies.

Mar 7, 2023 12:50 PM in response to IbsinRG

IbsinRG wrote:

At the start, it was generated from ChatGPT as Python, then regenerated/translated into Swift.
And as much as I’d prefer a proper education in Swift or coding, I don’t have funds for that currently.
I’m just trying to create an app from a few ideas my fiancé had.


You can get free Swift training from various sources, including Apple, Stanford University, and other sources.


Harvard has an intro Python course online and free, too.


You’ll get a free lesson from ChatGPT too, but not the working-code kind.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Continuous Xcode Error

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.