Cant compile any source code

Programming related discussions related to game research
tongbal
Posts: 7
Joined: Sat Apr 22, 2017 10:40 am

Cant compile any source code

Post by tongbal »

No matter what source code I use from https://aluigi.altervista.org/ , I always get mass errors. Im a beginner at programming and it seems no matter what IDE I use it gives me mass errors.
For example : https://aluigi.altervista.org/fakep/tcpfp.zip

Contains two files : winerr.h and tcpfp.c

Now I tried Visual Studio Code, started a new project and now this:

Code: Select all

c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\Dennis\AppData\Local\Temp\ccwJzarD.o:tcpfp.c:(.text+0x7): undefined reference to `WSAGetLastError@0'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\Dennis\AppData\Local\Temp\ccwJzarD.o:tcpfp.c:(.text+0x5ae): undefined reference to `WSAStartup@8'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\Dennis\AppData\Local\Temp\ccwJzarD.o:tcpfp.c:(.text+0x921): undefined reference to `htons@4'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\Dennis\AppData\Local\Temp\ccwJzarD.o:tcpfp.c:(.text+0x946): undefined reference to `ntohs@4'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\Dennis\AppData\Local\Temp\ccwJzarD.o:tcpfp.c:(.text+0x95a): undefined reference to `inet_ntoa@4'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\Dennis\AppData\Local\Temp\ccwJzarD.o:tcpfp.c:(.text+0x9c1): undefined reference to `socket@12'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\Dennis\AppData\Local\Temp\ccwJzarD.o:tcpfp.c:(.text+0x9ef): undefined reference to `connect@12'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\Dennis\AppData\Local\Temp\ccwJzarD.o:tcpfp.c:(.text+0xa06): undefined reference to `closesocket@4'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\Dennis\AppData\Local\Temp\ccwJzarD.o:tcpfp.c:(.text+0xc16): undefined reference to `__WSAFDIsSet@8'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\Dennis\AppData\Local\Temp\ccwJzarD.o:tcpfp.c:(.text+0xd23): undefined reference to `select@20'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\Dennis\AppData\Local\Temp\ccwJzarD.o:tcpfp.c:(.text+0xde8): undefined reference to `__WSAFDIsSet@8'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\Dennis\AppData\Local\Temp\ccwJzarD.o:tcpfp.c:(.text+0xe1c): undefined reference to `recv@16'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\Dennis\AppData\Local\Temp\ccwJzarD.o:tcpfp.c:(.text+0xfde): undefined reference to `socket@12'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\Dennis\AppData\Local\Temp\ccwJzarD.o:tcpfp.c:(.text+0x1049): undefined reference to `setsockopt@20'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\Dennis\AppData\Local\Temp\ccwJzarD.o:tcpfp.c:(.text+0x1077): undefined reference to `setsockopt@20'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\Dennis\AppData\Local\Temp\ccwJzarD.o:tcpfp.c:(.text+0x10a5): undefined reference to `setsockopt@20'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\Dennis\AppData\Local\Temp\ccwJzarD.o:tcpfp.c:(.text+0x10c5): undefined reference to `connect@12'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\Dennis\AppData\Local\Temp\ccwJzarD.o:tcpfp.c:(.text+0x10ff): undefined reference to `closesocket@4'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\Dennis\AppData\Local\Temp\ccwJzarD.o:tcpfp.c:(.text+0x1161): undefined reference to `send@16'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\Dennis\AppData\Local\Temp\ccwJzarD.o:tcpfp.c:(.text+0x119c): undefined reference to `closesocket@4'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\Dennis\AppData\Local\Temp\ccwJzarD.o:tcpfp.c:(.text+0x12c3): undefined reference to `closesocket@4'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\Dennis\AppData\Local\Temp\ccwJzarD.o:tcpfp.c:(.text+0x1432): undefined reference to `inet_addr@4'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\Dennis\AppData\Local\Temp\ccwJzarD.o:tcpfp.c:(.text+0x1449): undefined reference to `gethostbyname@4'


Suddenly I have to configure some weird tasks.json launch.json files, Internet description is a horror, tried many things and still wont work.

So ok next IDE. JetBrains CLion. Configured the path of Mingw. Now I start a new project with the files in the dir and now I cant even compile it because it says "CMake project is not loaded". What the hell.
When I look at your text at https://aluigi.altervista.org/about.htm it doesnt mention what IDE you use? And "I use ever and only Gcc and its Win32 port Mingw to compile my C stuff." So how do you do it? What if you have 10 or more files?

I cant even copy paste code and compile it please help
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: Cant compile any source code

Post by aluigi »

They aren't errors :)
"undefined reference" means that you must link the executable with the necessary libraries.
Add the following at the end of your gcc command-line and it will work:
-lws2_32

Example:
gcc -o file.exe file.c -s -O2 -lws2_32
tongbal
Posts: 7
Joined: Sat Apr 22, 2017 10:40 am

Re: Cant compile any source code

Post by tongbal »

Thanks for the answer. I tried everything and this worked. I seem to get less errors in general from simple -gcc -o test test.cpp line than the big IDEs. Really weird, I expect theses big programs to make it easier not harder.
How do you use that command line if you are using like 20 files? Does this simple line work too?
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: Cant compile any source code

Post by aluigi »

gcc -o file.exe *.c -s -O2 -lws2_32

:D
tongbal
Posts: 7
Joined: Sat Apr 22, 2017 10:40 am

Re: Cant compile any source code

Post by tongbal »

Is there a reason you prefer this over an IDE?

Edit: Also, there are a lot of things in Reverse Engineering (like Memory stuff) which wont work with gcc compiler and you need Microsoft visual 2017. I just tested it.
Gcc/clang gives error, VS doesnt.
I just uploaded a random .zip file which I get from some game hacking site which contains a project with 3 main files (2x cpp and 1 header) and you will not be able to compile it with your way. What do you do?
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: Cant compile any source code

Post by aluigi »

I'm not used to work with IDE on gcc projects, that's why I go directly with the command-line.

If you prefer the "command-line way" with VS projects, you can.
Usually you have just to run "C:\Program Files (x86)\Microsoft Visual Studio XX.0\VC\vcvarsall.bat" which will set the environment and then call cl.exe with the necessary arguments.

I didn't check what's missing with the project you uploaded since I have limited time and it's not my code.
tongbal
Posts: 7
Joined: Sat Apr 22, 2017 10:40 am

Re: Cant compile any source code

Post by tongbal »

thanks for answer