I want to make my own header file that has functions that I can call when trying to make a tcp connection, I have three files main.cpp,sock.hpp,sock.cpp
main.cpp contains
#include <stdio.h>
#include <stdlib.h>
#include "sock.hpp"
int main()
{
create_sock("0.0.0.0","1337");
return 0;
}
sock.hpp has
#ifndef SOCKS_H
#define SOCKS_H
#endif
int create_sock(const char * host , const char * port);
sock.cpp has
#include <stdio.h>
#include <stdlib.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#include <string.h>
int create_sock( const char * host , const char * port)
{
INT WSAAPI iResult;
return 0;
}
when compiling using the command g++ main.cpp sock.cpp -lws2_32 this results in the following error
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\msys64\tmp\cc1epM1h.o:main.cpp:(.text+0x31): undefined reference to `create_sock(char*, char*)'
collect2.exe: error: ld returned 1 exit status