首页 > 解决方案 > 将 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)**

标签: c++makefile

解决方案


推荐阅读