Reputation: 49
I got following error
'libwebsockets.h' file not found
but I have installed libwebsockets with the command
brew install libwebsockets
How can I solve this error? I want to implement a websocketserver and i need this. If my code is only has this following line
#include <libwebsockets.h>
it gave me an error.
I tried to compile it with gcc foo.c
Upvotes: 1
Views: 2636
Reputation: 51850
You need to pass the appropriate compile and link flags to the compiler for it to find the headers and libraries.
This is usually done with the program "pkg-config". To get the compile flags, run:
pkg-config libwebsockets --cflags
To get the link flags:
pkg-config libwebsockets --libs
If you compile and link in the same step, you need to pass the flags that are output by both of the above commands to the compiler. If you have separate compilation and link commands, you pass the "--cflags" output during compiling, and the "--libs" output during linking.
In your case, you can compile with:
gcc $(pkg-config libwebsockets --cflags) foo.c $(pkg-config libwebsockets --libs)
The $()
syntax takes the output of the command you put between (
and )
and puts it into yours, as if you had typed it in.
You should probably write a small build script to do that for you. For example in a file named "build" in the same directory as "foo.c":
#! /bin/sh
gcc $(pkg-config libwebsockets --cflags) foo.c $(pkg-config libwebsockets --libs)
Make the script executable:
chmod +x build
And then just call it:
./build
Upvotes: 4