I've gotten fed up with MSVC++6 and how everyone is always telling me that it's a crappy compiler and such.
So now I've decided to try to use vim plus g++ and makefiles. Here's my problem; I have the following makefile:
# This is supposed to be a comment..
CC = g++
# The line above sets the compiler in use..
# The next line sets the compilation flags
CFLAGS=-c -Wall
all: main.exe
main.exe: main.o Accel.o
$(CC) -o main.exe main.o Accel.o
main.o: main.cpp Accel.h
$(CC) $(CFLAGS) main.cpp
Accel.o: Accel.cpp Accel.h
$(CC) $(CFLAGS) Accel.cpp
clean:
del main.exe *.o
This gives an error when trying to make
, because I need to link to a windows library called Ws2_32.lib
, which is needed by Winsock2.h
, which I include
in one of my .h
files.
So how do I do this? I've tried the -l
option, but I can't make it work. How does it work with a path that has spaces?
Before running a Makefile in Windows, it is required to install the make command first by using the “Mingw-get install mingw32-make” command on the Command Prompt. Then, create a Makefile, remove the “. txt” extension, and use the “make” command to run the specified Makefile in Windows.
make was first developed in 1976, and yet it's still widely used, predominantly in application development where you need to compile binaries. While makefiles are quite uncommon in Web development in general, at SSENSE we have found an unconventional use-case for it.
The make command itself does not search for libraries or header files - instead it looks for a Makefile in the current directory (unless an alternative file is specified on the command line using the -f option) and executes the instructions inside.
First step: locate the library you are looking for. For me, it's in :
C:\Program Files\Microsoft Visual Studio\VC98\Lib
Second step, pass that directory with -L :
LINKFLAGS=-L"C:\Program Files\Microsoft Visual Studio\VC98\Lib"
Third step, pass the name of the library with -l (lowercase L):
LINKFLAGS=-L"C:\Program Files\Microsoft Visual Studio\VC98\Lib" -lWs2_32
Then use it:
main.exe: main.o Accel.o
$(CC) $(LINKFLAGS) -o main.exe main.o Accel.o
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With