Makefile - 逻辑网络的模拟

时间:2014-12-07 16:38:15

标签: c++ networking makefile g++

我必须编写模拟逻辑门网络的程序,但我的makefile不起作用。请帮忙。

主文件是Program2.cpp。 它需要使用TextMenu.h和Lognet.h头文件。

TextMenu.h需要使用Algebra.h。

Lognet需要Algebra.h(相同)和Gate.h. Gate.h包含Gate类的定义和该类的两个对象的声明 - TRUE_GATE和FALSE_GATE。

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

为什么这个makefile不起作用? 提前致谢。

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

,它就可以很容易地编译
g++ Program2.cpp -o Program2 $(PARAMS).

我的makefile:

#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

1 个答案:

答案 0 :(得分:0)

您正在多个文件中定义TRUE_GATEFALSE_GATE,因此当您将它们链接在一起时,您会收到警告。

split(std::string, char)的相同故事。

并且您没有链接到正在使用的增强库。

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