0

I'm trying to move individual modules into a project file structure and have encountered a curious problem- despite using symbolic links for all headers and -I[link path] in all compilation commands, the compiler proclaims that every single thing that was declared in a header located in another folder.

Here's the file structure:

../
├── 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

Command line used to create symbolic links (same syntax used for all headers):

ln -sr -T -f reactor/reactor.hpp ../include/reactor.hpp 

Command line used to compile the object file that fails to compile:

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

Example for the kind of errors the compiler throws:

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;

This goes on for a looooong while so I won't include all the errors, they're all the same.

The header itself:

#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__

Trying to change the include path causes the compiler to throw "file not found" fatal errors, so it finds the files through the links.

Any idea what might be causing this?

  • `__TEST_HPP__` is an identifier reserved for compiler use. Try with `TEST_HPP_` and see if it changes something. [What are the rules about using an underscore in a C++ identifier?](https://stackoverflow.com/questions/228783/what-are-the-rules-about-using-an-underscore-in-a-c-identifier) – Yksisarvinen Feb 24 '19 at 11:15
  • The actual text of the define includes my name, so I removed that part of it when copy-pasting it here. I doubt {__MYNAME_TEST_HPP__} is a reserved define. :P – Galorian Feb 24 '19 at 11:46
  • @Yksisarvinen Just in case I tried removing the preceding underscores and adding another word to the define, it didn't change anything. – Galorian Feb 24 '19 at 12:58

0 Answers0