-2

i type socket example with xcode in mac:

//
//  main.c
//  testsocket
//
//  Created by YiranWang on 17/11/2016.
//  Copyright © 2016 YiranWang. All rights reserved.
//

//#include "unp.h"
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <stdio.h>
#define SERV_PORT 9987
#define SA struct sockaddr
#define LISTENQ 1024

int main(int argc, const char * argv[]) {
    struct sockaddr_in cliaddr,servaddr;
    pid_t childpid;
    int listenfd,connfd;
    socklen_t clien;
    listenfd = socket(AF_INET, SOCK_STREAM, 0);
    bzero(&servaddr, sizeof(servaddr));
    servaddr.sin_family = AF_INET;
    servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
    servaddr.sin_port = htons(SERV_PORT);
    bind(listenfd, (SA *)&servaddr, sizeof(servaddr));
    listen(listenfd, LISTENQ);
    for (; ; ) {
        clien = sizeof(cliaddr);
        connfd = accept(listenfd, (SA *)&cliaddr, &clien);
        if ((childpid = fork()) == 0) {
            close(listenfd);
            str_echo(connfd);
            exit(0);
        }
        close(connfd);
    }
}

when i build, it errorenter image description here

王奕然
  • 3,891
  • 6
  • 41
  • 62
  • Text...please.... – Sourav Ghosh Nov 28 '16 at 07:11
  • Well the code you show calls `str_echo`. Where is that function defined (implemented)? – Some programmer dude Nov 28 '16 at 07:13
  • 1
    Forgot to link with the required library? Also, it looks like `unp.h` is actually needed. – Sourav Ghosh Nov 28 '16 at 07:15
  • I'm voting to close this question because _This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting._ – Sourav Ghosh Nov 28 '16 at 07:16
  • Possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Danh Nov 28 '16 at 07:23

1 Answers1

0

i try some ways DerivedData and change the "Architectures" for your project target
Xcode build failure "Undefined symbols for architecture x86_64" but not work.

finally i found some function are not reference, so i add the function definition it work. @Sourav Ghosh thanks your suggestion.

Community
  • 1
  • 1
王奕然
  • 3,891
  • 6
  • 41
  • 62