c++ - 将 config.cpp 中定义的函数链接到我的头文件 allvariables.hpp 有什么问题?
问题描述
obj/main_exec.o: In function `std::ctype<char>::do_widen(char) const':
/home/aj/Documents/02_AJ_Research/13_Striker/ext/SimuFlow_1.0/src/configmod.cpp:7: multiple definition of `ty_conf::setconf_fromfile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*, int*, int*)'
obj/configmod.o:/home/aj/Documents/02_AJ_Research/13_Striker/ext/SimuFlow_1.0/src/configmod.cpp:7: first defined here
有一个带有类的头文件,并且存在一个函数的公共声明:编译时该config.o
文件表示该函数已在config.cpp
. 为什么这会导致链接器错误?
信息
ty_Conf
是在头文件中定义的一个类:里面的所有内容都是公开的,包括函数声明:函数setconf_fromfile(...);
的定义在configmod.cpp
寻求任何帮助
以下是我的 Makefile 命令:
**# object list
HOBJ = $(OBJ_DIR)/allvariables.o\
OBJS = $(OBJ_DIR)/linker.o\
$(OBJ_DIR)/configmod.o\
EXEC = $(OBJ_DIR)/flus_exec.o
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.hpp
$(CPP) -c $< -o $@ $(FFLAGS) $(IFLAGS) #$(CFLAGS)
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp
$(CPP) -c $< -o $@ $(FFLAGS) $(IFLAGS) #$(CFLAGS)
.PHONY: all build externals clean distclean
all: externals build
build: $(HOBJ) $(OBJS) $(EXEC)
$(CPP) -o $(BIN_DIR)/$(EXE) $(OBJS) $(EXEC) $(FFLAGS) $(LFLAGS)**
解决方案
推荐阅读
- java - 获取两个映射类之间的json格式数据
- javascript - 没有ID时用JS将项目添加到html列表
- r - 按列名从 xts 中选择
- flask - 带有动态文件名的 Flask Url_for
- asp.net-core-2.0 - 必须声明表变量“@p0”
- c# - 没有父属性的二叉搜索树迭代器c#
- python - cv2.waitKey(25) & 0xFF == ord('q'): 和 cv2.imwrite() 不工作
- jquery - 如何在 django 视图中反序列化来自 jquery/ajax 的数据
- apache-spark - 纱线模式下的火花历史服务器
- git - Git:直接在工作目录中进行的更改(链接到裸存储库)