Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FreeBSD: Error while building caused by Linux Poll #56

Closed
Surgams opened this issue Jul 23, 2018 · 17 comments
Closed

FreeBSD: Error while building caused by Linux Poll #56

Surgams opened this issue Jul 23, 2018 · 17 comments

Comments

@Surgams
Copy link

Surgams commented Jul 23, 2018

Hi again,
I asked you sometime ago about building ulfius on FreeBSD and we got the cmake working yet I have been super busy since then.
Now I’m looking at the library again so returned to the code and all seems fine, I decided to use the normal make (not cmake and just updated the clags and lib to include /usr/local/lib and /usr/local/include - would be easier for me in the future to port to FreeBSD port system).

Both orcania and yder were built fine (and created symbolic links for the libs will add that to make later)
yet when I arrived to last make command, it threw an error (last time I had the same issue when I was working on cmake as well).

Thanks so much...

/home/code/app/lib/ulfius >gmake && sudo gmake install
cd ./src && gmake
gmake[1]: Entering directory '/usr/home/code/app/lib/ulfius/src'
cc -c -pedantic -std=gnu99 -fPIC -Wall -D_REENTRANT -I/usr/local/include -I../include -I../lib/orcania/src -I../lib/yder/src -O3 -I/usr/local/include ulfius.c
cc -c -pedantic -std=gnu99 -fPIC -Wall -D_REENTRANT -I/usr/local/include -I../include -I../lib/orcania/src -I../lib/yder/src -O3 -I/usr/local/include u_map.c
cc -c -pedantic -std=gnu99 -fPIC -Wall -D_REENTRANT -I/usr/local/include -I../include -I../lib/orcania/src -I../lib/yder/src -O3 -I/usr/local/include u_request.c
cc -c -pedantic -std=gnu99 -fPIC -Wall -D_REENTRANT -I/usr/local/include -I../include -I../lib/orcania/src -I../lib/yder/src -O3 -I/usr/local/include u_response.c
cc -c -pedantic -std=gnu99 -fPIC -Wall -D_REENTRANT -I/usr/local/include -I../include -I../lib/orcania/src -I../lib/yder/src -O3 -I/usr/local/include u_send_request.c
cc -c -pedantic -std=gnu99 -fPIC -Wall -D_REENTRANT -I/usr/local/include -I../include -I../lib/orcania/src -I../lib/yder/src -O3 -I/usr/local/include u_websocket.c
u_websocket.c:151:67: error: use of undeclared identifier 'POLLRDHUP'
} else if (websocket->websocket_manager->fds.revents & (POLLRDHUP|POLLERR|POLLHUP|POLLNVAL)) {
^
u_websocket.c:224:59: error: use of undeclared identifier 'POLLRDHUP'
websocket->websocket_manager->fds.events = POLLIN | POLLRDHUP;
^
u_websocket.c:516:54: error: use of undeclared identifier 'POLLRDHUP'
} else if (!(websocket_manager->fds.revents & (POLLRDHUP|POLLERR|POLLHUP|POLLNVAL)) && poll_ret > 0) {
^
3 errors generated.
gmake[1]: *** [Makefile:66: u_websocket.o] Error 1
gmake[1]: Leaving directory '/usr/home/code/app/lib/ulfius/src'
gmake: *** [Makefile:53: libulfius.so] Error 2

@babelouest
Copy link
Owner

Hello @bluecub ,

The error you have looks pretty much straight forward, but the fix isn't.

According to the FreeBSD poll manpage, you need to enable the macro _GNU_SOURCE in order to use POLLRDHUP.
Although, this macro is already enabled, so this must be something else. After a quick search, it seems that the current FreeBSD poll.h doesn't even have any definition for POLLRDHUP.

So if it works with CMake, can you install it with CMake, then make sure the websocket_example works as well?

After that, you can try to properly build Ulfius with the Makefile. You can try to manually define POLLRDHUP like in other places.
Or even disabling it.

Would you come back to me with some feedbacks?

@Surgams
Copy link
Author

Surgams commented Jul 23, 2018

Hi, i got the same error using cmake. I will try some options and get back to you. Thanks

@Surgams Surgams changed the title Error while building - use of undeclared identifier FreeBSD: Error while building - use of undeclared identifier Jul 24, 2018
@Surgams Surgams changed the title FreeBSD: Error while building - use of undeclared identifier FreeBSD: Error while building with Linux Poll Jul 24, 2018
@Surgams Surgams changed the title FreeBSD: Error while building with Linux Poll FreeBSD: Error while building caused by Linux Poll Jul 24, 2018
@Surgams
Copy link
Author

Surgams commented Jul 24, 2018

The only way I got it to work is by defining the POLLRDHUP manually which is not ideal but it worked for the time being.
Thanks a lot for all the support and the great work, though I sincerely wish this library was a bit more portable and not so coupled to Linux, nothing against Linux but many people use Mac or BSDs or even Windows.

#ifndef POLLRDHUP
#define POLLRDHUP 0x2000
#endif

Cheers

@babelouest
Copy link
Owner

Thanks @bluecub ,

I'll add this to the master branch then. Although, can you validate that the websocket_example works on your side with this patch?

The POLLRDHUP macro was added recently to detect if a websocket is improperly closed by the client or disconnected without sending the close message. Otherwise the websocket would stay open indefinitely and was consuming 100% of the CPU in some cases. If you can find a way to get the same result for OpenBSD, I'll be glad to add the patch to the master branch!

Concerning the portability, I understand your concerns but I do this on my free time with my limited resources, and I'm more used to linux than other systems. So I prefer to rely on experts of other systems to help with the portability, like this, rather than making bad portable code that I won't even know it's bad since I don't use it...

@Surgams
Copy link
Author

Surgams commented Jul 24, 2018

Tried couple examples and worked fine on FreeBSD .
The websockets example, opens and closes connections instantly as per the below attachment.
I will have a closer look at it tomorrow and let you know. Thanks again

4e9a7463-a175-4000-b12f-d83cf4c0d9d6

@babelouest
Copy link
Owner

That's very good news!

I'll wait for your feedbacks, thanks a lot for your help!

@Surgams
Copy link
Author

Surgams commented Jul 25, 2018

Hi @babelouest
I am very excited. Everything seems to work perfectly fine so far... thanks for checking in the POLLRDHUP patch.

I built it using make though (gmake in FreeBSD context, it stands for GNU make while make is the BSD make, and it can be installed from the port system quite easily) as I am not familiar with cmake, yet I agree cmake is best tool for the job. My bad for being lazy!

What I changed is pretty much the Makefile in all lib/yder/src/Makefile, lib/orcania/src/Makefile, and src/Makefile.
Basically I changed gcc to cc (FreeBSD is shipped with clang so cc should be compiler agnostic) and added -I/usr/local/include to cflags and -L/usr/local/lib to lib and added symbolic link to the .so created 3 shared libs.

Please feel free to close this thread if you are satisfied. And thanks for putting the effort to write and share this library. It definitely fills a gap in the C ecosystem.

Cheers :)

@babelouest
Copy link
Owner

Thanks for the feedback @bluecub ,

Concerning the changes you made to the Makefile, you can also make it like that:

  • change gcc to cc: run make with a new value for the variable CC: make CC=cc
  • add path to build command: you can use the environment variables, something likeexport C_INCLUDE_PATH=/usr/local/include/:${C_INCLUDE_PATH} and export LD_LIBRARY_PATH=/usr/local/lib:${LD_LIBRARY_PATH}

Concerning the symlink you manually create, this is probably due to the LD_LIBRARY_PATH not set, because the command ldconfig at the end of the build process should create the symlinks.

I assume that if the regular Makefile works on your FreeBSD now, so the CMake will work as well, and you probably won't have to patch it:

$ cd ulfius
$ mkdir build
$ cd build
$ cmake ..
$ make && sudo make install

@Surgams
Copy link
Author

Surgams commented Jul 25, 2018

Very True if you add those env variables for LD lib and include path, cmake as it is works fine and no need for symbolic links or anything else.

Yet I was hoping that cmake can be configured in such a way to do the build without any extra manual steps so the build works out of the box for FreeBSD.

@babelouest
Copy link
Owner

Yet I was hoping that cmake can be configured in such a way to do the build without any extra manual steps so the build works out of the box for FreeBSD.

It doesn't?
Currently, what are the problems with CMake?

@Surgams
Copy link
Author

Surgams commented Jul 26, 2018

Hey. I meant without the need to set the env variables.

Well, I added to CMAKE_C_FLAGS in the 3 CMakeLists.txt files for ulfius, yder, and orcania the -I/usr/local/include.

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror -I/usr/local/include")
and the package was built without setting any environment variables.
is it possible to add this to the CMakeLists.txt files? it won't effect other systems will just make it easier for Mac and FreeBSD to do the build using cmake.

Thanks

@babelouest
Copy link
Owner

Hello,

Better off using the CMake command include_directories to add /usr/local/include directory, but that would make it less agnostic for windows users for example. I wonder why you don't have /usr/local/include in your include path. Is it standard in FreeBSD? Or is it your specific configuration?

In the CMake documentation, it says you can specify the target directory, I've seen 2 methods so far:

$ cmake ..
$ make DESTDIR=/usr && sudo make install

Or

$ cmake -DCMAKE_INSTALL_PREFIX=/usr ..
$ make && sudo make install

I'd rather document this feature than adding absolute paths in the CMakelists.txt file

@Surgams
Copy link
Author

Surgams commented Jul 26, 2018

I can try those options and see if that would solve the issue.

I prefer not to set environments variables as it is easier for me to add Ulfuis to the port system later on.

@babelouest
Copy link
Owner

I understand, and I agree, but maybe a solution is to pass options to cmake when you build the port. Debian packages can be built like that, I imagine freebsd ports can too.

@Surgams
Copy link
Author

Surgams commented Jul 26, 2018

Sure, Will work on it tomorrow and confirm. Almost there..
Yet this worked for me just in the main CMakeLists.txt of ulfius I added this condition. Probably it is the easiest
IF(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -I/usr/ local/include")
endif()

@babelouest
Copy link
Owner

I've made some changes in the cmake scripts for ulfius, yder and orcania to fix the include local path. I've tested it on a fresh FreeBSD instance and ulfius installed successfully.

Can you check as well with the last master branches?

@Surgams
Copy link
Author

Surgams commented Jul 28, 2018

Awesome, well done.... it works like a charm now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants