2

A file called test.cpp in ~/test code is

#include <stdio.h>
#include "add.h" 
int main(){
    printf("%d\n",add(1,2));
}

file add.h is in ~/test/1, which is just a subdirctory

code is

int add(int a, int b){return a+b;}

then i use export

export PATH=$PATH:~/test/1

enter image description here

Is there any way to fix that?

not using #include "1/test"

any help is much appreciated

Athos
  • 145
  • 1
  • 1
  • 11

1 Answers1

4

export is used to create an environment variable for the shell. It has no bearing on where the compiler looks to find your include files.

gcc -Itest/1 test.cpp should make it work. The -I argument gives gcc a path to look for include files in.

You can use a makefile or cmake to give these specific instructions to gcc if you like.

kmort
  • 2,848
  • 2
  • 32
  • 54