crossbridge-community / crossbridge

C/C++ Compiler for the ActionScript Virtual Machine (AVM2)
http://sourceforge.net/projects/crossbridge-community/
Other
151 stars 35 forks source link

undefined reference to '_connect' #66

Closed RSeroka closed 9 years ago

RSeroka commented 9 years ago

In plain cygwin, I can create a simple .c program to create a tcp client socket and connect to remote tcp socket. In crossbridge, this fails with a link error /tmp/ccqLouBl.o: error: undefined reference to '_connect'

I can't use inline AS3 to access a socket because I wish to use the socket in OpenSSL which requires a file descriptor.

rseroka@R-SEROKA /cygdrive/c/users/rseroka/My Documents/TestProjects/openssl/crossbridge/sample $ uname -a CYGWIN_NT-6.1-WOW64 R-SEROKA 1.7.32(0.274/5/3) 2014-08-13 23:03 i686 Cygwin

rseroka@R-SEROKA /cygdrive/c/users/rseroka/My Documents/TestProjects/openssl/crossbridge/sample $ gcc --version gcc (GCC) 4.8.3 Copyright (C) 2013 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

rseroka@R-SEROKA /cygdrive/c/users/rseroka/My Documents/TestProjects/openssl/crossbridge/sample $ gcc -o clientSocket clientSocket.c

rseroka@R-SEROKA /cygdrive/c/users/rseroka/My Documents/TestProjects/openssl/crossbridge/sample $ clientSocket How about getting a socket! fd=3

rseroka@R-SEROKA /cygdrive/c/users/rseroka/My Documents/TestProjects/openssl/crossbridge/sample $ bash

rseroka@R-SEROKA /cygdrive/c/users/rseroka/My Documents/TestProjects/openssl/crossbridge/sample $ PATH=/cygdrive/c/Program\ Files/Java/jdk1.7.0_03/bin:/cygdrive/c/Applications/Crossbridge/15.0.0.3/sdk/usr/bin:$PATH

rseroka@R-SEROKA /cygdrive/c/users/rseroka/My Documents/TestProjects/openssl/crossbridge/sample $ gcc --version gcc (GCC) 4.2.1 for Adobe AVM2 (Based on Apple Inc. build 5658) (LLVM build) Copyright (C) 2007 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

rseroka@R-SEROKA /cygdrive/c/users/rseroka/My Documents/TestProjects/openssl/crossbridge/sample $ uname -a FreeBSD localhost.localdomain 8.2-RELEASE FreeBSD 8.2-RELEASE (compatible; Adobe Flascc 2.0) AVM2

rseroka@R-SEROKA /cygdrive/c/users/rseroka/My Documents/TestProjects/openssl/crossbridge/sample $ gcc -o clientSocket clientSocket.c /tmp/ccqLouBl.o: error: undefined reference to '_connect' java.io.FileNotFoundException: C:\cygwin\tmp\swfresolve.in.b8tzV8 (The system cannot find the path specified) at java.io.FileInputStream.open(Native Method) at java.io.FileInputStream.(FileInputStream.java:138) at flascc.AlcTool.swfresolve(AlcTool.java:414) at flascc.AlcTool.main(AlcTool.java:59) collect2: ld returned 1 exit status

rseroka@R-SEROKA /cygdrive/c/users/rseroka/My Documents/TestProjects/openssl/crossbridge/sample $ cat clientSocket.c


#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <netdb.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>

int tcpConnect (const char* hostName, int port)
{
        int error, handle;
        struct hostent *host;
        struct sockaddr_in server;

        host = gethostbyname (hostName);
        handle = socket (AF_INET, SOCK_STREAM, 0);
        if (handle == -1)
        {
                printf("Failed to create TCP/IP Socket\n");
        }
        else
        {
                server.sin_family = AF_INET;
                server.sin_port = htons (port);
                server.sin_addr = *((struct in_addr *) host->h_addr);
                bzero (&(server.sin_zero), 8);

                error = connect (handle, (struct sockaddr *) &server,
                                   sizeof (struct sockaddr));
                if (error == -1)
                {
                        printf("Failed to connect to TCP/IP Socket\n");
                        handle = -1;
                }

        }

        return handle;
}

int main()
{
    printf("How about getting a socket!\n");
    int fd = tcpConnect("MC3-RSEROKA", 80);
    printf("fd=%d\n", fd);
}
vpmedia commented 9 years ago

Hi, The simpliest solution is to add an empty connect method in your program, like here: https://github.com/crossbridge-community/crossbridge-swc-openssl/blob/master/clientlib.c (line 98) The proper solution would be to implement Sockets using inline AS3.

vpmedia commented 9 years ago

OpenSSL code is translated into ActionScript ByteCode so you have to use AS3 API, because the SWF runs inside the Flash Player, so no native APIs are present.

vpmedia commented 9 years ago

Closing this one. It's not possible to use the socket in OpenSSL because everything is translated to actionscript/bytecode.