adobe-flash / crossbridge

Welcome to visit the homepage!
http://www.crossbridge.io
542 stars 194 forks source link

Use crossbridge to compile client.c to swc but failed because of a link error #66

Open hgj100 opened 7 years ago

hgj100 commented 7 years ago

client.c is a test code. This file contains socket API for example socket, connect, send, why only 'connect' result in link error?

source code client.c :

include <netinet/in.h>

include <sys/types.h>

include <sys/socket.h>

include

include

include

include <arpa/inet.h>

include

int test(int argc, char **argv) { int client_socket, port; struct sockaddr_in serv_addr; if(argc != 3) { printf("useage:socket_client ipaddress port"); return -1; }

port = atoi(argv[2]);
if(-1 == (client_socket = socket(AF_INET,SOCK_STREAM,0)) )
{
    perror("error in create socket\n");
    exit(0);
}
bzero(&serv_addr,sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
serv_addr.sin_port = htons(port);
serv_addr.sin_addr.s_addr = inet_addr(argv[1]);

if(-1 == connect(client_socket,(struct sockaddr*)&serv_addr,sizeof(struct sockaddr)))
{
    perror("connect error\n");
    exit(0);
}

send(client_socket,"hello world",strlen("hello world"),0);

close(client_socket);

}

source code main.c :

include "AS3/AS3.h"

int main() { AS3_GoAsync(); }

when compile, $ make -------- Sample 5 --------

Now compile a SWC and demo SWF "/cygdrive/c/Crossbridge/sdk/usr/bin/g++" -Werror -Wno-write-strings -Wno-trigraphs -O4 main.cpp client.c -emit-swc=sample.test -o test.swc /tmp/cclj1lfj.o: error: undefined reference to '_connect' collect2: ld returned 1 exit status Makefile:2: recipe for target `T05' failed make: *** [T05] Error 1

If crossbridge sdk have some problem?

mbolt35 commented 7 years ago

Since the AS3/Flash Player support for sockets doesn't map easily to posix sockets, it wasn't implemented in crossbridge. You can use AS3 sockets and pass data back and forth via inline_as3(). In other words, you can use sockets in your C++ app, but you'd need to write your own implementation.

Hope this helps!