C++ Makefile—逻辑网络的模拟

C++ Makefile—逻辑网络的模拟,c++,networking,makefile,g++,C++,Networking,Makefile,G++,我必须编写模拟逻辑门网络的程序,但我的makefile无法工作。请帮忙 主文件是Program2.cpp。 它需要使用text menu.h和Lognet.h标题 文本菜单。h需要工作代数。h Lognet需要代数.h(相同)和Gate.h。 h包含Gate类的定义和该类的两个对象的声明-TRUE_Gate和FALSE_Gate 当然,每个.h文件都有自己的.cpp文件 为什么这个makefile不工作? 提前谢谢 另外,我的代码通常是有效的,因为如果我在适当的.h文件末尾包含每个.cpp文件并

我必须编写模拟逻辑门网络的程序,但我的makefile无法工作。请帮忙

主文件是Program2.cpp。 它需要使用text menu.h和Lognet.h标题

文本菜单。h需要工作代数。h

Lognet需要代数.h(相同)和Gate.h。 h包含Gate类的定义和该类的两个对象的声明-TRUE_Gate和FALSE_Gate

当然,每个.h文件都有自己的.cpp文件

为什么这个makefile不工作? 提前谢谢

另外,我的代码通常是有效的,因为如果我在适当的.h文件末尾包含每个.cpp文件并仅调用

g++ Program2.cpp -o Program2 $(PARAMS).
我的生成文件:

#PROGRAM 2 - LOGICAL NETWORK

#compiler name
CC = g++

#C++ version
STD = -std=c++11

#headers to include
INCLS = -I /home/mion/s/73/abrodzki/boost_1_57_0

#libs to use
LIBS = -lncurses

#other compilation options
OPT = -Wall -pedantic -g

#params
PARAMS = $(STD) $(OPT) $(INCLS) $(LIBS)


all: Algebra.o TextMenu.o Gate.o Lognet.o Program2.o
    $(CC) Algebra.o TextMenu.o Gate.o Lognet.o Program2.o -o program2 $(PARAMS)

Program2.o: Program2.cpp
    $(CC) Program2.cpp -o Program2.o -c $(PARAMS)

TextMenu.o: TextMenu.cpp TextMenu.h
    $(CC) TextMenu.cpp -o TextMenu.o -c $(PARAMS)

Lognet.o: Lognet.cpp Lognet.h
    $(CC) Lognet.cpp -o LogNet.o -c $(PARAMS)

Gate.o: Gate.h Gate.cpp
    $(CC) Gate.cpp -o Gate.o -c $(PARAMS)

Algebra.o: Algebra.cpp Algebra.h
    $(CC) Algebra.cpp -o Algebra.o -c $(PARAMS)
错误:

g++ TextMenu.cpp -o TextMenu.o -c -std=c++11 -Wall -pedantic -g -I /home/mion/s/73/abrodzki/boost_1_57_0 -lncurses
g++ Lognet.cpp -o LogNet.o -c -std=c++11 -Wall -pedantic -g -I /home/mion/s/73/abrodzki/boost_1_57_0 -lncurses
g++ Algebra.o TextMenu.o Gate.o Lognet.o Program2.o -o program2 -std=c++11 -Wall -pedantic -g -I /home/mion/s/73/abrodzki/boost_1_57_0 -lncurses
Lognet.o:(.bss+0x0): multiple definition of `TRUE_GATE'
Gate.o:/home/mion/s/73/abrodzki/Gate.cpp:11: first defined here
Lognet.o:(.bss+0x10): multiple definition of `FALSE_GATE'
Gate.o:/home/mion/s/73/abrodzki/Gate.cpp:11: first defined here
Lognet.o: In function `split(std::string, char)':
Lognet.cpp:(.text+0x0): multiple definition of `split(std::string, char)'
Algebra.o:/home/mion/s/73/abrodzki/Algebra.cpp:77: first defined here
Lognet.o: In function `split2D(std::string, char, char)':
Lognet.cpp:(.text+0x1e6): multiple definition of `split2D(std::string, char, char)'
Algebra.o:/home/mion/s/73/abrodzki/Algebra.cpp:103: first defined here
Program2.o: In function `loadNetwork()':
/opt/gcc-4.7.2/lib/gcc/x86_64-unknown-linux-gnu/4.7.2/../../../../include/c++/4.7.2/new:112: multiple definition of `TRUE_GATE'
Gate.o:/home/mion/s/73/abrodzki/Gate.cpp:11: first defined here
Program2.o: In function `loadNetwork()':
/opt/gcc-4.7.2/lib/gcc/x86_64-unknown-linux-gnu/4.7.2/../../../../include/c++/4.7.2/stdexcept:101: multiple definition of `FALSE_GATE'
Gate.o:/home/mion/s/73/abrodzki/Gate.cpp:11: first defined here
Lognet.o: In function `lognetDescriptionIsValid(std::string)':
Lognet.cpp:(.text+0x552): undefined reference to `boost::numeric::ublas::vector<std::string, boost::numeric::ublas::unbounded_array<std::string, std::allocator<std::string> > > getColumn<std::string>(boost::numeric::ublas::matrix<std::string, boost::numeric::ublas::basic_row_major<unsigned long, long>, boost::numeric::ublas::unbounded_array<std::string, std::allocator<std::string> > >, int)'
Lognet.cpp:(.text+0x598): undefined reference to `boost::numeric::ublas::vector<std::string, boost::numeric::ublas::unbounded_array<std::string, std::allocator<std::string> > > getColumn<std::string>(boost::numeric::ublas::matrix<std::string, boost::numeric::ublas::basic_row_major<unsigned long, long>, boost::numeric::ublas::unbounded_array<std::string, std::allocator<std::string> > >, int)'
Lognet.cpp:(.text+0x5de): undefined reference to `boost::numeric::ublas::vector<std::string, boost::numeric::ublas::unbounded_array<std::string, std::allocator<std::string> > > getColumn<std::string>(boost::numeric::ublas::matrix<std::string, boost::numeric::ublas::basic_row_major<unsigned long, long>, boost::numeric::ublas::unbounded_array<std::string, std::allocator<std::string> > >, int)'
Lognet.cpp:(.text+0x624): undefined reference to `boost::numeric::ublas::vector<std::string, boost::numeric::ublas::unbounded_array<std::string, std::allocator<std::string> > > getColumn<std::string>(boost::numeric::ublas::matrix<std::string, boost::numeric::ublas::basic_row_major<unsigned long, long>, boost::numeric::ublas::unbounded_array<std::string, std::allocator<std::string> > >, int)'
Lognet.o: In function `LogNet::LogNet(LoadMod, std::string, std::string)':
Lognet.cpp:(.text+0x1127): undefined reference to `boost::numeric::ublas::vector<std::string, boost::numeric::ublas::unbounded_array<std::string, std::allocator<std::string> > > getColumn<std::string>(boost::numeric::ublas::matrix<std::string, boost::numeric::ublas::basic_row_major<unsigned long, long>, boost::numeric::ublas::unbounded_array<std::string, std::allocator<std::string> > >, int)'
Lognet.o:Lognet.cpp:(.text+0x119d): more undefined references to `boost::numeric::ublas::vector<std::string, boost::numeric::ublas::unbounded_array<std::string, std::allocator<std::string> > > getColumn<std::string>(boost::numeric::ublas::matrix<std::string, boost::numeric::ublas::basic_row_major<unsigned long, long>, boost::numeric::ublas::unbounded_array<std::string, std::allocator<std::string> > >, int)' follow
collect2: error: ld returned 1 exit status
make: *** [all] Error 1
g++TextMenu.cpp-o TextMenu.o-c-std=c++11-Wall-pedantic-g-I/home/mion/s/73/abrodzki/boost\u 1\u 57\u 0-lncurses
g++Lognet.cpp-o Lognet.o-c-std=c++11-Wall-pedantic-g-I/home/mion/s/73/abrodzki/boost_1_57_0-lncurses
g++Algebra.o TextMenu.o Gate.o Lognet.o Program2.o-o Program2-std=c++11-Wall-pedantic-g-I/home/mion/s/73/abrodzki/boost\u 1\u 57\u 0-lncurses
Lognet.o:(.bss+0x0):“真门”的多个定义
Gate.o:/home/mion/s/73/abrodzki/Gate.cpp:11:首先在这里定义
Lognet.o:(.bss+0x10):“假门”的多个定义
Gate.o:/home/mion/s/73/abrodzki/Gate.cpp:11:首先在这里定义
Lognet.o:在函数“split(std::string,char)”中:
Lognet.cpp:(.text+0x0):'split(std::string,char)的多个定义
Algebra.o:/home/mion/s/73/abrodzki/Algebra.cpp:77:首先在这里定义
Lognet.o:在函数“split2D(std::string,char,char)”中:
Lognet.cpp:(.text+0x1e6):'split2D(std::string,char,char)的多个定义
Algebra.o:/home/mion/s/73/abrodzki/Algebra.cpp:103:首先在这里定义
Program2.o:在函数“loadNetwork()”中:
/opt/gcc-4.7.2/lib/gcc/x86_64-unknown-linux-gnu/4.7.2/../../../../../../../../include/c++/4.7.2/new:112:“真门”的多重定义
Gate.o:/home/mion/s/73/abrodzki/Gate.cpp:11:首先在这里定义
Program2.o:在函数“loadNetwork()”中:
/opt/gcc-4.7.2/lib/gcc/x86_64-unknown-linux-gnu/4.7.2/../../../../../../../../include/c++/4.7.2/stdexcept:101:“假门”的多重定义
Gate.o:/home/mion/s/73/abrodzki/Gate.cpp:11:首先在这里定义
Lognet.o:在函数“lognetDescriptionIsValid(std::string)”中:
Lognet.cpp:(.text+0x552):对“boost::numeric::ublas::vector getColumn(boost::numeric::ublas::matrix,int)”的未定义引用
Lognet.cpp:(.text+0x598):对“boost::numeric::ublas::vector getColumn(boost::numeric::ublas::matrix,int)”的未定义引用
Lognet.cpp:(.text+0x5de):对“boost::numeric::ublas::vector getColumn(boost::numeric::ublas::matrix,int)”的未定义引用
Lognet.cpp:(.text+0x624):对“boost::numeric::ublas::vector getColumn(boost::numeric::ublas::matrix,int)”的未定义引用
Lognet.o:在函数“Lognet::Lognet(LoadMod,std::string,std::string)”中:
Lognet.cpp:(.text+0x1127):对“boost::numeric::ublas::vector getColumn(boost::numeric::ublas::matrix,int)”的未定义引用
Lognet.o:Lognet.cpp:(.text+0x119d):下面是对“boost::numeric::ublas::vector getColumn(boost::numeric::ublas::matrix,int)”的更多未定义引用
collect2:错误:ld返回了1个退出状态
make:**[all]错误1

您在多个文件中定义了
TRUE\u-GATE
FALSE\u-GATE
,因此当您将它们链接在一起时,会收到警告

拆分(std::string,char)
的情况也一样

并且您没有链接到正在使用的boost库


您需要在链接阶段添加适当的
-l
标志。

如果您认为makefile已损坏,请尝试不使用它。我不能尝试不使用makefile,因为这是我的讲师要求的。我的意思是尝试不使用makefile,以查看您的假设是否正确。我相信你的讲师不会介意你想一想,试着找出一个问题。问题是,当我在.h文件的末尾包含.cpp文件时,程序会工作吗?是的,我试过了,然后一切都正常了。但是makefile确实是非常需要的,我不知道你所说的“在.h文件末尾包含.cpp文件”是什么意思;这对我来说没有意义。但是,上面的错误是链接器错误而不是make错误,这意味着代码中有错误,而不是makefile中有错误。如果在shell提示符下手动一次运行一个相同的命令,您将看到相同的错误。由于您没有提供有关代码的太多信息,因此我们无法提供太多帮助,但“多个定义”通常意味着您正在将定义放入头文件中,而这些定义本应仅存在于.cpp文件中。