undefined reference to怎么解决的?
"undefined reference to"怎么解决的?
有下面几个文件:
tiwei@tiwei-desktop:~/graph$ ls
binet.cpp global.cpp graph.cpp group.cpp main_1.cpp node_graph.cpp partition.cpp support.cpp
binet.hpp global.hpp graph.hpp group.hpp Makefile node_graph.hpp partition.hpp support.hpp
tiwei@tiwei-desktop:~/graph$
其中:
graph.cpp和partition.cpp引用了global.cpp中定义的GetNodeDict()函数,在
graph.cpp和partition.cpp中都使用了#include "global.hpp".
下面是我的Makefile文件:(我是改写别人的Makefile文件)
CC = g++
CFLAGS = -g
INCLUDE = -I. -I/usr/include/ -I/usr/include/X11/ -I/usr/local/inclucde
LDFLAGS = -L. -L/usr/lib -L/usr/lib/X11 -L/usr/local/lib
LDLIBS = -L. -lprng -L/usr/lib -lm
SRCS = \
global.cpp graph.cpp group.cpp node_graph.cpp partition.cpp support.cpp \
main_1.cpp
OBJS = \
global.o graph.o group.o node_graph.o partition.o support.o main_1.o
.c.o:
$(CC) $(DEFS) $(INCLUDE) $(CFLAGS) -c $<
all:main
main:$(OBJS)
$(CC) $(CFLAGS) $(INCLUDE) $(OBJS) $(LDFLAGS) $(LDLIBS) -o $@
clean:
rm -f *.o core main
我在网上看了,别人的undefined reference to是用系统的库函数,在-L后加上 -lm就可以了,
或是简单的,
请各位帮我看看Makefile文件怎么写的?我猜可能是Makefile文件的问题。
谢谢了各位!
下面是连接时的错误:
tiwei@tiwei-desktop:~/graph$ sudo make -f Makefile
g++ -c -o global.o global.cpp
g++ -c -o graph.o graph.cpp
g++ -c -o group.o group.cpp
g++ -c -o node_graph.o node_graph.cpp
g++ -c -o partition.o partition.cpp
g++ -c -o support.o support.cpp
g++ -c -o main_1.o main_1.cpp
g++ -g -I. -I/usr/include/ -I/usr/include/X11/ -I/usr/local/inclucde global.o graph.o group.o node_graph.o partition.o support.o main_1.o -L. -L/usr/lib -L/usr/lib/X11 -L/usr/local/lib -L. -lprng -L/usr/lib -lm -o main
graph.o: In function `graph::RewireAdjacencyByLabel()':graph.cpp:(.text+0xe74): undefined reference to `GetNodeDict(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, void*)'
graph.o: In function `graph::ClearAdjacencies()':graph.cpp:(.text+0x1df2): undefined reference to `GetNodeDict(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, void*)'
partition.o: In function `partition::MapPartToNet(graph*)':partition.cpp:(.text+0x232f): undefined reference to `GetNodeDict(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, void*)'
partition.o: In function `partition::partition(graph*, double, double, double, double, int, char, int, char, prng*)':partition.cpp:(.text+0x3da9): undefined reference to `GetNodeDict(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, void*)'
partition.o: In function `partition::partition(graph*, double, double, double, double, int, char, int, char, prng*)':partition.cpp:(.text+0x58c3): undefined reference to `GetNodeDict(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, void*)'
collect2: ld returned 1 exit status
make: *** [main] Error 1
tiwei@tiwei-desktop:~/graph$