所以,我正在Linux终端中用g ++编译一个C ++程序并得到以下一组错误,这并不罕见:
/tmp/cc3Td57c.o: In function `main':
/code/newAlgorithm/newAlgorithmTests/basicTest.cpp:69: undefined reference to `readpoints(char*, point*, int*, int*)'
/code/newAlgorithm/newAlgorithmTests/basicTest.cpp:70: undefined reference to `readpointsSky(char*, point*, int*, int*)'
/code/newAlgorithm/newAlgorithmTests/basicTest.cpp:76: undefined reference to `generalCube(int, int, int, point*, int*)'
collect2: ld returned 1 exit status
make: *** [basicTest.o] Error 1
但不寻常的是,这些错误的常用解决方案都没有奏效。所有文件都被正确包含,它们的名称拼写正确,它们的候选函数拼写与我在main()中调用的相同,并且依赖文件都正确编译。由于这是一个链接器错误,这里是makefile:
CC = g++
CC1 = g++ -g -I ../../glpk-4.45/gnu/include -c
CC2 = g++ -g -L ../../glpk-4.45/gnu/lib
all: basicTest
basicTest: quickSortPoint.o point.o skyline1.o readpoints.o newAlgorithmTest.o evaluate1.o basicTest.o
$(CC2) quickSortPoint.o point.o skyline1.o readpoints.o newAlgorithmTest.o evaluate1.o basicTest.o -o basicTest -lglpk -lm
basicTest.o: basicTest.cpp quickSortPoint.cpp readpoints.c evaluate1.c newAlgorithmTest.cpp
$(CC2) basicTest.cpp -lglpk -lm
quickSortPoint.o: quickSortPoint.cpp
$(CC1) quickSortPoint.cpp
point.o: point.cpp
$(CC1) point.cpp
skyline1.o: skyline1.c point.cpp
$(CC1) skyline1.c
readpoints.o: readpoints.c skyline.c
$(CC1) readpoints.c
newAlgorithmTest.o: newAlgorithmTest.cpp quickSortPoint.cpp point.cpp
$(CC1) newAlgorithmTest.cpp
evaluate1.o: evaluate1.c point.cpp
$(CC1) evaluate1.c
因此,它在basicTest.o上失败了,即使它编译依赖文件(readpoints.c和newAlgorithmTest.cpp)没有任何问题。我是否犯了一个非常基本的错误,或者这是一个更大的问题?
(问题不在于GLPK包,因为我之前遇到过问题,但后来解决了。)