Makefile在Windows上与g ++,链接库 [英] Makefiles on windows with g++, linking a library

查看:726
本文介绍了Makefile在Windows上与g ++,链接库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经厌倦了MSVC ++ 6,以及每个人都总是告诉我这是一个糟糕的编译器等。

I've gotten fed up with MSVC++6 and how everyone is always telling me that it's a crappy compiler and such.

现在我决定尝试使用vim加g ++和makefile。这是我的问题;我有以下makefile:

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

当尝试 make 时会出现错误,因为我需要链接到一个名为 Ws2_32.lib .h 之一中包含 code>文件。

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.

那么我该如何做呢?我尝试了 -l <​​/ code>选项,但我不能使它的工作。

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?

推荐答案

第一步:找到您要寻找的库。对我来说,它在:

First step: locate the library you are looking for. For me, it's in :

C:\Program Files\Microsoft Visual Studio\VC98\Lib

第二步,传递该目录到-L:

Second step, pass that directory with -L :

LINKFLAGS=-L"C:\Program Files\Microsoft Visual Studio\VC98\Lib"

第三步,使用-l(小写L)传递库的名称:

Third step, pass the name of the library with -l (lowercase L):

LINKFLAGS=-L"C:\Program Files\Microsoft Visual Studio\VC98\Lib" -lWs2_32

然后使用它:

main.exe: main.o Accel.o
   $(CC) $(LINKFLAGS) -o main.exe main.o Accel.o

这篇关于Makefile在Windows上与g ++,链接库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆