我使用的是DevC ++ 5.11,我有一个包含5个文件的项目:
mainDistances.cpp
distances.cpp
distances.h
matrix.cpp
matrix.h
我收到这些错误:
enterabs
几乎所有东西看起来都是未定义的。它不会读取其他文件。
cancel
这些文件各有近200行,所以我不打算把这篇文章变得很大,但请告诉我你是否需要其他一些代码部分。
distances.h
[Error] ld returned 1 exit status
mainDistances.cpp: undefined reference to `Matrix<float>::operator=(Matrix<float> const&)'
mainDistances.cpp:(.text+0xb5f): undefined reference to `Matrix<float>::rows()'
[...]\distances.o distances.cpp:(.rdata$_ZTV6MatrixIiE[_ZTV6MatrixIiE]+0x18): undefined reference to `Matrix<int>::readMatrix(std::string const&)'
AND MORE
distaces.cpp
# Project: mainDistances
# Makefile created by Dev-C++ 5.11
CPP = g++.exe
CC = gcc.exe
WINDRES = windres.exe
OBJ = distances.o mainDistances.o matrix.o
LINKOBJ = distances.o mainDistances.o matrix.o
LIBS = -L"C:/Program Files (x86)/Dev-Cpp/MinGW64/lib" -L"C:/Program Files (x86)/Dev-Cpp/MinGW64/x86_64-w64-mingw32/lib" -static-libgcc
INCS = -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/include" -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/x86_64-w64-mingw32/include" -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include"
CXXINCS = -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/include" -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/x86_64-w64-mingw32/include" -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include" -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++"
BIN = mainDistances.exe
CXXFLAGS = $(CXXINCS) -std=c++11
CFLAGS = $(INCS) -std=c++11
RM = rm.exe -f
.PHONY: all all-before all-after clean clean-custom
all: all-before $(BIN) all-after
clean: clean-custom
${RM} $(OBJ) $(BIN)
$(BIN): $(OBJ)
$(CPP) $(LINKOBJ) -o $(BIN) $(LIBS)
distances.o: distances.cpp
$(CPP) -c distances.cpp -o distances.o $(CXXFLAGS)
mainDistances.o: mainDistances.cpp
$(CPP) -c mainDistances.cpp -o mainDistances.o $(CXXFLAGS)
matrix.o: matrix.cpp
$(CPP) -c matrix.cpp -o matrix.o $(CXXFLAGS)
答案 0 :(得分:-1)
你的代码可能叫做math.h,因为c ++默认叫做libc.so(它不需要add -lc参数)。如果你调用了math.h,你需要添加“-lm”来添加libm.so.希望它可以帮到你。我的英语非常糟糕,我很抱歉......