Προς το περιεχόμενο

Γιατί δεν μπορώ να linkαρω το applink.c όταν κάνω crossbuild σε linux windows app 32bit?


PC_MAGAS

Προτεινόμενες αναρτήσεις

Προσπαθώ να συνδέσω την βιβλιοθήκη που έκτησα  σε linux Μέσω Mingw-32 comiler:

sudo apt-get install gcc-mingw-w64-x86-64 g++-mingw-w64-x86-64 wine64
sudo apt-get install g++-mingw-w64-i686 g++-mingw-w64-i686
wget https://www.openssl.org/source/openssl-1.1.1q.tar.gz
tar -xvf openssl-1.1.1q.tar.gz
cd ./openssl-1.1.1q
./Configure enable-tls1_3 no-asm no-async no-dso no-engine no-shared --cross-compile-prefix=i686-w64-mingw32- --prefix=/usr/bin/i686-w64-mingw32-gcc mingw
make -j16

Σε μια εφαρμογή που xρησιμοποιεί winsock (αρχείο main.c):
 

#define _WINSOCK_DEPRECATED_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS

#include <winsock2.h>
#include <ws2tcpip.h>
#include <stdio.h>

#include <openssl/ssl.h>
#include <openssl/err.h>
#include <openssl/applink.c>

// Need to link with Ws2_32.lib, Mswsock.lib, and Advapi32.lib
#pragma comment (lib, "Ws2_32.lib")
//#pragma comment (lib, "Mswsock.lib")
//#pragma comment (lib, "AdvApi32.lib")


#define DEFAULT_BUFLEN 512
#define FAIL    -1

#define WIN32_LEAN_AND_MEAN

SOCKET OpenConnection(char* hostname, int port)
{
    WSADATA wsaData;
    SOCKET ConnectSocket = INVALID_SOCKET;
    struct addrinfo* result = NULL;
    struct addrinfo* ptr = NULL;
    struct addrinfo hints;
    char recvbuf[DEFAULT_BUFLEN];
    int iResult;
    int recvbuflen = DEFAULT_BUFLEN;

    // Initialize Winsock
    iResult = WSAStartup(MAKEWORD(2, 2), &wsaData);
    if (iResult != 0) {
        printf("WSAStartup failed with error: %d\n", iResult);
        return 1;
    }

    ZeroMemory(&hints, sizeof(hints));
    hints.ai_family = AF_UNSPEC;
    hints.ai_socktype = SOCK_STREAM;
    hints.ai_protocol = IPPROTO_TCP;

    // Resolve the server address and port
    iResult = getaddrinfo("google.com", "449", &hints, &result);
    if (iResult != 0) {
        printf("getaddrinfo failed with error: %d\n", iResult);
        WSACleanup();
        return 1;
    }
    ptr = result;
    // Create a SOCKET for connecting to server
    ConnectSocket = socket(ptr->ai_family, ptr->ai_socktype, ptr->ai_protocol);
    if (ConnectSocket == INVALID_SOCKET) {
        printf("socket failed with error: %ld\n", WSAGetLastError());
        WSACleanup();
        return 1;
    }

    // Connect to server.
    iResult = connect(ConnectSocket, ptr->ai_addr, (int)ptr->ai_addrlen);
    if (iResult == SOCKET_ERROR) {
        closesocket(ConnectSocket);
        ConnectSocket = INVALID_SOCKET;
    }
    return ConnectSocket;
}


SSL_CTX* InitCTX(void)
{
    OpenSSL_add_all_algorithms();  /* Load cryptos, et.al. */
    SSL_load_error_strings();   /* Bring in and register error messages */
    const SSL_METHOD* method = TLSv1_2_client_method();  /* Create new client-method instance */
    SSL_CTX* ctx = SSL_CTX_new(method);   /* Create new context */
    if (ctx == NULL)
    {
        ERR_print_errors_fp(stderr);
        abort();
    }
    return ctx;
}


void ShowCerts(SSL* ssl)
{
    X509* cert;
    char* line;
    cert = SSL_get_peer_certificate(ssl); /* get the server's certificate */
    if (cert != NULL)
    {
        printf("Server certificates:\n");
        line = X509_NAME_oneline(X509_get_subject_name(cert), 0, 0);
        printf("Subject: %s\n", line);
        //free(line);       /* free the malloc'ed string */
        line = X509_NAME_oneline(X509_get_issuer_name(cert), 0, 0);
        printf("Issuer: %s\n", line);
        //free(line);       /* free the malloc'ed string */
        X509_free(cert);     /* free the malloc'ed certificate copy */
    }
    else
        printf("Info: No client certificates configured.\n");
}

με την εντολή:

LANG=C i686-w64-mingw32-gcc main.c -lws2_32 -Iopenssl-1.1.1q/include -o main.exe


Αλλά αδυνατώ να συνδέσω το αρχείο openssl/applink.c. Εχετε καμια ιδέα πως θα το Linkάρω;

main.cpp:10:10: fatal error: openssl/applink.c: No such file or directory
 #include <openssl/applink.c>
          ^~~~~~~~~~~~~~~~~~~
compilation terminated.

 

Συνδέστε για να σχολιάσετε
Κοινοποίηση σε άλλες σελίδες

Υπάρχει όντως το αρχείο στον φάκελο που θα έπρεπε να βρίσκεται;

Από Google search:

openssl/applink.c is required for OpenSSL to work on Windows, when compiled by MSVC (Miscrosoft Visual Studio Compiler). It is included in the Windows version of OpenSSL from 1.1.0 and above, but is excluded on OpenSSL for Mac, Linux or MinGW

Συνδέστε για να σχολιάσετε
Κοινοποίηση σε άλλες σελίδες

I the end απλά ήθελε να κάνω:

make install

Μετά έπρεπε εκτελέσω τα παρακάτω: https://stackoverflow.com/a/72984554/4706711

Η Openssl 1.1.0.g απλά ορίζει μυστήρια διαδρομή για linux όταν κάνεις `make install`.

6 ώρες πριν, n3a είπε

Υπάρχει όντως το αρχείο στον φάκελο που θα έπρεπε να βρίσκεται;

Από Google search:

openssl/applink.c is required for OpenSSL to work on Windows, when compiled by MSVC (Miscrosoft Visual Studio Compiler). It is included in the Windows version of OpenSSL from 1.1.0 and above, but is excluded on OpenSSL for Mac, Linux or MinGW

Indeed δεν χρειάζετε επειδή κάνω build με mingw.

Συνδέστε για να σχολιάσετε
Κοινοποίηση σε άλλες σελίδες

Δημιουργήστε ένα λογαριασμό ή συνδεθείτε για να σχολιάσετε

Πρέπει να είστε μέλος για να αφήσετε σχόλιο

Δημιουργία λογαριασμού

Εγγραφείτε με νέο λογαριασμό στην κοινότητα μας. Είναι πανεύκολο!

Δημιουργία νέου λογαριασμού

Σύνδεση

Έχετε ήδη λογαριασμό; Συνδεθείτε εδώ.

Συνδεθείτε τώρα
  • Δημιουργία νέου...