0

I have created a dynamically linked library. The only problem I have is that my main program does not recognize my header file. The header file is in a separate folder from my main program. I have tried #include "myheader.h" as well as #include "/folder/dir/myheader.h"

Here is what my .h consist of

    extern int afunction(int,int);
    extern int afunction(int,int);

So far this code works

    gcc -fPIC -c filename1.c
    gcc -fPIC -c filename2.c

    gcc -shared -o libMylib.so filename1.o filename2.o

I then copy the lib to /usr/local/lib, and then

    gcc main.c -L. -lMylib -o exeName -ldl

and I get

    " myheader.h : no such file or directory.

Here is my directory structure:

directory1 ----------------folder1(main program.c)

directory1 ----------------folder2(myheader.h, along with functions for the pgm)

A push in the right direction would help, as I have written all my code and I am just at the last phase.

jhonkola
  • 3,385
  • 1
  • 17
  • 32
sergio
  • 75
  • 2
  • 10

2 Answers2

3

You need gcc ... -I<some directory to myheader.h>. That will enable the compiler to find the header file.

Ed Heal
  • 59,252
  • 17
  • 87
  • 127
  • Are you comping into object code, if so look up the `I`flag. Otherwise if linking look up the -L flag and the `LD_LIBRARY_PATH`environment variable. It is on the manual page – Ed Heal May 03 '12 at 23:00
  • i think i figured it out. i dont have the code for the pointers and what not in my main program. – sergio May 03 '12 at 23:14
1

You can put your lib header files in the same folder with your current program.

or like @Ed Heal said.. adding -I<path> for include header folder.

Oki Sallata
  • 374
  • 1
  • 10