0

I have the desired header files in the folder '/mnt/droplet/include'. I use the -I option (-I/mnt/droplet/include) while creating the desired object file. The aforementioned folder contains the header file "stdlib.h", however the compiler tries to include the header file located at '/usr/include/stdlib.h' instead.

How do I ensure that the header file in directory '/mnt/droplet/include/' is included instead.

Note that there are several more such header files I wish to include in the same way, and replacing them directly in usr/include is not an option.

The make file for the same is as follows

LIBS :=  -L/mnt/droplet/gcc-7.1/lib64/ -L/mnt/droplet/local/lib/v1.2/  
CXX  := /mnt/droplet/gcc-7.1/bin/g++ -std=c++1z
INCS := -I/mnt/droplet/include -I/mnt/droplet/local/include/v1.2/ 
SRCS := main.cpp 


CXXFLAGS := -Og -g -ggdb3
OUT_EXE :=  binary
SRCS_EXE := ${SRCS} 

OBJS := $(addsuffix .o,$(basename ${SRCS}))
OBJS_EXE := $(addsuffix .o,$(basename ${SRCS_EXE}))

${OUT_EXE}: ${OBJS_EXE}
    g++  -g -o $@ ${OBJS_EXE} ${LIBS} 

%.o : %.cpp
    ${CXX} -v -c ${CXXFLAGS} ${MAIN_DEF} ${INCS} $< -o $@
clean:
    rm -f core ${OBJS_EXE} ${OUT_EXE} 
  • 1
    `stdlib.h` is a header file that is part of your compiler/tool-chain. Using an alternative file will probably break your compiler. – Richard Critten Mar 18 '23 at 12:25
  • What are you really trying to do? What is the original and underlying problem you need to solve? Why do you need a non-standard variant of a standard header? What are you really trying to build? What is this "droplet"? – Some programmer dude Mar 18 '23 at 12:28
  • The alternative location has another installation of gcc. I want to use that instead. – MrOmnipotent Mar 18 '23 at 12:31
  • I'm trying to compile my objects using gcc on a remote system, the usr/include of the remote system is mounted(basically a copy over ssh) at the location /mnt/droplet using sshfs. Hence I want to use the files located at /mnt/droplet/ to compile the object file. – MrOmnipotent Mar 18 '23 at 12:33
  • For `gcc`, the `-I` option can be used to specify include paths to search. This info can easily be found in the [GCC documentation](https://gcc.gnu.org/onlinedocs/). – Jesper Juhl Mar 18 '23 at 12:35
  • If the other compiler have been built and installed correctly, you shouldn't need to do anything. Then that compiler should already use its own system include directories. Just invoke the other compiler and it should work automatically. – Some programmer dude Mar 18 '23 at 12:38
  • As I mentioned, I already used the -I option, however that still doesn't find the file and reverts back to '/usr/include'. I have validated that the file it wants to search stdlib.h is located at '/mnt/droplet/include' – MrOmnipotent Mar 18 '23 at 12:39
  • The other compiler seems to be installed correctly, have compiled the same object file on the remote system itself without issue. – MrOmnipotent Mar 18 '23 at 12:39
  • Are you actually building using the other compiler? How are you invoking it? Can you please show the complete build command you use? – Some programmer dude Mar 18 '23 at 12:42
  • Have included the Make file I'm using now – MrOmnipotent Mar 18 '23 at 12:47
  • Now the big question: ***How*** did you build and install the compiler? Did you do it on the system where you're using it? If you didn't do that, but instead use a network mount, then the compilers configured directories are wrong and the compiler can't be used on your system. – Some programmer dude Mar 18 '23 at 12:50
  • I have my source code on my local system, and the libraries to compile it on a remote system. I want to compile my executable on my local system while using the libraries on the remote system. Is this not possible using a network mount and specify the path of the library to compile since some of the source files are being correctly found, while others are not. – MrOmnipotent Mar 18 '23 at 12:54

1 Answers1

0

Check if your compiler can disable default included header files and if you want to change where to search for header files then use double quotations in your #include statement.

For example, #include <stdlib.h> and #include "stdlib.h" have two different meanings.

The first will search your system includes directory and the second will search the directory relative to the directory of your source file.

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
  • The actual difference between `` and `"file"`>, in terms of where the compiler looks for those files, is implementation-dependent and rather more complex than your answers suggests. See [this answer](https://stackoverflow.com/a/21594/10871073), for example. – Adrian Mole Mar 23 '23 at 05:45