-1

I wrote a makefile which builds a C program attaching the x.264 header. After trying to execute the makefile in terminal I receive the fatal error: "example.c line [line of #include ] x264.h no such file or directory". Below you can find the C code and makefile (located in the same folder, the library - containing the x264.pc file- is in the folder libx264 of the parent folder). I would be very grateful if you could help with the linkage.

Makefile:

    CC = gcc

    CFLAGS = -c -Wall `export PKG_CONFIG_PATH=../libx264 && pkg-config            --cflags x264`
    LDFLAGS = -static `export PKG_CONFIG_PATH=../libx264 && pkg-config --libs --static libx264`


    all: Release

    Debug: CFLAGS += -g
    Debug: example

    Release: example

    test: example.o
        $(CC) -o example example.o $(LDFLAGS)

    test.o: example.c
        $(CC) $(CFLAGS) example.c -o example.o

    clean:
        rm -f example.o example

example.c code

    #include <stdio.h>
    #include <x264.h>
    int main( int argc, char **argv )
    {
        int width, height;
         return 0;
    }
  • Install `libx264-dev` in Ubuntu or Debian. – S.S. Anne Apr 23 '19 at 21:47
  • Hi. The task or challange is to get the makefile working. Bat thaank you, in case I don't manage it I will install the library. –  Apr 24 '19 at 06:10
  • The makefile works just fine. It's the fact that you don't have the header files for the library installed. – S.S. Anne Apr 24 '19 at 19:32

1 Answers1

1

You'd need to tell the compiler (to be more precise: the preprocessor) where the header file is using the -I option:

CFLAGS = -c -Wall -I../libx264

If I'm right, you need to unpack that .pc file, so that x264.h is indeed in ../libx264.

Similar thing for the linker flags (assuming there's a libx264.a file in ../libx264), where you have to specify where the library is using the -L option:

LDFLAGS = -static -L../libx264 -lx264

Alternatively you could of course also write:

LDFLAGS = -static ../libx264/libx264.a
Dale K
  • 25,246
  • 15
  • 42
  • 71
meaning-matters
  • 21,929
  • 10
  • 82
  • 142
  • Thank you! There was one error: the a package was libx264.a not x.264.a. Adding the -I `export PKG_CONFIG_PATH= -I ../libx264 && pkg-config --cflags x264` is not working. I get the error: /bin/sh: 1 export: -I : bad variable name. If I delete the -I I get the same error for the next word: /bin/sh: 1 export: ../libx264 : bad variable name. What is sure is that the parent folder contains the libx264 and the example folders. The libx264 contans a lot of files including: x264.c, x264.h, x265.pc and libx264.a. The example folder contains the example.c file and the makefile which does not work. –  Apr 24 '19 at 06:05
  • That needs to be included in the Makefile. RTFM for more details. – S.S. Anne Apr 24 '19 at 19:35