如何包含自编译库中的标头
How to include header from self compiled 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"
在编译时仍然失败:
fatal error: simplog.h: No such file or directory
我正在自己的项目文件夹中编译库,与此项目分开。simplog.h/simplog.c 存在于该项目中,而不是这个项目。编译此库的其他项目的生成文件如下所示:
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/的包含目录。
CXXFLAGS= -g -Wall -std=c++11 -I./src/ -L./src/ -lsimplog $(shell pkg-config --cflags ${LIBS})
您是否尝试过包含 I 标志以包含头文件?例如:
-I/usr/include/
来自 g++ 的手册页
-I dir Add the directory dir to the list of directories to
be searched for header files. Directories named by -I are searched
before the standard system include directories.
If the directory dir is a standard system include directory,
the option is ignored to ensure that the default search order for
system directories and the special treatment of system headers are no
defeated .If dir begins with "=", then the "=" will be replaced by the
sysroot prefix; see --sysroot and -isysroot.
相关文章:
- 编译包含字符串的代码时遇到问题
- 函数何时会在c++中包含stack_Unwind_Resume调用
- g++编译包含的头:没有这样的文件或目录
- 包含模板文件的递归会导致编译失败
- 即使不包含其标头,如何成功向前声明的类编译?
- 为什么更改包含 psapi.h 的顺序会产生编译错误?(标识符 BOOL 未定义)
- 如何确定integer_sequence在编译时是否包含给定的数字?
- 编译包含指向模板函数的指针的初始值设定项列表时,gcc 出错,但 clang 不出错
- BGL:当包含 random_spanning_tree.hpp 时,对strong_components的调用无法编译
- 为什么我需要包含<compare>标头才能编译 <=>?
- 包含来自 boost 1.73.0 的read_graphviz_new.cpp无法编译
- 为什么具有静态存储持续时间的同一内联变量在包含在 VS2017 编译的两个翻译单元中时会构造和销毁两次
- 编译时条件包含.分段标头与包括整个实现
- 当包含成员函数名为errno和cerrno时,g++7编译错误
- 编译包含LLVM API标头的C++文件时出错
- 包含 cmath 标头时出现 cmake 编译错误
- 在我的 CLR 项目中添加包含会导致无法在启用 /clr 的情况下编译 WLR
- 为什么包含任意 STL 标头可以解决这些编译错误?
- GCC - 包含编译标志的宏
- 为什么许多编译语言不包含编译时反射?