如何包含自编译库中的标头? [英] How to include header from self compiled library?

查看:86
本文介绍了如何包含自编译库中的标头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,所以我已经编写了一个写在库中的简单记录器,以便可以将其包含在其他项目中.但是,当我尝试包括该记录器的标题时,它将无法编译.

Okay, so I've compiled a simple logger I wrote into a library so I can include it with other projects. But when I try to include the header for that logger, it fails compilation.

这是我的Makefile链接库:

Here is my Makefile linking the library:

CC= clang++
PROG= ./bin/tetris
OBJS= ./src/main.o ./src/Tetris.o ./src/states/BaseState.o ./src/states/MenuState.o \
    ./src/states/GameState.o
LIBS= allegro-5.0 allegro_dialog-5.0 allegro_font-5.0 allegro_ttf-5.0 allegro_color-5.0
CXXFLAGS= -g -Wall -std=c++11
LDFLAGS= $(shell pkg-config --static --libs ${LIBS}) -I./src/util -L./src/util/ -lsimplog

all: $(PROG)

$(PROG): $(OBJS)
    mkdir -p ./bin/
    $(CC) -o $(PROG) $(CXXFLAGS) $(OBJS) $(LDFLAGS)
    rm -f $(OBJS)

clean:
    rm -f $(PROG) $(TEST_PROG) $(OBJS)

该库为 libsimplog.a ,位于该项目的 src 目录中.我将其编译在一个单独的项目文件夹中,然后在此处复制.simplog.h/simplog.c仅存在于我最初编译该库的项目文件夹中.据我了解,我的编译标志中的 -L ./src/-lsimplog 应该链接了这个库.但是,我的 #include"simplog.h" 在编译时仍然失败:

The library is libsimplog.a and is located in the src directory of this project. I'm compiling it in a separate project folder, then copying here. simplog.h/simplog.c only exist in the project folder where I'm initially compiling this library. From what I understand, -L ./src/ -lsimplog in my compile flags should be linking this library. However, my #include "simplog.h" is still failing upon compilation:

fatal error: simplog.h: No such file or directory

我正在将该库与该项目分开地在其自己的项目文件夹中进行编译.simplog.h/simplog.c存在于该项目中,而不是该项目中.编译该库的另一个项目的makefile如下:

I'm compiling the library in its own project folder, separate from this project. simplog.h/simplog.c exist in that project, not this one. The makefile for the other project that compiles this library is as follows:

CC = clang
CFLAGS = -Wall -c
LIB = libsimplog.a
SOURCE = simplog.c
OBJ = simplog.o

all:
    $(CC) $(CFLAGS) $(SOURCE)
    ar -cvq $(LIB) $(OBJ)

clean:
    rm -f $(LIB)

推荐答案

-L"指定链接器路径.

您需要告诉预处理器,还有一个包含-I./src/的包含目录.

You need to tell the pre-processor that there is another include directory with -I./src/.

CXXFLAGS= -g -Wall -std=c++11 -I./src/ -L./src/ -lsimplog $(shell pkg-config --cflags ${LIBS})

这篇关于如何包含自编译库中的标头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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