我正在尝试将各个模块移到项目文件结构中,并且遇到了一个奇怪的问题-尽管在所有编译命令中都对所有标头使用符号链接和-I [link path],但编译器宣称每件事在另一个文件夹的标头中声明。
这是文件结构:
../
├── bin
│ ├── libutil.dbg.a
│ └── obj
│ ├── reactor.dbg.o
│ ├── testFile.dbg.o
│ └── timer.dbg.o
├── include
│ ├── cpp98_utils.hpp -> ../src/reactor/reactor.hpp
│ ├── errorTemplate.hpp -> ../src/reactor/reactor.hpp
│ ├── reactor.hpp -> ../src/reactor/reactor.hpp
│ ├── testFile.hpp -> ../src/reactor/reactor.hpp
│ ├── testHeader.hpp -> ../src/reactor/reactor.hpp
│ └── timer.hpp -> ../src/reactor/reactor.hpp
└── src
├── makefile
├── reactor
│ ├── reactor.cpp
│ ├── reactor.hpp
│ └── reactor_test.cpp
├── timer
│ ├── timer.cpp
│ ├── timer.hpp
│ └── timer_test.cpp
└── utils
├── cpp98_utils.hpp
├── errorTemplate.hpp
├── testFile.cpp
├── testFile.hpp
└── testHeader.hpp
用于创建符号链接的命令行(所有标头使用相同的语法):
ln -sr -T -f reactor/reactor.hpp ../include/reactor.hpp
用于编译无法编译的目标文件的命令行:
g++ -MT ../bin/obj/reactor_test.o -MMD -MP -MF ../.d/reactor_test.Td -std=c++98 -ansi -Wall -pedantic-errors -Wextra -I../include -c -g -o ../bin/obj/reactor_test.o reactor/reactor_test.cpp -lm -pthread -lglut -lboost_system -lboost_thread
有关编译器引发的错误类型的示例:
reactor/reactor_test.cpp:76:34: error: ‘ARR_LEN’ was not declared in this scope
for (size_t i=0; i<ARR_LEN(tests); ++i)
^
reactor/reactor_test.cpp:80:4: error: ‘cout’ is not a member of ‘std’
std::cout << test_names[i] << " successful." << std::endl;
^
reactor/reactor_test.cpp:80:52: error: ‘endl’ is not a member of ‘std’
std::cout << test_names[i] << " successful." << std::endl;
这会持续很长时间,所以我不会包括所有错误,它们都是一样的。
标题本身:
#ifndef __TEST_HPP__
#define __TEST_HPP__
#include <cstdlib> // size_t, EXIT_FAILURE, EXIT_SUCCESS
#include <iostream> // std::cout, std::endl
#include <pthread.h> // pthread_create, pthread_join
#include <stdio.h> // perror
#include <errno.h> // perror
#include <unistd.h> // usleep
#include <time.h> // clock_gettime
#include <cstring> // strcmp
#include <sys/stat.h> // open
#include <fcntl.h> // open
#include <exception> // set_terminate, terminate, set_unexpected, unexpected
#include <sys/types.h> /* mode_t */
#include "errorTemplate.hpp"
#include "testFile.hpp"
namespace ilrd
{
#ifndef MAX
#define MAX(a, b) TemplateMax(a, b)
template <typename T>
inline T TemplateMax(const T& a, const T& b)
{
return (((a)>(b))?(a):(b));
}
#endif
#define TEST_SCALE 20
#define STOP_TEXT "Stop!"
#define CLIENT_TEXT "ping!"
#define ARR_LEN(x) (sizeof(x)/sizeof(x[0])) // expands to number of cells in
// array
}// ilrd
#endif // __TEST_HPP__
尝试更改包含路径会导致编译器抛出“找不到文件”致命错误,因此它会通过链接查找文件。
知道是什么原因造成的吗?