Reputation: 17
#pragma once
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#ifdef __linux__
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <unistd.h>
#define WSACleanup()
#define closeConnection(fd) ::close(fd)
#elif _WIN32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#include <stdlib.h>
#include <stdio.h>
WORD versionWanted = MAKEWORD(1, 1);
WSADATA wsaData;
WSAStartup (versionWanted, &wsaData);
#define closeConnection(fd) closesocket(fd);
#endif
#include <openssl/ssl.h>
using namespace std;
...
compiling with this command:
x86_64-w64-mingw32-g++ main.cpp -I include -o main.exe -lssl -lcrypto -lws2_32 -static
Compile error: error: expected constructor, destructor, or type conversion before ‘(’ token WSAStartup (versionWanted, &wsaData);
Host: Kubuntu 18.04 LTS
Q_1: Why its giving me this error?
Q_2: Should I use comment... for linking when using mingw64 (or just when on msvc)?
Upvotes: 0
Views: 478
Reputation: 36389
Other than initialisations and declarations, all code must be inside a function or method. You need to put the following code inside of a function:
WORD versionWanted = MAKEWORD(1, 1);
WSADATA wsaData;
WSAStartup (versionWanted, &wsaData);
Upvotes: 1